OSDN Git Service

stopped to set luatexja.direction.shipout_lthook=nil
[luatex-ja/luatexja.git] / src / ltj-latex.sty
1 %
2 % ltj-latex.sty
3 %
4
5 %! これは外から読まれない
6 %% Avoid multiple loading.
7 \csname luatexjalatexLoaded\endcsname
8 \edef\ltj@latex@AtEnd{%
9 \endlinechar=\the\endlinechar
10 \relax}
11 \endlinechar\m@ne%
12 \def\luatexjalatexLoaded{\endinput}
13
14 \NeedsTeXFormat{LaTeX2e}
15 \ProvidesPackage{ltj-latex}[2021-05-17 LaTeX support of LuaTeX-ja]
16
17 \endlinechar=13
18
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}
24     {%
25       \ifnum\patch@level<0\relax \ifnum\patch@level<-6 \ltj@ltfilehook@availtrue\fi
26       \else\ltj@ltfilehook@availtrue\fi
27     }%
28 }{}
29 \@ifl@t@r\fmtversion{2021-05-01}{\count@=1 }{\count@=0 }
30 \ifnum \count@<1
31 %%%% \shipout
32   \newluafunction\ltj@@lua@shipout@inner
33   \directlua{
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
40     end
41   }
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
48   \fi
49 \else
50   \directlua{%
51     luatexbase.add_to_callback('pre_shipout_filter',luatexja.direction.shipout_lthook, 'ltj.direction', 1)
52   }
53 \fi
54
55 %%% patch for LaTeX
56 \usepackage{lltjfont}
57 \usepackage{lltjdefs}
58 \usepackage{lltjcore}
59 \RequirePackage{lltjp-atbegshi}
60
61 %%% patching commands
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}}%
68   }
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}}%
72   }
73 \else
74   \RequirePackage{filehook}
75   \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
76   \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
77 \fi
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
84     \fi
85     \@@input{#1.\@pkgextension}\ltj@temp
86   }%
87 }
88
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]}
92 \else
93   \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
94 \fi
95 \def\ltj@pkgpatch@#1[#2]{%
96   \ltj@pkgpatch@@{%
97     \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
98   }%
99 }
100 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
101
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)
113 \fi
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}
119
120 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
121
122 \RequirePackage{lltjp-geometry}
123
124 \def\ltj@@q@stop{\ltj@@q@stop}
125 \ifdefined\ltj@stop@overwrite@primitive
126   \begingroup
127     \def\ltj@loop#1{%
128       \unless\ifx#1\ltj@@q@stop
129         \escapechar-1
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}%
134             \escapechar92
135             \PackageWarningNoLine{luatexja}{%
136               Restoring \string#1\space into its orignal meaning\MessageBreak
137               (\expandafter\meaning\csname\ltj@@temp\endcsname)}%
138             \ltj@@next%
139           \fi
140         \fi
141         \let\ltj@@next\ltj@loop
142       \else\let\ltj@@next\relax\fi\ltj@@next
143     }%
144     \expandafter\ltj@loop\ltj@stop@overwrite@primitive\ltj@@q@stop
145   \endgroup
146 \fi
147 \def\ltj@overwrite@primitive#1{%
148   \begingroup
149     \def\ltj@loop##1{%
150       \unless\ifx##1\ltj@@q@stop
151         \escapechar-1
152         \edef\ltj@@next{\unexpanded{\let\ltj@@temp}\csname ltj@@\string##1\endcsname}\ltj@@next
153         \ifx\ltj@@temp\relax
154            \escapechar92
155            \PackageInfo{luatexja}{Cannot redefine \string##1, since it is not redefined\MessageBreak by LuaTeX-ja}%
156         \else\ifx\ltj@@temp##1
157            \escapechar92
158            \PackageInfo{luatexja}{No need to redefine \string##1, since it is not\MessageBreak
159              overwritten by packages other than LuaTeX-ja\MessageBreak}%
160         \else
161           \edef\ltj@@next{\unexpanded{\global\let##1}\csname ltj@@\string##1\endcsname}%
162            \escapechar92\PackageInfo{luatexja}{Redefining \string##1}\ltj@@next%
163         \fi\fi
164         \let\ltj@@next\ltj@loop
165       \else\let\ltj@@next\relax\fi\ltj@@next
166     }%
167     \ltj@loop#1\ltj@@q@stop
168   \endgroup
169 }
170
171 %%------------------ all done
172 \ltj@latex@AtEnd
173 \endinput
174 %% EOF