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-17 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 \def\@@ltj@ExecuteAfterPackage#1{\AddToHook{package/after/#1}}
64 \def\@@ltj@ExecuteBeforePackage#1{\AddToHook{package/before/#1}}
65 \def\ltj@ExecuteAfterPackage{\@ifstar\@@ltj@ExecuteAfterPackage@star\@@ltj@ExecuteAfterPackage}
66 \def\@@ltj@ExecuteAfterPackage@star#1#2{%
67 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteAfterPackage{#1}{#2}}%
69 \def\ltj@ExecuteBeforePackage{\@ifstar\@@ltj@ExecuteBeforePackage@star\@@ltj@ExecuteBeforePackage}
70 \def\@@ltj@ExecuteBeforePackage@star#1#2{%
71 \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteBeforePackage{#1}{#2}}%
74 \RequirePackage{filehook}
75 \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
76 \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
78 \def\ltj@pkgpatch@im#1{\@ifnextchar[{\ltj@pkgpatch@im@{#1}}{\ltj@pkgpatch@im@{#1}[lltjp-#1]}}%]
79 \def\ltj@pkgpatch@im@#1[#2]{\ltj@ExecuteAfterPackage*{#1}{\ltj@pkgpatch@im@@{#2}}}
80 \def\ltj@pkgpatch@im@@#1{%
81 \@ifpackageloaded{#1}{}{%
82 \if\catcode`@=11\let\ltj@temp\relax\else
83 \edef\ltj@temp{\noexpand\catcode`@=\the\catcode`@\relax}\makeatletter
85 \@@input{#1.\@pkgextension}\ltj@temp
89 \def\ltj@pkgpatch#1{\@ifnextchar[{\ltj@pkgpatch@{#1}}{\ltj@pkgpatch@{#1}[lltjp-#1]}}%]
90 \ifltj@ltfilehook@avail
91 \def\ltj@pkgpatch@@{\AddToHook{begindocument/before}[luatexja.autopatch]}
93 \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
95 \def\ltj@pkgpatch@#1[#2]{%
97 \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
100 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
102 %%% patch for packages
103 \ltj@pkgpatch@im{listings}
104 \ltj@pkgpatch{xunicode} %% at \begin{document}
105 \ltj@pkgpatch@im{fontspec}
106 \ltj@pkgpatch{footmisc} %% at \begin{document}
107 \ltj@pkgpatch{tascmac}
108 \ltj@pkgpatch{ascmac}[lltjp-tascmac]
109 \ltj@pkgpatch@im{stfloats}
110 \ifltj@ltfilehook@avail\else
111 \ltj@pkgpatch{preview} %% at \begin{document}
112 % (preview package has delayed option)
114 \ltj@pkgpatch{array} %% at \begin{document}
115 \ltj@pkgpatch{collcell} %% at \begin{document}
116 \ltj@pkgpatch@im{unicode-math}
117 \ltj@pkgpatch@im{siunitx}
118 \ltj@pkgpatch@im{microtype}
120 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
122 \RequirePackage{lltjp-geometry}
124 \def\ltj@@q@stop{\ltj@@q@stop}
125 \ifdefined\ltj@stop@overwrite@primitive
128 \unless\ifx#1\ltj@@q@stop
130 \ifcsname ltj@@orig@\string#1\endcsname
131 \ifcsname ltj@@\string#1\endcsname
132 \edef\ltj@@next{\unexpanded{\global\let#1}\csname ltj@@orig@\string#1\endcsname}%
133 \edef\ltj@@temp{ltj@@orig@\string#1}%
135 \PackageWarningNoLine{luatexja}{%
136 Restoring \string#1\space into its orignal meaning\MessageBreak
137 (\expandafter\meaning\csname\ltj@@temp\endcsname)}%
141 \let\ltj@@next\ltj@loop
142 \else\let\ltj@@next\relax\fi\ltj@@next
144 \expandafter\ltj@loop\ltj@stop@overwrite@primitive\ltj@@q@stop
147 \def\ltj@overwrite@primitive#1{%
150 \unless\ifx##1\ltj@@q@stop
152 \edef\ltj@@next{\unexpanded{\let\ltj@@temp}\csname ltj@@\string##1\endcsname}\ltj@@next
155 \PackageInfo{luatexja}{Cannot redefine \string##1, since it is not redefined\MessageBreak by LuaTeX-ja}%
156 \else\ifx\ltj@@temp##1
158 \PackageInfo{luatexja}{No need to redefine \string##1, since it is not\MessageBreak
159 overwritten by packages other than LuaTeX-ja\MessageBreak}%
161 \edef\ltj@@next{\unexpanded{\global\let##1}\csname ltj@@\string##1\endcsname}%
162 \escapechar92\PackageInfo{luatexja}{Redefining \string##1}\ltj@@next%
164 \let\ltj@@next\ltj@loop
165 \else\let\ltj@@next\relax\fi\ltj@@next
167 \ltj@loop#1\ltj@@q@stop
171 %%------------------ all done