OSDN Git Service

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