OSDN Git Service

lltjcore etc.: use \pltx@adjust@wd@outputbox
[luatex-ja/luatexja.git] / src / patches / lltjcore.sty
1 %
2 % lltjcore.sty: derived from plcore.dtx in pLaTeX.
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjcore}[2021-03-25 Patch to LaTeX2e Kernel for LuaTeX-ja]
7 \RequirePackage{etoolbox}
8
9 %%% expl3
10 \RequirePackage{expl3}
11 \ExplSyntaxOn
12 \cs_set_eq:NN \platex_direction_yoko: \yoko
13 \cs_set_eq:NN \platex_direction_tate: \tate
14 \cs_set_eq:NN \platex_direction_dtou: \dtou
15 \cs_set_eq:NN \platex_direction_utod: \utod % LuaTeX-ja specific
16 \prg_new_conditional:Npnn \platex_if_box_yoko:N #1 { p, T, F, TF }
17   { \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 4 \scan_stop:
18       \prg_return_true: \else: \prg_return_false: \fi: }
19 \prg_new_conditional:Npnn \platex_if_box_utod:N #1 { p, T, F, TF }
20   { \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 11 \scan_stop:
21       \prg_return_true: \else: \prg_return_false: \fi: }
22 \prg_new_eq_conditional:NNn \platex_if_box_tate_math:N \platex_if_box_utod:N { p, T, F, TF }
23 \prg_new_conditional:Npnn \platex_if_box_tate_nomath:N #1 { p, T, F, TF }
24   { \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 3 \scan_stop:
25       \prg_return_true: \else: \prg_return_false: \fi: }
26 \prg_new_conditional:Npnn \platex_if_box_tate:N #1 { p, T, F, TF }
27   { \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 3 \scan_stop:
28       \prg_return_true:
29     \else: \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 11 \scan_stop: % utod
30       \prg_return_true:
31     \else
32       \prg_return_false:
33     \fi: \fi:}
34 \prg_new_conditional:Npnn \platex_if_box_dtou:N #1 { p, T, F, TF }
35   { \if_int_compare:w \ltjgetparameter{boxdir}{#1} = 1 \scan_stop:
36       \prg_return_true: \else: \prg_return_false: \fi: }
37 \prg_new_conditional:Npnn \platex_if_direction_yoko: { p, T, F, TF }
38   { \if_int_compare:w \ltjgetparameter{direction} = 4 \scan_stop:
39       \prg_return_true: \else: \prg_return_false: \fi: }
40 \prg_new_conditional:Npnn \platex_if_direction_utod: { p, T, F, TF }
41   { \if_int_compare:w \ltjgetparameter{direction} = 11 \scan_stop:
42       \prg_return_true: \else: \prg_return_false: \fi: }
43 \prg_new_eq_conditional:NNn
44   \platex_if_direction_tate_math: \platex_if_direction_utod: { p, T, F, TF }
45 \prg_new_conditional:Npnn \platex_if_direction_tate_nomath: { p, T, F, TF }
46   { \if_int_compare:w \ltjgetparameter{direction} = 3 \scan_stop:
47       \prg_return_true: \else: \prg_return_false: \fi: }
48 \prg_new_conditional:Npnn \platex_if_direction_tate: { p, T, F, TF }
49   { \if_int_compare:w \ltjgetparameter{direction} = 3 \scan_stop:
50       \prg_return_true:
51     \else: \if_int_compare:w \ltjgetparameter{direction} = 11 \scan_stop: % utod
52       \prg_return_true:
53     \else
54       \prg_return_false:
55     \fi: \fi:}
56 \prg_new_conditional:Npnn \platex_if_direction_dtou: { p, T, F, TF }
57   { \if_int_compare:w \ltjgetparameter{direction} = 1 \scan_stop:
58       \prg_return_true: \else: \prg_return_false: \fi: }
59 \ExplSyntaxOff
60
61 \def\cleardoublepage{\clearpage\if@twoside
62   \ifodd\c@page
63     \ifnum\ltjgetparameter{direction}=3
64       \hbox{}\thispagestyle{empty}\newpage
65       \if@twocolumn\hbox{}\newpage\fi
66     \fi
67   \else
68     \ifnum\ltjgetparameter{direction}=4
69       \hbox{}\thispagestyle{empty}\newpage
70       \if@twocolumn\hbox{}\newpage\fi
71     \fi
72   \fi\fi}
73
74 \patchcmd\@vtryfc{\global\setbox\@outputbox\vbox{}}
75   {\global\setbox\@outputbox\vbox{%
76      \unless\ifnum\ltjgetparameter{direction}=4
77        \primitive\everypar{}\hskip\z@\fi
78   }}{}{}
79
80 \newif\iftombow \tombowfalse
81 \newif\iftombowdate \tombowdatetrue
82 \newdimen\@tombowwidth
83 \setlength{\@tombowwidth}{.1\p@}
84 \newbox\@TL\newbox\@Tl
85 \newbox\@TC
86 \newbox\@TR\newbox\@Tr
87 \newbox\@BL\newbox\@Bl
88 \newbox\@BC
89 \newbox\@BR\newbox\@Br
90 \newbox\@CL
91 \newbox\@CR
92 \font\@bannerfont=file:lmmono9-regular.otf % cmtt9 in pLaTeX
93 \newtoks\@bannertoken
94 \@bannertoken{}
95 \def\maketombowbox{%
96   \setbox\@TL\hbox to\z@{\yoko\hss
97       \vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@
98       \vrule height10mm width\@tombowwidth depth\z@
99       \iftombowdate
100         \raise4pt\hbox to\z@{\hskip5mm\@bannerfont\the\@bannertoken\hss}%
101       \fi}%
102   \setbox\@Tl\hbox to\z@{\yoko\hss
103       \vrule width10mm height\@tombowwidth depth\z@
104       \vrule height\dimexpr 10mm+\@tombowbleed\relax  width\@tombowwidth depth\z@}%
105   \setbox\@TC\hbox{\yoko
106       \vrule width10mm height\@tombowwidth depth\z@
107       \vrule height10mm width\@tombowwidth depth\z@
108       \vrule width10mm height\@tombowwidth depth\z@}%
109   \setbox\@TR\hbox to\z@{\yoko
110       \vrule height10mm width\@tombowwidth depth\z@
111       \vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@\hss}%
112   \setbox\@Tr\hbox to\z@{\yoko
113       \vrule height\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth depth\z@
114       \vrule width10mm height\@tombowwidth depth\z@\hss}%
115   \setbox\@BL\hbox to\z@{\yoko\hss
116       \vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@
117       \vrule depth10mm width\@tombowwidth height\z@}%
118   \setbox\@Bl\hbox to\z@{\yoko\hss
119       \vrule width10mm depth\@tombowwidth height\z@
120       \vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@}%
121   \setbox\@BC\hbox{\yoko
122       \vrule width10mm depth\@tombowwidth height\z@
123       \vrule depth10mm width\@tombowwidth height\z@
124       \vrule width10mm depth\@tombowwidth height\z@}%
125   \setbox\@BR\hbox to\z@{\yoko
126       \vrule depth10mm width\@tombowwidth height\z@
127       \vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@\hss}%
128   \setbox\@Br\hbox to\z@{\yoko
129       \vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@
130       \vrule width10mm depth\@tombowwidth height\z@\hss}%
131   \setbox\@CL\hbox to\z@{\yoko\hss
132       \vrule width10mm height.5\@tombowwidth depth.5\@tombowwidth
133       \vrule height10mm depth10mm width\@tombowwidth}%
134   \setbox\@CR\hbox to\z@{\yoko
135       \vrule height10mm depth10mm width\@tombowwidth
136       \vrule height.5\@tombowwidth depth.5\@tombowwidth width10mm\hss}%
137 }
138 \def\@outputtombow{%
139   \iftombow
140   \vbox to\z@{\kern\dimexpr-10mm-\@tombowbleed\relax
141     \boxmaxdepth\maxdimen
142       \moveleft\@tombowbleed\vbox to\@@paperheight{%
143           \color@begingroup
144           \@tombowcolor
145       \hbox to\@@paperwidth{\hskip\@tombowbleed\relax
146          \copy\@TL\hfill\copy\@TC\hfill\copy\@TR\hskip\@tombowbleed}%
147       \kern-10mm%
148       \hbox to\@@paperwidth{\copy\@Tl\hfill\copy\@Tr}%
149       \vfill
150       \hbox to\@@paperwidth{\copy\@CL\hfill\copy\@CR}%
151       \vfill
152       \hbox to\@@paperwidth{\copy\@Bl\hfill\copy\@Br}%
153       \kern-10mm%
154       \hbox to\@@paperwidth{\hskip\@tombowbleed\relax
155          \copy\@BL\hfill\copy\@BC\hfill\copy\@BR\hskip\@tombowbleed}%
156       \color@endgroup
157     }\vss
158   }%
159   \fi
160 }
161 \def\@tombowcolor{\normalcolor}
162 \def\@tombowbleed{3mm}
163 \def\@tombowreset@@paper{%
164    \@@topmargin \topmargin % only for compatibility
165    \iftombow
166      \@@paperwidth\dimexpr\paperwidth+2\dimexpr\@tombowbleed\relax
167      \@@paperheight\dimexpr\paperheight+10mm+2\dimexpr\@tombowbleed\relax
168      \advance\@@topmargin 1in\relax \advance\@themargin 1in\relax
169    \fi
170 }
171 \newdimen\@@paperheight
172 \newdimen\@@paperwidth
173 \newdimen\@@topmargin % not used by LuaTeX-ja; only to avoid existing codes
174 \patchcmd\@outputpage{\begingroup\let\protect\noexpand}{% tate direction
175 \begingroup
176   \ifnum\ltjgetparameter{direction}=4\else
177     \dimen\z@\textwidth \textwidth\textheight \textheight\dimen\z@
178   \fi
179   \let \protect \noexpand
180 }{}{}
181 \patchcmd\@outputpage{% supply \yoko
182     \set@typeset@protect
183     \aftergroup \endgroup
184 }{%
185     \yoko \set@typeset@protect
186     \aftergroup \endgroup
187 }{}{}
188 \patchcmd\@outputpage{\let\@thefoot\@oddfoot\let\@themargin\oddsidemargin}{% tate direction
189   \let\@thefoot\@oddfoot
190   \ifnum\ltjgetparameter{direction}=3 \let\@themargin\evensidemargin
191   \else\let\@themargin\oddsidemargin\fi
192 }{}{}
193 \patchcmd\@outputpage{\let\@thefoot\@evenfoot\let\@themargin\evensidemargin}{% tate direction
194   \let\@thefoot\@evenfoot
195   \ifnum\ltjgetparameter{direction}=3 \let\@themargin\oddsidemargin
196   \else\let\@themargin\evensidemargin\fi
197 }{}{}
198
199 % 将来は shipout hook で書き直したい
200 \patchcmd\@outputpage{\vskip\topmargin}{\vskip\topmargin\iftombow\vskip1in\fi}{}{}
201 \patchcmd\@outputpage{\reset@font}{\@tombowreset@@paper\reset@font}{}{}
202 \patchcmd\@outputpage{\@begindvi}{\@begindvi\@outputtombow}{}{}
203
204 %%% Remove extra xkanjiskip
205 \renewcommand\@makefnmark{%
206   \unless\ifnum\ltjgetparameter{direction}=3
207     \hbox{}\hbox{\@textsuperscript{\normalfont\@thefnmark}}\hbox{}%
208   \else\hbox{\yoko \@textsuperscript{\normalfont\@thefnmark}}\fi}
209 \begingroup
210 \@ifpackageloaded{hyperref}
211   {\def\ltj@setrefprefix{real}}
212   {\def\ltj@setrefprefix{}}
213 \expandafter\gdef\csname \ltj@setrefprefix @setref\endcsname#1#2#3{%
214   \ifx#1\relax
215     \protect\G@refundefinedtrue
216     \nfss@text{\reset@font\bfseries ??}%
217     \@latex@warning{Reference `#3' on page \thepage \space
218               undefined}%
219   \else
220     \expandafter#2#1\protect\@setref@{}% change \null to \protect\@setref@{}
221   \fi}
222 \gdef\@setref@{\ifhmode\spacefactor\@m\fi}
223 \endgroup
224 \if@compatibility\else
225 \def\verb{\relax\ifmmode\hbox\else\leavevmode\vadjust{}\fi
226   \bgroup
227     \verb@eol@error \let\do\@makeother \dospecials
228     \verbatim@font\@noligs
229     \language\l@nohyphenation
230     \@ifstar\@sverb\@verb}
231 \fi
232 \patchcmd{\do@noligs}{\kern\z@}{\vadjust{}}{}{} % reported by p_typo
233 \gdef\@stopfield{%
234   \inhibitglue\@tempskipa\lastskip\unskip
235   \hskip\@tempskipa\color@endgroup\egroup}
236 \pretocmd{\footnote}{\inhibitglue}{}{}
237 \pretocmd{\footnotemark}{\inhibitglue}{}{}
238 \patchcmd{\@footnotemark}{\@makefnmark}{%
239   \unless\ifnum\ltjgetparameter{direction}=3 \@makefnmark%
240   \else\hbox to\z@{\hskip-.25\zw\raise.9\zh\@makefnmark\hss}\fi%
241 }{}{}
242 \let\@parboxto\@empty
243 \long\def\@iiiparbox#1#2[#3]#4#5{%
244   \leavevmode
245   \@pboxswfalse
246   \setlength\@tempdima{#4}%
247   \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
248     \ifx\relax#2\else
249       \setlength\@tempdimb{#2}%
250       \edef\@parboxto{to\the\@tempdimb}%
251     \fi
252     \if#1b\vbox
253     \else\if #1t\vtop
254     \else\ifmmode\vcenter
255     \else\@pboxswtrue\null$\vcenter% !!!
256     \fi\fi\fi
257     \@parboxto{\let\hss\vss\let\unhbox\unvbox
258        \csname bm@#3\endcsname}%
259     \if@pboxsw \m@th$\null\fi% !!!
260   \@end@tempboxa}
261 \DeclareRobustCommand\underline[1]{%
262   \relax
263   \ifmmode\@@underline{#1}%
264   \else \leavevmode\null$\@@underline{\hbox{#1}}\m@th$\null\relax\fi}
265
266 \newif\iffnfixbottom
267 \newif\ifltj@ftn@unvboxed
268 %%% @makecol
269 \def\pltx@adjust@wd@outputbox{%
270   \unless\ifnum\ltjgetparameter{direction}=4
271     \vbox{\primitive\everypar{}\hskip\z@}%
272    \fi}
273 \patchcmd\@makecol{\vskip -\dimen@\@textbottom}%
274   {\pltx@adjust@wd@outputbox
275    \vskip -\dimen@
276    \ifltj@ftn@unvboxed\iffnfixbottom\else\@textbottom\fi\else\@textbottom\fi}{}{}
277 \patchcmd\@makecol{\vskip\skip\footins}{\iffnfixbottom\vskip\z@\@plus.0001fil\fi\vskip\skip\footins}{}{}
278 \patchcmd\@makecol{\ifvoid\footins}{\ifvoid\footins\ltj@ftn@unvboxedfalse}{}{}
279 \patchcmd\@makecol{\setbox\@outputbox \vbox}{\ltj@ftn@unvboxedtrue\setbox\@outputbox \vbox}{}{}
280 \let\ltj@orig@makecol=\@makecol
281
282 \patchcmd\@makespecialcolbox{\@textbottom}{\ifltj@ftn@unvboxed\iffnfixbottom\else\@textbottom\fi\else\@textbottom\fi}{}{}
283
284 \def\@gnewline #1{%
285   \ifvmode
286     \@nolnerr
287   \else
288     \unskip \reserved@e {\reserved@f#1}\nobreak \hfil \break \null
289     % \null は \break の効果が行頭禁則文字で打ち消されないために必要
290   \ignorespaces
291 \fi}
292
293
294 %%%%%% tabular (platex/#43) \@tabclassz
295 \def\ltj@sharp{\relax\pltx@next@inhibitglue\ltjfakeboxbdd\ignorespaces\@sharp\unskip\ltjfakeboxbdd}
296 \def\@tabclassz{%
297   \ifcase\@lastchclass
298     \@acolampacol
299   \or
300     \@ampacol
301   \or
302   \or
303   \or
304     \@addamp
305   \or
306     \@acolampacol
307   \or
308     \@firstampfalse\@acol
309   \fi
310   \edef\@preamble{%
311     \@preamble{%
312       \ifcase\@chnum
313         \hfil\hskip1sp\ltj@sharp\hfil
314       \or
315         \hskip1sp\ltj@sharp\hfil
316       \or
317         \hfil\hskip1sp\ltj@sharp
318       \fi}}}
319 \patchcmd\@classv{%
320    \ignorespaces\@sharp
321 }{%
322    \everypar\expandafter{\the\everypar\ltjfakeboxbdd}\ignorespaces\@sharp\unskip
323 }{}{}
324 \patchcmd{\@tabular}{\leavevmode}{\leavevmode\null}{}{}
325 \apptocmd{\endtabular}{\null}{}{}
326 \expandafter \let \csname endtabular*\endcsname = \endtabular
327
328 %%%%%% tabbing (platex/#53)
329 \patchcmd\@startline{\strut}{\strut\inhibitglue}{}{}
330 \def\ltj@unhbox@curfield{\ltjfakeboxbdd\unhbox\@curfield\ltjfakeboxbdd}
331 %\patchcmd\@contfield{\unhbox\@curfield}{\ltj@unhbox@curfield}{}{}
332 \patchcmd\@addfield{\unhbox\@curfield}{\ltj@unhbox@curfield}{}{}
333 \endinput