OSDN Git Service

\ltj@stop@overwrite@primitive (test)
[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-03-18 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   \directlua{luatexja.direction.shipout_lthook = nil}
50 \else
51   \directlua{%
52     luatexbase.add_to_callback('pre_shipout_filter',luatexja.direction.shipout_lthook, 'ltj.direction', 1)
53   }
54 \fi
55
56 %%% patch for LaTeX
57 \usepackage{lltjfont}
58 \usepackage{lltjdefs}
59 \usepackage{lltjcore}
60 \RequirePackage{lltjp-atbegshi}
61
62 %%% patching commands
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}}%
69   }
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}}%
73   }
74 \else
75   \RequirePackage{filehook}
76   \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
77   \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
78 \fi
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
85     \fi
86     \@@input{#1.\@pkgextension}\ltj@temp
87   }%
88 }
89
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]}
93 \else
94   \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
95 \fi
96 \def\ltj@pkgpatch@#1[#2]{%
97   \ltj@pkgpatch@@{%
98     \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
99   }%
100 }
101 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
102
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)
114 \fi
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}
120
121 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
122
123 \RequirePackage{lltjp-geometry}
124
125 \ifdefined\ltj@stop@overwrite@primitive
126   \begingroup
127     \def\ltj@loop#1{%
128       \unless\ifx#1\@nil
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\@nil
145   \endgroup
146 \fi
147
148 %%------------------ all done
149 \ltj@latex@AtEnd
150 \endinput
151 %% EOF