OSDN Git Service

added \ltjghostjachar
[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-10-24 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   %% \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}}%
73     }
74     \long\def\@@ltj@ExecuteBeforePackage#1#2{%
75       \@ifpackageloaded{#1}{}{\AddToHook{package/#1/before}{#2}}%
76     }
77   }{
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}}%
82     }
83     \long\def\@@ltj@ExecuteBeforePackage@star#1#2{%
84       \@ifpackageloaded{#1}{#2}{\@@ltj@ExecuteBeforePackage{#1}{#2}}%
85     }
86   }
87 \else
88   \RequirePackage{filehook}
89   \let\ltj@ExecuteAfterPackage=\AtEndOfPackageFile
90   \let\ltj@ExecuteBeforePackage=\AtBeginOfPackageFile
91 \fi
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
98     \fi
99     \@@input{#1.\@pkgextension}\ltj@temp
100   }%
101 }
102
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]}
106 \else
107   \def\ltj@pkgpatch@@{\gpreto\@begindocumenthook}
108 \fi
109 \def\ltj@pkgpatch@#1[#2]{%
110   \ltj@pkgpatch@@{%
111     \@ifpackageloaded{#1}{\@ifpackageloaded{#2}{}{\RequirePackage{#2}}}{}%
112   }%
113 }
114 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
115
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)
127 \fi
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}
133
134 \ifltj@ltfilehook@avail\else\ltj@pkgpatch@im{everyshi}\fi
135
136 \RequirePackage{lltjp-geometry}
137
138 \def\ltj@@q@stop{\ltj@@q@stop}
139 \ifdefined\ltj@stop@overwrite@primitive
140   \begingroup
141     \def\ltj@loop#1{%
142       \unless\ifx#1\ltj@@q@stop
143         \escapechar-1
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}%
148             \escapechar92
149             \PackageInfo{luatexja}{%
150               Restoring \string#1\space into its orignal meaning\MessageBreak
151               (\expandafter\meaning\csname\ltj@@temp\endcsname)}%
152             \ltj@@next%
153           \fi
154         \fi
155         \let\ltj@@next\ltj@loop
156       \else\let\ltj@@next\relax\fi\ltj@@next
157     }%
158     \expandafter\ltj@loop\ltj@stop@overwrite@primitive\ltj@@q@stop
159   \endgroup
160 \fi
161 \def\ltj@overwrite@primitive#1{%
162   \begingroup
163     \def\ltj@loop##1{%
164       \unless\ifx##1\ltj@@q@stop
165         \escapechar-1
166         \edef\ltj@@next{\unexpanded{\let\ltj@@temp}\csname ltj@@\string##1\endcsname}\ltj@@next
167         \ifx\ltj@@temp\relax
168         \else\ifx\ltj@@temp##1
169            \escapechar92
170            \PackageInfo{luatexja}{No need to redefine \string##1}%
171         \else
172           \edef\ltj@@next{\unexpanded{\global\let##1}\csname ltj@@\string##1\endcsname}%
173            \escapechar92\PackageInfo{luatexja}{Redefining \string##1}\ltj@@next%
174         \fi\fi
175         \let\ltj@@next\ltj@loop
176       \else\let\ltj@@next\relax\fi\ltj@@next
177     }%
178     \ltj@loop#1\ltj@@q@stop
179   \endgroup
180 }
181
182 %%------------------ all done
183 \ltj@latex@AtEnd
184 \endinput
185 %% EOF