OSDN Git Service

date
[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}[2020-09-28 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{\unless\ifnum\ltjgetparameter{direction}=4\hskip\z@\fi}}{}{}
76
77 \newif\iftombow \tombowfalse
78 \newif\iftombowdate \tombowdatetrue
79 \newdimen\@tombowwidth
80 \setlength{\@tombowwidth}{.1\p@}
81 \newbox\@TL\newbox\@Tl
82 \newbox\@TC
83 \newbox\@TR\newbox\@Tr
84 \newbox\@BL\newbox\@Bl
85 \newbox\@BC
86 \newbox\@BR\newbox\@Br
87 \newbox\@CL
88 \newbox\@CR
89 \font\@bannerfont=cmtt9
90 \newtoks\@bannertoken
91 \@bannertoken{}
92 \def\maketombowbox{%
93   \setbox\@TL\hbox to\z@{\yoko\hss
94       \vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@
95       \vrule height10mm width\@tombowwidth depth\z@
96       \iftombowdate
97         \raise4pt\hbox to\z@{\hskip5mm\@bannerfont\the\@bannertoken\hss}%
98       \fi}%
99   \setbox\@Tl\hbox to\z@{\yoko\hss
100       \vrule width10mm height\@tombowwidth depth\z@
101       \vrule height\dimexpr 10mm+\@tombowbleed\relax  width\@tombowwidth depth\z@}%
102   \setbox\@TC\hbox{\yoko
103       \vrule width10mm height\@tombowwidth depth\z@
104       \vrule height10mm width\@tombowwidth depth\z@
105       \vrule width10mm height\@tombowwidth depth\z@}%
106   \setbox\@TR\hbox to\z@{\yoko
107       \vrule height10mm width\@tombowwidth depth\z@
108       \vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@\hss}%
109   \setbox\@Tr\hbox to\z@{\yoko
110       \vrule height\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth depth\z@
111       \vrule width10mm height\@tombowwidth depth\z@\hss}%
112   \setbox\@BL\hbox to\z@{\yoko\hss
113       \vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@
114       \vrule depth10mm width\@tombowwidth height\z@}%
115   \setbox\@Bl\hbox to\z@{\yoko\hss
116       \vrule width10mm depth\@tombowwidth height\z@
117       \vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@}%
118   \setbox\@BC\hbox{\yoko
119       \vrule width10mm depth\@tombowwidth height\z@
120       \vrule depth10mm width\@tombowwidth height\z@
121       \vrule width10mm depth\@tombowwidth height\z@}%
122   \setbox\@BR\hbox to\z@{\yoko
123       \vrule depth10mm width\@tombowwidth height\z@
124       \vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@\hss}%
125   \setbox\@Br\hbox to\z@{\yoko
126       \vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@
127       \vrule width10mm depth\@tombowwidth height\z@\hss}%
128   \setbox\@CL\hbox to\z@{\yoko\hss
129       \vrule width10mm height.5\@tombowwidth depth.5\@tombowwidth
130       \vrule height10mm depth10mm width\@tombowwidth}%
131   \setbox\@CR\hbox to\z@{\yoko
132       \vrule height10mm depth10mm width\@tombowwidth
133       \vrule height.5\@tombowwidth depth.5\@tombowwidth width10mm\hss}%
134 }
135 \def\@outputtombow{%
136   \iftombow
137   \vbox to\z@{\kern-\dimexpr 10mm+\@tombowbleed\relax
138     \boxmaxdepth\maxdimen
139       \moveleft\@tombowbleed\vbox to\@@paperheight{%
140           \color@begingroup
141           \@tombowcolor
142       \hbox to\@@paperwidth{\hskip\@tombowbleed\relax
143          \copy\@TL\hfill\copy\@TC\hfill\copy\@TR\hskip\@tombowbleed}%
144       \kern-10mm
145       \hbox to\@@paperwidth{\copy\@Tl\hfill\copy\@Tr}%
146       \vfill
147       \hbox to\@@paperwidth{\copy\@CL\hfill\copy\@CR}%
148       \vfill
149       \hbox to\@@paperwidth{\copy\@Bl\hfill\copy\@Br}%
150       \kern-10mm
151       \hbox to\@@paperwidth{\hskip\@tombowbleed\relax
152          \copy\@BL\hfill\copy\@BC\hfill\copy\@BR\hskip\@tombowbleed}%
153         \color@endgroup
154     }\vss
155   }%
156   \fi
157 }
158 \def\@tombowcolor{\normalcolor}
159 \def\@tombowbleed{3mm}
160 \def\@tombowreset@@paper{%
161      \@@topmargin\topmargin
162      \iftombow
163        \@@paperwidth\paperwidth
164            \advance\@@paperwidth 2\dimexpr\@tombowbleed\relax
165        \@@paperheight\paperheight\advance\@@paperheight 10mm\relax
166            \advance\@@paperheight 2\dimexpr\@tombowbleed\relax
167        \advance\@@topmargin 1in\relax \advance\@themargin 1in\relax
168      \fi
169 }
170 \newdimen\@@paperheight
171 \newdimen\@@paperwidth
172 \newdimen\@@topmargin
173 \def\@outputpage{%
174 \begingroup % the \endgroup is put in by \aftergroup
175   \ifnum\ltjgetparameter{direction}=4\else
176     \dimen\z@\textwidth \textwidth\textheight \textheight\dimen\z@
177   \fi
178   \let \protect \noexpand
179   \language\document@default@language %LaTeX2e 2017/05/01
180   \@resetactivechars
181   \global\let\@@if@newlist\if@newlist
182   \global\@newlistfalse
183   \@parboxrestore
184   \shipout\vbox{\yoko
185     \set@typeset@protect
186     \aftergroup\endgroup
187     \aftergroup\set@typeset@protect
188      \if@specialpage
189        \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
190      \fi
191      \if@twoside
192        \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
193           \ifnum\ltjgetparameter{direction}=3 \let\@themargin\evensidemargin
194           \else\let\@themargin\oddsidemargin\fi
195        \else \let\@thehead\@evenhead
196           \let\@thefoot\@evenfoot
197            \ifnum\ltjgetparameter{direction}=3 \let\@themargin\oddsidemargin
198            \else\let\@themargin\evensidemargin\fi
199      \fi\fi
200      \@tombowreset@@paper
201      \reset@font
202      \normalsize
203      \normalsfcodes
204      \let\label\@gobble
205      \let\index\@gobble
206      \let\glossary\@gobble
207      \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
208     \@begindvi
209     \@outputtombow
210     \vskip \@@topmargin
211     \moveright\@themargin\vbox{%
212       \setbox\@tempboxa \vbox to\headheight{%
213         \vfil
214         \color@hbox
215           \normalcolor
216           \hb@xt@\textwidth{\@thehead}%
217         \color@endbox
218       }%                        %% 22 Feb 87
219       \dp\@tempboxa \z@
220       \box\@tempboxa
221       \vskip \headsep
222       \box\@outputbox
223       \baselineskip \footskip
224       \color@hbox
225         \normalcolor
226         \hb@xt@\textwidth{\@thefoot}%
227       \color@endbox
228     }%
229   }%
230   \global\let\if@newlist\@@if@newlist
231   \global \@colht \textheight
232   \stepcounter{page}%
233   \let\firstmark\botmark
234 }
235
236 %%% Remove extra xkanjiskip
237 \renewcommand\@makefnmark{%
238   \unless\ifnum\ltjgetparameter{direction}=3
239     \hbox{}\hbox{\@textsuperscript{\normalfont\@thefnmark}}\hbox{}%
240   \else\hbox{\yoko \@textsuperscript{\normalfont\@thefnmark}}\fi}
241 \begingroup
242 \@ifpackageloaded{hyperref}
243   {\def\ltj@setrefprefix{real}}
244   {\def\ltj@setrefprefix{}}
245 \expandafter\gdef\csname \ltj@setrefprefix @setref\endcsname#1#2#3{%
246   \ifx#1\relax
247     \protect\G@refundefinedtrue
248     \nfss@text{\reset@font\bfseries ??}%
249     \@latex@warning{Reference `#3' on page \thepage \space
250               undefined}%
251   \else
252     \expandafter#2#1\protect\@setref@{}% change \null to \protect\@setref@{}
253   \fi}
254 \gdef\@setref@{\ifhmode\spacefactor\@m\fi}
255 \endgroup
256 \if@compatibility\else
257 \def\verb{\relax\ifmmode\hbox\else\leavevmode\vadjust{}\fi
258   \bgroup
259     \verb@eol@error \let\do\@makeother \dospecials
260     \verbatim@font\@noligs
261     \language\l@nohyphenation
262     \@ifstar\@sverb\@verb}
263 \fi
264 \patchcmd{\do@noligs}{\kern\z@}{\vadjust{}}{}{} % reported by p_typo
265 \gdef\@stopfield{%
266   \inhibitglue\@tempskipa\lastskip\unskip
267   \hskip\@tempskipa\color@endgroup\egroup}
268 \pretocmd{\footnote}{\inhibitglue}{}{}
269 \pretocmd{\footnotemark}{\inhibitglue}{}{}
270 \patchcmd{\@footnotemark}{\@makefnmark}{%
271   \unless\ifnum\ltjgetparameter{direction}=3 \@makefnmark%
272   \else\hbox to\z@{\hskip-.25\zw\raise.9\zh\@makefnmark\hss}\fi%
273 }{}{}
274 \let\@parboxto\@empty
275 \long\def\@iiiparbox#1#2[#3]#4#5{%
276   \leavevmode
277   \@pboxswfalse
278   \setlength\@tempdima{#4}%
279   \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
280     \ifx\relax#2\else
281       \setlength\@tempdimb{#2}%
282       \edef\@parboxto{to\the\@tempdimb}%
283     \fi
284     \if#1b\vbox
285     \else\if #1t\vtop
286     \else\ifmmode\vcenter
287     \else\@pboxswtrue\null$\vcenter% !!!
288     \fi\fi\fi
289     \@parboxto{\let\hss\vss\let\unhbox\unvbox
290        \csname bm@#3\endcsname}%
291     \if@pboxsw \m@th$\null\fi% !!!
292   \@end@tempboxa}
293 \DeclareRobustCommand\underline[1]{%
294   \relax
295   \ifmmode\@@underline{#1}%
296   \else \leavevmode\null$\@@underline{\hbox{#1}}\m@th$\null\relax\fi}
297
298 \newif\iffnfixbottom
299 \newif\ifltj@ftn@unvboxed
300 %%% @makecol
301 \gdef \@makecol {%
302    \ifvoid\footins
303      \ltj@ftn@unvboxedfalse
304      \setbox\@outputbox \box\@cclv
305    \else
306      \ltj@ftn@unvboxedtrue
307      \setbox\@outputbox \vbox {%
308        \boxmaxdepth \@maxdepth
309        \unvbox \@cclv
310        \iffnfixbottom\vskip\z@ \@plus.0001fil\fi
311        \vskip \skip\footins
312        \color@begingroup
313          \normalcolor
314          \footnoterule
315          \unvbox \footins
316        \color@endgroup
317        }%
318    \fi
319    \let\@elt\relax
320    \xdef\@freelist{\@freelist\@midlist}%
321    \global \let \@midlist \@empty
322    \@combinefloats
323    \ifvbox\@kludgeins
324      \@makespecialcolbox
325    \else
326      \setbox\@outputbox \vbox to\@colht {%
327        \@texttop
328        \dimen@ \dp\@outputbox
329        \unvbox \@outputbox
330        \unless\ifnum\ltjgetparameter{direction}=4\vbox{\hskip\z@}\fi %%% LuaTeX-ja
331        \vskip -\dimen@
332        \ifltj@ftn@unvboxed\iffnfixbottom\else\@textbottom\fi\else\@textbottom\fi
333        }%
334    \fi
335    \global \maxdepth \@maxdepth
336 }
337 \let\ltj@orig@makecol=\@makecol
338
339 \patchcmd\@makespecialcolbox{\@textbottom}{\ifltj@ftn@unvboxed\iffnfixbottom\else\@textbottom\fi\else\@textbottom\fi}{}{}
340
341 \def\@gnewline #1{%
342   \ifvmode
343     \@nolnerr
344   \else
345     \unskip \reserved@e {\reserved@f#1}\nobreak \hfil \break \null
346     % \null は \break の効果が行頭禁則文字で打ち消されないために必要
347   \ignorespaces
348 \fi}
349
350
351 %%%%%% tabular (platex/#43) \@tabclassz
352 \def\ltj@sharp{\relax\pltx@next@inhibitglue\ltjfakeboxbdd\ignorespaces\@sharp\unskip\ltjfakeboxbdd}
353 \def\@tabclassz{%
354   \ifcase\@lastchclass
355     \@acolampacol
356   \or
357     \@ampacol
358   \or
359   \or
360   \or
361     \@addamp
362   \or
363     \@acolampacol
364   \or
365     \@firstampfalse\@acol
366   \fi
367   \edef\@preamble{%
368     \@preamble{%
369       \ifcase\@chnum
370         \hfil\hskip1sp\ltj@sharp\hfil
371       \or
372         \hskip1sp\ltj@sharp\hfil
373       \or
374         \hfil\hskip1sp\ltj@sharp
375       \fi}}}
376 \patchcmd\@classv{%
377    \ignorespaces\@sharp
378 }{%
379    \everypar\expandafter{\the\everypar\ltjfakeboxbdd}\ignorespaces\@sharp\unskip
380 }{}{}
381 \patchcmd{\@tabular}{\leavevmode}{\leavevmode\null}{}{}
382 \apptocmd{\endtabular}{\null}{}{}
383 \expandafter \let \csname endtabular*\endcsname = \endtabular
384
385 %%%%%% tabbing (platex/#53)
386 \patchcmd\@startline{\strut}{\strut\inhibitglue}{}{}
387 \def\ltj@unhbox@curfield{\ltjfakeboxbdd\unhbox\@curfield\ltjfakeboxbdd}
388 %\patchcmd\@contfield{\unhbox\@curfield}{\ltj@unhbox@curfield}{}{}
389 \patchcmd\@addfield{\unhbox\@curfield}{\ltj@unhbox@curfield}{}{}
390 \endinput