6 %% Avoid multiple loading.
7 \csname luatexjalatexLoaded\endcsname
8 \edef\ltj@latex@AtEnd{%
9 \endlinechar=\the\endlinechar
12 \def\luatexjalatexLoaded{\endinput}
14 \NeedsTeXFormat{LaTeX2e}
15 \ProvidesPackage{ltj-latex}[2021-10-24 LaTeX support of LuaTeX-ja]
19 %%% LaTeX version detection
20 \newif\ifltj@ltfilehook@avail
21 \@ifl@t@r\fmtversion{2020-10-01}{%
22 \@ifl@t@r\fmtversion{2020-10-02}%
23 {\ltj@ltfilehook@availtrue}
25 \ifnum\patch@level<0\relax \ifnum\patch@level<-6 \ltj@ltfilehook@availtrue\fi
26 \else\ltj@ltfilehook@availtrue\fi
29 \@ifl@t@r\fmtversion{2021-05-01}{\count@=1 }{\count@=0 }
32 \newluafunction\ltj@@lua@shipout@inner
34 local t = lua.get_functions_table()
35 local getbox, setbox = tex.getbox, tex.setbox
36 local shipout_lthook = luatexja.direction.shipout_lthook
37 t[\the\ltj@@lua@shipout@inner]=function ()
38 local a = shipout_lthook(getbox(\the\ltj@afbox))
39 if a then setbox(\the\ltj@afbox, a) end
42 \protected\luadef\ltj@@lua@shipout\ltj@@lua@shipout@inner
43 \def\ltj@shipout@{\ltj@@lua@shipout\primitive\shipout\box\ltj@afbox}%
44 \protected\def\ltj@shipout{\ltj@afterbox\ltj@shipout@}
45 \ifprimitive\shipout\let\shipout\ltj@shipout\fi
46 \ifcsname tex_shipout:D\endcsname
47 \expandafter\let\csname tex_shipout:D\endcsname\ltj@shipout
51 luatexbase.add_to_callback('pre_shipout_filter',luatexja.direction.shipout_lthook, 'ltj.direction', 1)
59 \RequirePackage{lltjp-atbegshi}
62 \ifltj@ltfilehook@avail
63 %% \ltj@ExecuteBeforePackage <package><code> and \ltj@ExecuteAfterPackage <package><code>
64 %% no-starred version: do nothing if the <package> is loaded
65 %% starred version: do <code> right away if the <package> is loaded
66 \def\ltj@ExecuteAfterPackage{\@ifstar\@@ltj@ExecuteAfterPackage@star\@@ltj@ExecuteAfterPackage}
67 \def\ltj@ExecuteBeforePackage{\@ifstar\@@ltj@ExecuteBeforePackage@star\@@ltj@ExecuteBeforePackage}
68 \@ifl@t@r\fmtversion{2021-11-15}{% 2021-11-15
69 \def\@@ltj@ExecuteAfterPackage@star#1{\AddToHook{package/#1/after}}
70 \def\@@ltj@ExecuteBeforePackage@star#1{\AddToHook{package/#1/before}}
71 \long\def\@@ltj@ExecuteAfterPackage#1#2{%
72 \@ifpackageloaded{#1}{}{\AddToHook{package/#1/after}{#2}}%
74 \long\def\@@ltj@ExecuteBeforePackage#1#2{%
75 \@ifpackageloaded{#1}{}{\AddToHook{package/#1/before}{#2}}%
78 \def\@@ltj@ExecuteAfterPackage#1{\AddToHook{package/after/#1}}
79 \def\@@ltj@ExecuteBeforePackage#1{\AddToHook{package/before/#1}}
80 \long\def\@@ltj@ExecuteAfterPackage@star#1#2{%
81 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteAfterPackage{#1}{#2}}%
83 \long\def\@@ltj@ExecuteBeforePackage@star#1#2{%
84 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteBeforePackage{#1}{#2}}%
88 \RequirePackage{filehook}
89 \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
90 \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
92 \def\ltj@pkgpatch@im#1{\@ifnextchar[{\ltj@pkgpatch@im@{#1}}{\ltj@pkgpatch@im@{#1}[lltjp-#1]}}%]
93 \def\ltj@pkgpatch@im@#1[#2]{\ltj@ExecuteAfterPackage*{#1}{\ltj@pkgpatch@im@@{#2}}}
94 \def\ltj@pkgpatch@im@@#1{%
95 \@ifpackageloaded{#1}{}{%
96 \if\catcode`@=11\let\ltj@temp\relax\else
97 \edef\ltj@temp{\noexpand\catcode`@=\the\catcode`@\relax}\makeatletter
99 \@@input{#1.\@pkgextension}\ltj@temp
103 \def\ltj@pkgpatch#1{\@ifnextchar[{\ltj@pkgpatch@{#1}}{\ltj@pkgpatch@{#1}[lltjp-#1]}}%]
104 \ifltj@ltfilehook@avail
105 \def\ltj@pkgpatch@@{\AddToHook{begindocument/before}[luatexja.autopatch]}
107 \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
109 \def\ltj@pkgpatch@#1[#2]{%
111 \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
114 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
116 %%% patch for packages
117 \ltj@pkgpatch@im{listings}
118 \ltj@pkgpatch{xunicode} %% at \begin{document}
119 \ltj@pkgpatch@im{fontspec}
120 \ltj@pkgpatch{footmisc} %% at \begin{document}
121 \ltj@pkgpatch{tascmac}
122 \ltj@pkgpatch{ascmac}[lltjp-tascmac]
123 \ltj@pkgpatch@im{stfloats}
124 \ifltj@ltfilehook@avail\else
125 \ltj@pkgpatch{preview} %% at \begin{document}
126 % (preview package has delayed option)
128 \ltj@pkgpatch{array} %% at \begin{document}
129 \ltj@pkgpatch{collcell} %% at \begin{document}
130 \ltj@pkgpatch@im{unicode-math}
131 \ltj@pkgpatch@im{siunitx}
132 \ltj@pkgpatch@im{microtype}
134 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
136 \RequirePackage{lltjp-geometry}
138 \def\ltj@@q@stop{\ltj@@q@stop}
139 \ifdefined\ltj@stop@overwrite@primitive
142 \unless\ifx#1\ltj@@q@stop
144 \ifcsname ltj@@orig@\string#1\endcsname
145 \ifcsname ltj@@\string#1\endcsname
146 \edef\ltj@@next{\unexpanded{\global\let#1}\csname ltj@@orig@\string#1\endcsname}%
147 \edef\ltj@@temp{ltj@@orig@\string#1}%
149 \PackageInfo{luatexja}{%
150 Restoring \string#1\space into its orignal meaning\MessageBreak
151 (\expandafter\meaning\csname\ltj@@temp\endcsname)}%
155 \let\ltj@@next\ltj@loop
156 \else\let\ltj@@next\relax\fi\ltj@@next
158 \expandafter\ltj@loop\ltj@stop@overwrite@primitive\ltj@@q@stop
161 \def\ltj@overwrite@primitive#1{%
164 \unless\ifx##1\ltj@@q@stop
166 \edef\ltj@@next{\unexpanded{\let\ltj@@temp}\csname ltj@@\string##1\endcsname}\ltj@@next
168 \else\ifx\ltj@@temp##1
170 \PackageInfo{luatexja}{No need to redefine \string##1}%
172 \edef\ltj@@next{\unexpanded{\global\let##1}\csname ltj@@\string##1\endcsname}%
173 \escapechar92\PackageInfo{luatexja}{Redefining \string##1}\ltj@@next%
175 \let\ltj@@next\ltj@loop
176 \else\let\ltj@@next\relax\fi\ltj@@next
178 \ltj@loop#1\ltj@@q@stop
182 %%------------------ all done