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-05-11 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
49 \directlua{luatexja.direction.shipout_lthook = nil}
52 luatexbase.add_to_callback('pre_shipout_filter',luatexja.direction.shipout_lthook, 'ltj.direction', 1)
60 \RequirePackage{lltjp-atbegshi}
63 \ifltj@ltfilehook@avail
64 \def\@@ltj@ExecuteAfterPackage#1{\AddToHook{package/after/#1}}
65 \def\@@ltj@ExecuteBeforePackage#1{\AddToHook{package/before/#1}}
66 \def\ltj@ExecuteAfterPackage{\@ifstar\@@ltj@ExecuteAfterPackage@star\@@ltj@ExecuteAfterPackage}
67 \def\@@ltj@ExecuteAfterPackage@star#1#2{%
68 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteAfterPackage{#1}{#2}}%
70 \def\ltj@ExecuteBeforePackage{\@ifstar\@@ltj@ExecuteBeforePackage@star\@@ltj@ExecuteBeforePackage}
71 \def\@@ltj@ExecuteBeforePackage@star#1#2{%
72 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteBeforePackage{#1}{#2}}%
75 \RequirePackage{filehook}
76 \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
77 \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
79 \def\ltj@pkgpatch@im#1{\@ifnextchar[{\ltj@pkgpatch@im@{#1}}{\ltj@pkgpatch@im@{#1}[lltjp-#1]}}%]
80 \def\ltj@pkgpatch@im@#1[#2]{\ltj@ExecuteAfterPackage*{#1}{\ltj@pkgpatch@im@@{#2}}}
81 \def\ltj@pkgpatch@im@@#1{%
82 \@ifpackageloaded{#1}{}{%
83 \if\catcode`@=11\let\ltj@temp\relax\else
84 \edef\ltj@temp{\noexpand\catcode`@=\the\catcode`@\relax}\makeatletter
86 \@@input{#1.\@pkgextension}\ltj@temp
90 \def\ltj@pkgpatch#1{\@ifnextchar[{\ltj@pkgpatch@{#1}}{\ltj@pkgpatch@{#1}[lltjp-#1]}}%]
91 \ifltj@ltfilehook@avail
92 \def\ltj@pkgpatch@@{\AddToHook{begindocument/before}[luatexja.autopatch]}
94 \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
96 \def\ltj@pkgpatch@#1[#2]{%
98 \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
101 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
103 %%% patch for packages
104 \ltj@pkgpatch@im{listings}
105 \ltj@pkgpatch{xunicode} %% at \begin{document}
106 \ltj@pkgpatch@im{fontspec}
107 \ltj@pkgpatch{footmisc} %% at \begin{document}
108 \ltj@pkgpatch{tascmac}
109 \ltj@pkgpatch{ascmac}[lltjp-tascmac]
110 \ltj@pkgpatch@im{stfloats}
111 \ifltj@ltfilehook@avail\else
112 \ltj@pkgpatch{preview} %% at \begin{document}
113 % (preview package has delayed option)
115 \ltj@pkgpatch{array} %% at \begin{document}
116 \ltj@pkgpatch{collcell} %% at \begin{document}
117 \ltj@pkgpatch@im{unicode-math}
118 \ltj@pkgpatch@im{siunitx}
119 \ltj@pkgpatch@im{microtype}
121 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
123 \RequirePackage{lltjp-geometry}
125 \def\ltj@@q@stop{\ltj@@q@stop}
126 \ifdefined\ltj@stop@overwrite@primitive
129 \unless\ifx#1\ltj@@q@stop
131 \ifcsname ltj@@orig@\string#1\endcsname
132 \ifcsname ltj@@\string#1\endcsname
133 \edef\ltj@@next{\unexpanded{\global\let#1}\csname ltj@@orig@\string#1\endcsname}%
134 \edef\ltj@@temp{ltj@@orig@\string#1}%
136 \PackageWarningNoLine{luatexja}{%
137 Restoring \string#1\space into its orignal meaning\MessageBreak
138 (\expandafter\meaning\csname\ltj@@temp\endcsname)}%
142 \let\ltj@@next\ltj@loop
143 \else\let\ltj@@next\relax\fi\ltj@@next
145 \expandafter\ltj@loop\ltj@stop@overwrite@primitive\ltj@@q@stop
148 \def\ltj@overwrite@primitive#1{%
151 \unless\ifx##1\ltj@@q@stop
153 \edef\ltj@@next{\unexpanded{\let\ltj@@temp}\csname ltj@@\string##1\endcsname}\ltj@@next
156 \PackageInfo{luatexja}{Cannot redefine \string##1, since it is not redefined\MessageBreak by LuaTeX-ja}%
157 \else\ifx\ltj@@temp##1
159 \PackageInfo{luatexja}{No need to redefine \string##1, since it is not\MessageBreak
160 overwritten by packages other than LuaTeX-ja\MessageBreak}%
162 \edef\ltj@@next{\unexpanded{\global\let##1}\csname ltj@@\string##1\endcsname}%
163 \escapechar92\PackageInfo{luatexja}{Redefining \string##1}\ltj@@next%
165 \let\ltj@@next\ltj@loop
166 \else\let\ltj@@next\relax\fi\ltj@@next
168 \ltj@loop#1\ltj@@q@stop
172 %%------------------ all done