OSDN Git Service

a6ad8ad905dbdd6d92386228afa219a09dcdfc6f
[luatex-ja/luatexja.git] / src / lltjext.sty
1 %
2 % lltjext.sty: derived from plext.sty in pLaTeX.
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjext}[2022-08-18 v1.2k-ltj-14 Macros for vertical writing]
7 \RequirePackage{luatexja}
8 \newcount\ltj@ext@dir
9 \let\ltj@lltjext@orig@tabular=\tabular
10 \let\ltj@lltjext@orig@array=\array
11
12 %%% array and tabular
13 \def\array{\let\@acol\@arrayacol \let\@classz\@arrayclassz
14  \let\@classiv\@arrayclassiv
15  \let\\\@arraycr\let\@halignto\@empty
16  \ltj@ext@dir=\ltjgetparameter{direction}\relax\X@tabarray}
17 \def\tabular{\let\@halignto\@empty\X@tabular}
18 \@namedef{tabular*}{\@ifnextchar<%>
19    {\p@stabular}{\p@stabular<Z>}}
20 {\catcode`\*=11
21 \global\let\ltj@lltjext@orig@tabularS=\tabular*
22 }%
23 \def\X@tabarray{\@ifnextchar<%>
24    {\p@tabarray}{\p@tabarray<Z>}}
25 \def\X@tabular{\@ifnextchar<%>
26    {\p@tabular}{\p@tabular<Z>}}
27 \def\p@stabular<#1>#2{%
28    \setlength\dimen@{#2}%
29    \edef\@halignto{to\the\dimen@}\p@tabular<#1>}
30 \def\p@tabular<#1>{\leavevmode \hbox \bgroup 
31    \ltj@ext@dir=\ltjgetparameter{direction}\relax
32    $\let\@acol\@tabacol
33    \let\@classz\@tabclassz
34    \let\@classiv\@tabclassiv \let\\\@tabularcr\p@tabarray<#1>}
35 \def\p@tabarray<#1>{\m@th\@ifnextchar[%]
36    {\p@array<#1>}{\p@array<#1>[c]}}
37
38 \def\p@array<#1>[#2]#3{%
39   \ifnum\ltj@ext@dir=0 \ltj@ext@dir=\ltjgetparameter{direction}\relax\fi
40   \let\box@dir\relax
41   \if #1z\relax
42     \ifnum\ltj@ext@dir=3\relax
43       \let\box@dir\utod\@tempcnta=\zstrutbox
44     \fi
45   \else
46     \if #1y\relax
47        \let\box@dir\yoko\@tempcnta=\ystrutbox
48     \else\if #1t\relax
49        \let\box@dir\tate\@tempcnta=\tstrutbox
50     \else\if #1d\relax
51        \let\box@dir\dtou\@tempcnta=\dstrutbox
52     \else\if #1u\relax
53        \let\box@dir\utod\@tempcnta=\zstrutbox
54     \fi\fi\fi\fi
55   \fi
56   \ifx\box@dir\relax
57     \ifcase\ltj@ext@dir
58        \or   \let\box@dir\dtou\@tempcnta=\dstrutbox% dtou
59        \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
60        \or   \let\box@dir\yoko\@tempcnta=\ystrutbox% yoko
61        \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
62     \fi
63   \fi
64   \fork@array@option<#1>[#2]\@begin@alignbox
65   \bgroup\box@dir\adjustbaseline
66   \setbox\@arstrutbox\hbox{%
67     \box@dir
68     \vrule\@height\arraystretch\ltjgetht\@tempcnta
69           \@depth\arraystretch\ltjgetdp\@tempcnta \@width\z@}%
70   \@mkpream{#3}\edef\@preamble{\ialign \noexpand\@halignto
71   \bgroup\@arstrut \@preamble \tabskip\z@skip \cr}%
72   \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
73   \let\tabularnewline\\%
74     \let\par\@empty
75     \let\@sharp##%
76         \set@typeset@protect
77     \lineskip\z@skip\baselineskip\z@skip
78     \ifhmode \@preamerr\z@ \@@par\fi
79         \@preamble}
80 \def\endarray{\crcr\egroup\egroup\@end@alignbox}
81 \def\endtabular{\endarray$\egroup}
82 \expandafter \let \csname endtabular*\endcsname = \endtabular
83 % ↓中身\周囲→ yoko  tate  utod  dtou
84 % yoko          A*    B*    B     B
85 % tate          B*    A*    D     C
86 % utod          B     D*    A     C
87 % dtou          B     C     C     A
88 % A: 周囲と中身の組方向が一致.そのまま \vtop/\vcenter/\vbox
89 % B: 周囲と中身が90度ずれ.上端/下端がベースラインに揃うように
90 % C: 周囲と中身が180度ずれ.\vtop, \vbox 入れ替え
91 % D: 欧文ベースライン同士を揃えるようにする
92
93 \def\fork@array@option@@A#1{%
94   \let\@end@alignbox\relax
95   \if #1t\relax     \let\@begin@alignbox\vtop
96   \else\if #1b\relax\let\@begin@alignbox\vbox
97   \else             \let\@begin@alignbox\vcenter
98   \fi\fi}
99 \def\fork@array@option@@B#1{%
100   \if #1t\relax
101     \def\@begin@alignbox{\vtop\bgroup\kern\z@\vbox}%
102     \let\@end@alignbox\egroup
103   \else\if #1b\relax
104     \def\@begin@alignbox{\vbox\bgroup\vbox}%
105     \def\@end@alignbox{\kern\z@\egroup}%
106   \else
107     \let\@begin@alignbox\vcenter
108     \let\@end@alignbox\relax
109   \fi\fi}
110 \def\fork@array@option@@C#1{%
111   \let\@end@alignbox\relax
112   \if #1t\relax     \let\@begin@alignbox\vbox
113   \else\if #1b\relax\let\@begin@alignbox\vtop
114   \else             \let\@begin@alignbox\vcenter
115   \fi\fi}
116 \def\fork@array@option<#1>[#2]{%
117 \ifnum\ltj@ext@dir=4 % yoko
118   \ifx\box@dir\yoko      \fork@array@option@@A{#2}%
119   \else                  \fork@array@option@@B{#2}%
120   \fi
121 \else\ifnum\ltj@ext@dir=1 % dtou
122   \ifx\box@dir\yoko      \fork@array@option@@B{#2}%
123   \else\ifx\box@dir\dtou \fork@array@option@@A{#2}%
124   \else                  \fork@array@option@@C{#2}%
125   \fi\fi
126 \else\ifnum\ltj@ext@dir=3 % tate
127   \ifx\box@dir\yoko      \fork@array@option@@B{#2}%
128   \else\ifx\box@dir\tate \fork@array@option@@A{#2}%
129   \else\ifx\box@dir\dtou \fork@array@option@@C{#2}%
130   \else
131     \if #2t\relax
132       \def\@begin@alignbox{\lower\dimexpr
133          \ltjgetparameter{talbaselineshift}-\ltjgetparameter{yalbaselineshift}\vtop}
134       \let\@end@alignbox\relax
135     \else\if #2b\relax
136       \def\@begin@alignbox{\lower\dimexpr
137          \ltjgetparameter{talbaselineshift}-\ltjgetparameter{yalbaselineshift}\vbox}
138       \let\@end@alignbox\relax
139     \else
140       \let\@begin@alignbox\vcenter
141       \let\@end@alignbox\relax
142     \fi\fi
143   \fi\fi\fi
144 \else % utod
145   \ifx\box@dir\yoko      \fork@array@option@@B{#2}%
146   \else\ifx\box@dir\utod \fork@array@option@@A{#2}%
147   \else\ifx\box@dir\dtou \fork@array@option@@C{#2}%
148   \else
149     \if #2t\relax
150       \def\@begin@alignbox{\lower\dimexpr
151          \ltjgetparameter{yalbaselineshift}-\ltjgetparameter{talbaselineshift}\vtop}
152       \let\@end@alignbox\relax
153     \else\if #2b\relax
154       \def\@begin@alignbox{\lower\dimexpr
155          \ltjgetparameter{yalbaselineshift}-\ltjgetparameter{talbaselineshift}\vbox}
156       \let\@end@alignbox\relax
157     \else
158       \let\@begin@alignbox\vcenter
159       \let\@end@alignbox\relax
160     \fi\fi
161   \fi\fi\fi
162 \fi\fi\fi}
163
164 %%% caption
165 \newbox\@floatbox
166 \newdimen\floatwidth
167 \newdimen\floatheight
168 \newdimen\floatruletick \floatruletick=0.4pt
169 \newdimen\captionfloatsep \captionfloatsep=10pt
170 \def\caption@dir{Z}
171 \let\captiondir\relax
172 \newdimen\captionwidth \captionwidth\z@
173 \def\caption@posa{Z}
174 \def\caption@posb{Z}
175 \newbox\@captionbox
176 \def\captionfontsetup{\normalfont\normalsize}
177 \def\layoutfloat{\@ifnextchar(%)
178    {\X@layoutfloat}{\X@layoutfloat(-5\p@,-5\p@)}}
179 \def\X@layoutfloat(#1,#2){\@ifnextchar[%]
180    {\@layoutfloat(#1,#2)}{\@layoutfloat(#1,#2)[c]}}
181 \long\def\@layoutfloat(#1,#2)[#3]#4{%
182   \setbox\z@\hbox{#4}%
183   \floatwidth=#1 \floatheight=#2 \edef\float@pos{#3}%
184   \ifdim\floatwidth<\z@
185      \floatwidth\ltjgetwd\z@\floatruletick\z@
186   \fi
187   \ifdim\floatheight<\z@
188      \floatheight\ltjgetht\z@\advance\floatheight\ltjgetdp\z@\relax
189      \floatruletick\z@
190   \fi
191   \setbox\@floatbox\vbox to\floatheight{\offinterlineskip
192     \hrule width\floatwidth height\floatruletick depth\z@
193     \vss\hbox to\floatwidth{%
194       \vrule width\floatruletick height\floatheight depth\z@
195       \hss\vbox to\floatheight{\hsize\floatwidth\vss#4\vss}\hss
196       \vrule width\floatruletick height\floatheight depth\z@
197     }\hrule width\floatwidth height\floatruletick depth\z@}}
198 \def\DeclareLayoutCaption#1<#2>(#3)[#4#5]{%
199   \expandafter
200   \ifx\csname #1@layoutc@ption\endcsname\relax \else
201     \@latex@info{Redeclaring capiton layout setting of '#1'}%
202   \fi
203   \expandafter
204   \gdef\csname #1@layoutc@ption\endcsname{%
205      \if Z\caption@dir\def\caption@dir{#2}\fi
206      \ifdim\captionwidth=\z@ \captionwidth=#3\relax\fi
207      \if Z\caption@posa\def\caption@posa{#4}\fi
208      \if Z\caption@posb\def\caption@posb{#5}\fi}}
209 \@onlypreamble\DeclareLayoutCaption
210 \DeclareLayoutCaption{figure}<n>(.8\linewidth)[cd]
211 \DeclareLayoutCaption{table}<n>(.8\linewidth)[cu]
212 \def\layoutcaption{\def\caption@dir{Z}\captionwidth\z@
213   \def\caption@posa{Z}\def\caption@posb{Z}%
214   \@ifnextchar<\X@layoutcaption{%
215     \@ifnextchar(\@ilayoutcaption{%
216       \@ifnextchar[\@iilayoutcaption\relax}}}
217 \def\X@layoutcaption<#1>{\def\caption@dir{#1}%
218   \@ifnextchar(\@ilayoutcaption{%
219     \@ifnextchar[\@iilayoutcaption\relax}}
220 \def\@ilayoutcaption(#1){\setlength\captionwidth{#1}%
221   \@ifnextchar[{\@iilayoutcaption}{\relax}}
222 \def\@iilayoutcaption[#1#2]{%
223   \def\caption@posa{#1}\def\caption@posb{#2}}
224 \def\pcaption{%
225   \ifx\@captype\@undefined
226     \@latex@error{\noexpand\pcaption outside float}\@ehd
227     \expandafter\@gobble
228   \else
229     \refstepcounter\@captype
230     \expandafter\@firstofone
231   \fi
232   {\@dblarg{\@pcaption\@captype}}%
233 }
234 \long\def\@pcaption#1[#2]#3{%
235   \addcontentsline{\csname ext@#1\endcsname}{#1}{%
236     \protect\numberline{\csname the#1\endcsname}{\ignorespaces#2}}%
237   \ifvoid\@floatbox
238      \@latex@error{Use \noexpand\pcaption with `\protect\layoutfloat'}\@eha
239   \fi
240   \make@pcaptionbox{#3}%
241   \@pboxswfalse
242   \setbox\@tempboxa\vbox{\hbox to\hsize{\if l\float@pos\else\hss\fi
243     \if l\caption@posb\box\@captionbox\kern\captionfloatsep\fi
244     \if t\caption@posa\vtop
245     \else\if b\caption@posa\vbox
246     \else\@pboxswtrue $\vcenter \fi\fi
247     {\if u\caption@posb\box\@captionbox\kern\captionfloatsep\fi
248      \unvbox\@floatbox
249      \if d\caption@posb\kern\captionfloatsep\box\@captionbox\fi}%
250     \if@pboxsw \m@th$\fi
251     \if r\caption@posb\kern\captionfloatsep\box\@captionbox\fi
252     \if r\float@pos\else\hss\fi}}%
253   \par\vskip.25\baselineskip
254   \box\@tempboxa}
255 \def\make@pcaptionbox#1{%
256   \expandafter
257   \ifx\csname\@captype @layoutc@ption\endcsname\relax
258      \@latex@warning{Default caption layout of `\@captype' unknown.}%
259        \def\caption@dir{Z}\captionwidth\z@
260        \def\caption@posa{Z}\def\caption@posb{Z}%
261   \else
262      \csname \@captype @layoutc@ption\endcsname
263   \fi
264   \@tempswafalse
265   % \@tempswa: 基本組の組方向とキャプションの組方向が直交するか?
266   \if y\caption@dir \let\captiondir\yoko
267     \ifodd\ltjgetparameter{direction}\relax\@tempswatrue\fi
268   \else\if z\caption@dir \let\captiondir\relax
269     \ifnum\ltjgetparameter{direction}=3\relax\let\captiondir\utod\fi
270   \else\if d\caption@dir \let\captiondir\dtou
271     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
272   \else\if u\caption@dir \let\captiondir\utod
273     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
274   \else\if t\caption@dir \let\captiondir\tate
275     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
276   \fi\fi\fi\fi\fi
277   \setbox0\hbox{\hbox{\captiondir
278      \captionfontsetup\parindent\z@\inhibitglue
279      \csname fnum@\@captype\endcsname  #1}}%"
280   \if@tempswa\@tempdima\ltjgetht0 \advance\@tempdima\ltjgetdp0
281   \else\@tempdima\ltjgetwd0 \fi
282   \ifdim\@tempdima>\captionwidth \@tempdima\captionwidth \fi
283   \@pboxswfalse
284   \setbox0\hbox{%
285     \if u\caption@posb\vbox
286     \else\if d\caption@posb\vbox
287     \else\if t\caption@posa\vtop
288     \else\if b\caption@posa\vbox
289     \else\ifmmode\vcenter\else\@pboxswtrue $\vcenter\fi
290     \fi\fi\fi\fi
291     {\hsize\@tempdima\kern\z@
292     \vbox{\captiondir\hsize\@tempdima
293       \captionfontsetup\parindent\z@\inhibitglue
294       \csname fnum@\@captype\endcsname  #1}\kern\z@
295     }\if@pboxsw \m@th$\fi}%
296   \let\to@captionboxwidth\relax
297   \if l\caption@posb \else\if r\caption@posb\else
298   \def\to@captionboxwidth{to\floatwidth}\fi\fi
299   \setbox\@captionbox\hbox\to@captionboxwidth{%
300      \if t\caption@posa\else\hss\fi
301      \unhbox0\relax
302      \if b\caption@posa\else\hss\fi}}
303
304 %%% minipage and parbox
305 \def\minipage{\@ifnextchar<%>
306    {\X@minipage}{\X@minipage<Z>}}
307 \def\X@minipage<#1>{\@ifnextchar[%]
308    {\@iminipage<#1>}{\@iiiminipage<#1>{c}\relax[s]}}
309 \def\@iminipage<#1>[#2]{\@ifnextchar[%]
310    {\@iiminipage<#1>{#2}}{\@iiiminipage<#1>{#2}\relax[s]}}
311 \def\@iiminipage<#1>#2[#3]{\@ifnextchar[%]
312    {\@iiiminipage<#1>{#2}{#3}}{\@iiiminipage<#1>{#2}{#3}[#2]}}
313 \def\@iiiminipage<#1>#2#3[#4]#5{%
314   \leavevmode\bgroup
315   \setlength\@tempdima{#5}%
316   \def\@mpargs{<#1>{#2}{#3}[#4]{#5}}%
317   \let\box@dir\relax
318   \if #1z\relax
319     \ifnum\ltjgetparameter{direction}=3\relax
320       \let\box@dir\utod
321     \fi
322   \else
323     \if #1y\relax     \let\box@dir\yoko
324     \else\if #1t\relax\let\box@dir\tate
325     \else\if #1d\relax\let\box@dir\dtou
326     \else\if #1u\relax\let\box@dir\utod
327     \fi\fi\fi\fi
328   \fi
329   \ifx\box@dir\relax
330     \ifcase\ltjgetparameter{direction}\relax
331        \or   \let\box@dir\dtou
332        \or\or\let\box@dir\tate
333        \or   \let\box@dir\yoko
334        \else \let\box@dir\utod
335     \fi
336   \fi
337   \setbox\@tempboxa\vbox\bgroup\box@dir
338     \adjustbaseline
339     \color@begingroup
340       \hsize\@tempdima
341       \textwidth\hsize \columnwidth\hsize
342       \@parboxrestore
343       \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}%
344       \c@mpfootnote\z@
345       \let\@footnotetext\@mpfootnotetext
346       \let\@listdepth\@mplistdepth \@mplistdepth\z@
347       \@minipagerestore
348       \@setminipage}
349 \def\endminipage{%
350     \par
351     \unskip
352     \ifvoid\@mpfootins\else
353       \vskip\skip\@mpfootins
354       \normalcolor
355       \footnoterule
356       \unvbox\@mpfootins
357     \fi
358     \@minipagefalse   %% added 24 May 89
359   \color@endgroup
360   \egroup
361   \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}\egroup}
362 \DeclareRobustCommand\parbox{\@ifnextchar<%>
363    {\X@parbox}{\X@parbox<Z>}}
364 \def\X@parbox<#1>{\@ifnextchar[%]
365    {\@iparbox<#1>}{\@iiiparbox<#1>{c}\relax[s]}}
366 \def\@iparbox<#1>[#2]{\@ifnextchar[%]
367    {\@iiparbox<#1>{#2}}{\@iiiparbox<#1>{#2}\relax[s]}}
368 \def\@iiparbox<#1>#2[#3]{\@ifnextchar[%]%
369    {\@iiiparbox<#1>{#2}{#3}}{\@iiiparbox<#1>{#2}{#3}[#2]}}
370 \long\def\@iiiparbox<#1>#2#3[#4]#5#6{%
371   \leavevmode
372   \setlength\@tempdima{#5}%
373   \fork@parbox@option<#1>[#2]%
374   \@begin@tempboxa\vbox{\box@dir
375     \hsize\@tempdima\@parboxrestore\adjustbaseline#6\@@par}%
376     \ifx\relax#3\else
377       \setlength\@tempdimb{#3}%
378       \edef\@parboxto{to\the\@tempdimb}%
379     \fi
380     \@begin@parbox\@parboxto{\box@dir\adjustbaseline
381        \let\hss\vss\let\unhbox\unvbox
382        \csname bm@#4\endcsname}\@end@parbox
383   \@end@tempboxa}
384
385
386 % ↓中身\周囲→ yoko  tate  utod  dtou
387 % yoko          A*    B*    B     B
388 % tate          B*    A*    D     C
389 % utod          B     D*    A     C
390 % dtou          B     C     C     A
391 % A: 周囲と中身の組方向が一致.そのまま \vtop/\vcenter/\vbox
392 % B: 周囲と中身が90度ずれ.上端が和文の高さ or 下端が和文の深さに揃うように
393 % C: 周囲と中身が180度ずれ.(コードは B のものを流用)
394 % D: 上端が和文の高さ or 下端が和文の深さに揃うように(コードは B のものを流用)
395
396 \def\fork@parbox@option@@A#1{%
397   \let\@end@parbox\relax
398   \if #1t\relax     \let\@begin@parbox\vtop
399   \else\if #1b\relax\let\@begin@parbox\vbox
400   \else
401     \ifmmode
402       \let\@begin@parbox\vcenter\let\@end@parbox\relax
403     \else
404       \def\@begin@parbox{\null$\vcenter}%
405       \def\@end@parbox{\m@th$\null}%
406     \fi
407   \fi\fi}
408 \def\lltjext@getjablshift{%
409   \ifnum\ltj@ext@dir=3 \ltjgetparameter{tjabaselineshift}\else
410   \ltjgetparameter{yjabaselineshift}\fi}
411 \def\fork@parbox@option@@B#1{%
412   \if #1t\relax
413     \def\@begin@parbox{\raise\dimexpr\cht-\lltjext@getjablshift\vtop\bgroup\kern\z@\vbox}%
414     \let\@end@parbox\egroup
415   \else\if #1b\relax
416     \def\@begin@parbox{\lower\dimexpr\cdp+\lltjext@getjablshift\vbox\bgroup\vbox}%
417     \def\@end@parbox{\kern\z@\egroup}%
418   \else
419     \ifmmode
420       \let\@begin@parbox\vcenter\let\@end@parbox\relax
421     \else
422       \def\@begin@parbox{\null$\vcenter}%
423       \def\@end@parbox{\m@th$\null}%
424     \fi
425   \fi\fi}
426 \let\fork@parbox@option@@C=\fork@parbox@option@@B
427 \def\fork@parbox@option<#1>[#2]{%
428   \let\box@dir\relax \ltj@ext@dir=\ltjgetparameter{direction}\relax
429   \if #1z\relax
430     \ifnum\ltj@ext@dir=3\relax
431       \let\box@dir\utod
432     \fi
433   \else
434     \if #1y\relax     \let\box@dir\yoko
435     \else\if #1t\relax\let\box@dir\tate
436     \else\if #1d\relax\let\box@dir\dtou
437     \else\if #1u\relax\let\box@dir\utod
438     \fi\fi\fi\fi
439   \fi
440   \ifx\box@dir\relax
441     \ifcase\ltj@ext@dir
442        \or   \let\box@dir\dtou
443        \or\or\let\box@dir\tate
444        \or   \let\box@dir\yoko
445        \else \let\box@dir\utod
446     \fi
447   \fi
448 \ifnum\ltj@ext@dir=4 % yoko
449   \ifx\box@dir\yoko      \fork@parbox@option@@A{#2}%
450   \else                  \fork@parbox@option@@B{#2}%
451   \fi
452 \else\ifnum\ltj@ext@dir=1 % dtou
453   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
454   \else\ifx\box@dir\dtou \fork@parbox@option@@A{#2}%
455   \else                  \fork@parbox@option@@C{#2}%
456   \fi\fi
457 \else\ifnum\ltj@ext@dir=3 % tate
458   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
459   \else\ifx\box@dir\tate \fork@parbox@option@@A{#2}%
460   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
461   \else                  \fork@parbox@option@@B{#2}% D
462   \fi\fi\fi
463 \else % utod
464   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
465   \else\ifx\box@dir\utod \fork@parbox@option@@A{#2}%
466   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
467   \else                  \fork@parbox@option@@B{#2}% D
468   \fi\fi\fi
469 \fi\fi\fi}
470
471 %%% pbox
472 \DeclareRobustCommand\pbox{\leavevmode\@ifnextchar<{\X@makePbox}{\X@makePbox<Z>}}
473 \def\X@makePbox<#1>{%
474   \@ifnextchar[{\@imakePbox<#1>}{\@imakePbox<#1>[-5\p@]}}
475 \def\@imakePbox<#1>[#2]{\@ifnextchar[%]
476   {\@iimakePbox<#1>{#2}}{\@iimakePbox<#1>{#2}[c]}}
477 \def\@iimakePbox<#1>#2[#3]#4{%
478   \bgroup\let\box@dir\relax
479   \if #1z\relax
480     \ifnum\ltjgetparameter{direction}=3 \relax
481       \let\box@dir\utod
482     \fi
483   \else
484     \if #1y\relax     \let\box@dir\yoko
485     \else\if #1t\relax\let\box@dir\tate
486     \else\if #1d\relax\let\box@dir\dtou
487     \else\if #1u\relax\let\box@dir\utod
488     \fi\fi\fi\fi
489   \fi
490   \ifx\box@dir\relax
491     \ifcase\ltjgetparameter{direction}
492        \or   \let\box@dir\dtou
493        \or\or\let\box@dir\tate
494        \or   \let\box@dir\yoko
495        \else \let\box@dir\utod
496     \fi
497   \fi
498     \setlength{\@tempdima}{#2}%
499     \ifdim\@tempdima<\z@ \hbox{\box@dir#4}\else
500     \hb@xt@\@tempdima{\box@dir
501                \if #3l\relax\else\hss\fi
502                #4\relax
503                \if #3r\relax\else\hss\fi}\fi\egroup}
504
505 %%% picture
506 \def\picture{\@ifnextchar<%>
507    {\X@picture}{\X@picture<Z>}}
508 \def\X@picture<#1>(#2,#3){\@ifnextchar(%)
509    {\@@picture<#1>(#2,#3)}{\@@picture<#1>(#2,#3)(0,0)}}
510 \newdimen\@picwd
511 \def\ltj@@pic@reset@blshift{%
512   \unsetattribute\ltj@yablshift\unsetattribute\ltj@ykblshift
513   \unsetattribute\ltj@tablshift\unsetattribute\ltj@tkblshift
514 }%
515 \def\@@picture<#1>(#2,#3)(#4,#5){%
516   \edef\ltj@@pic@save@blshift{%
517     \noexpand\ltj@yablshift\the\ltj@yablshift\noexpand\relax
518     \noexpand\ltj@ykblshift\the\ltj@ykblshift\noexpand\relax
519     \noexpand\ltj@tablshift\the\ltj@tablshift\noexpand\relax
520     \noexpand\ltj@tkblshift\the\ltj@tkblshift\noexpand\relax
521   }%
522   \bgroup\let\box@dir\relax
523   \if #1z\relax
524     \ifnum\ltjgetparameter{direction}=3 \relax
525       \let\box@dir\utod
526     \fi
527   \else
528     \if #1y\relax     \let\box@dir\yoko
529     \else\if #1t\relax\let\box@dir\tate
530     \else\if #1d\relax\let\box@dir\dtou
531     \else\if #1u\relax\let\box@dir\utod
532     \fi\fi\fi\fi
533   \fi
534   \ifx\box@dir\relax
535     \ifcase\ltjgetparameter{direction}
536        \or   \let\box@dir\dtou
537        \or\or\let\box@dir\tate
538        \or   \let\box@dir\yoko
539        \else \let\box@dir\utod
540     \fi
541   \fi
542 \ifltj@ltfilehook@avail % LaTeX2e >= 2020-10-01
543   \@defaultunitsset\@picht{#3}\unitlength
544   \@defaultunitsset\@picwd{#2}\unitlength
545   \setbox\@picbox\hbox to\@picwd\bgroup\box@dir
546     \@defaultunitsset\@tempdimc{#4}\unitlength\hskip-\@tempdimc
547     \@defaultunitsset\@tempdimc{#5}\unitlength\lower\@tempdimc\hbox\bgroup
548 \else % <= 2020-02-02
549   \@picwd=#2\unitlength \@picht=#3\unitlength
550   \setbox\@picbox\hbox to\@picwd\bgroup\box@dir
551   \hskip-#4\unitlength\lower#5\unitlength\hbox\bgroup
552 \fi
553   \ltj@@pic@reset@blshift
554   \ignorespaces}
555 \def\endpicture{%
556   \egroup\hss\egroup
557   \setbox0=\hbox{\box@dir%
558     \ltjsetht\@picbox\@picht \ltjsetdp\@picbox\z@
559   }%
560   \@tempswafalse
561   \ifnum\ltjgetparameter{direction}=3  \@tempswatrue\fi
562   \ifnum\ltjgetparameter{direction}=11  \@tempswatrue\fi
563   \if@tempswa
564     \ifx\box@dir\yoko % この場合だけ垂直位置補正が必要
565      \ltjsetht\@picbox\dimexpr\ltjgetht\@picbox+\ltjgetdp\@picbox\relax
566       \ltjsetdp\@picbox\z@
567     \fi
568   \fi
569   \mbox{\box\@picbox}%
570   \egroup\ltj@@pic@save@blshift}
571 \let\org@put\put
572 \def\put{\ltj@@pic@reset@blshift\org@put}
573 \let\org@line\line
574 \def\line{\ltj@@pic@reset@blshift\org@line}
575 \let\org@vector\vector
576 \def\vector{\ltj@@pic@reset@blshift\org@vector}
577 \let\org@dashbox\dashbox
578 \def\dashbox{\ltj@@pic@reset@blshift\org@dashbox}
579 \let\org@oval\oval
580 \def\oval{\ltj@@pic@reset@blshift\org@oval}
581 \let\org@circle\circle
582 \def\circle{\ltj@@pic@reset@blshift\org@circle}
583
584 %%% rensuji
585 \newif\ifnot@advanceline
586 \newskip\rensujiskip
587 \rensujiskip=0.25\chs plus.25\zw minus.25\zw
588 \DeclareRobustCommand\rensuji{%
589   \@ifstar{\not@advancelinetrue\@rensuji}{\@rensuji}}
590 \def\@rensuji{\@ifnextchar[{\@@rensuji}{\@@rensuji[c]}}
591 \def\@@rensuji[#1]#2{%
592   \ifvmode\leavevmode\fi
593   \ifnum\ltjgetparameter{direction}=4\relax\hbox{#2}\else
594   \hskip\rensujiskip
595   \setbox\tw@\hbox{漢}% 「あ」では仮名書体使用時がまずそう
596   \@tempdimb\ltjgetht\tw@ \advance\@tempdimb\ltjgetdp\tw@
597   \ifnot@advanceline\not@advancelinefalse\else
598     \setbox\z@\hbox{\yoko#2}%
599     \@tempdima\ltjgetht\z@ \advance\@tempdima\ltjgetdp\z@
600     \ifnum\ltjgetparameter{direction}=1\relax
601       % 周囲が dtou の場合には,高さ \ltjgetht\tw@, 深さ \ltjgetdp\tw@ のボックスを基準としている.
602       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
603                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
604       \else\if #1l\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
605       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
606       \fi\fi
607     \else
608       % 周囲が tate, utod の場合も同じ
609       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
610                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
611       \else\if #1r\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
612       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
613       \fi\fi
614     \fi
615   \fi
616   \ifnum\ltjgetparameter{direction}=1\relax
617     \if #1c\relax\hbox to\@tempdimb{\yoko\hss#2\hss\kern-\ltjgetdp\tw@}%
618     \else\if #1r\relax\vbox{\hbox to\@tempdimb{\yoko\hss#2\kern-\ltjgetdp\tw@}}%
619     \else\lower\ltjgetdp\tw@\vtop{\hbox to\@tempdimb{\yoko#2\hss}}%
620     \fi\fi
621   \else
622     \if #1c\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
623         \hbox to\@tempdimb{\yoko \hss#2\hss}%
624     \else\if #1r\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
625         \vbox{\hbox to\@tempdimb{\yoko\hss#2}}%
626     \else\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
627          \vtop{\hbox to\@tempdimb{\yoko #2\hss}}%
628     \fi\fi
629   \fi
630   \hskip\rensujiskip
631 \fi}
632 \let\Rensuji\rensuji
633 \let\prensuji\rensuji
634
635 %%% kanji
636 \def\Kanji#1{\expandafter\@Kanji\csname c@#1\endcsname}
637 \def\@Kanji#1{\kansuji #1}
638 \def\kanji{\ifnum\ltjgetparameter{direction}=3 \expandafter\kansuji\fi}
639
640 %%% bou
641 %%%
642 \def\boutenchar{\char\euc"A1A2}%"
643 \DeclareRobustCommand\bou[1]{\ifvmode\leavevmode\fi\@bou#1\end}
644 \def\@bou#1{%
645   \ifx#1\end \let\ltj@@next=\relax
646   \else
647     \ifnum\ltjgetparameter{direction}=3\relax
648       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
649         \vss\moveleft0.2\zw\hbox{\yoko\boutenchar}\nointerlineskip
650         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
651     \else
652       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
653         \vss\moveleft-0.2\zw\hbox{\boutenchar}\nointerlineskip
654         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
655     \fi
656     \let\ltj@@next=\@bou
657   \fi\ltj@@next}
658
659 %%% kasen
660 \DeclareRobustCommand\kasen[1]{%
661   \ifnum\ltjgetparameter{direction}=3\relax
662     \setbox\z@\hbox{#1}\leavevmode\raise.7\zw
663     \hbox to\z@{\vrule\@width\wd\z@ \@depth\z@ \@height.4\p@\hss}%
664     \box\z@
665   \else\underline{#1}\fi}
666
667 %%% references
668 \def\@eqnnum{{\reset@font\rmfamily \normalcolor
669   \ifnum\ltjgetparameter{direction}=11\raise.25\zh\hbox{\yoko(\theequation)}%
670   \else (\theequation)\fi}}
671 \def\@thecounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
672 \def\@thmcounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
673
674 %% Compatibility with array package
675
676 \def\ltj@lltjext@patch@array{%
677   \patchcmd{\@tabular}{\hbox\bgroup}{%
678         \hbox\bgroup\ltj@ext@dir=\ltjgetparameter{direction}\relax}{}{}
679   \pretocmd{\array}%
680         {\ltj@ext@dir=\ltjgetparameter{direction}\relax}{}{}
681   \expandafter\let\csname tabular*\endcsname=\ltj@lltjext@orig@tabularS
682   \patchcmd{\p@stabular}{\p@tabular}{\@tabular}{}{}
683   \@ifpackagelater{array}{2018/09/13}
684     {\expandafter\@firstoftwo}
685     {\expandafter\@secondoftwo}
686   {% = for 2018/09/13 v2.4i or newer
687   \def\@startpbox##1{\bgroup
688     \color@begingroup
689     \box@dir\adjustbaseline%%% これを追加
690     \setlength\hsize{##1}\@arrayparboxrestore
691       \everypar{%
692          \vrule \@height \ltjgetht\@arstrutbox \@width \z@
693          \everypar{}}%
694       }%
695   }{ % = for 2018/04/30 v2.4h or older
696   \def\@startpbox##1{\bgroup
697     \box@dir\adjustbaseline%%% これを追加
698     \setlength\hsize{##1}\@arrayparboxrestore
699       \everypar{%
700          \vrule \@height \ltjgetht\@arstrutbox \@width \z@
701          \everypar{}}%
702       }%
703   }%
704   \def\@tabarray{\@ifnextchar<\p@tabarray{\p@tabarray<Z>}}
705   \def\p@array<##1>[##2]##3{%
706     \ifnum\ltj@ext@dir=0 \ltj@ext@dir=\ltjgetparameter{direction}\relax\fi
707     \let\box@dir\relax
708     \if ##1z\relax
709       \ifnum\ltj@ext@dir=3\relax
710         \let\box@dir\utod\@tempcnta=\zstrutbox
711       \fi
712     \else
713       \if ##1y\relax
714         \let\box@dir\yoko\@tempcnta=\ystrutbox
715       \else\if ##1t\relax
716         \let\box@dir\tate\@tempcnta=\tstrutbox
717       \else\if ##1d\relax
718          \let\box@dir\dtou\@tempcnta=\dstrutbox
719       \else\if ##1u\relax
720          \let\box@dir\utod\@tempcnta=\zstrutbox
721       \fi\fi\fi\fi
722     \fi
723     \ifx\box@dir\relax
724       \ifcase\ltj@ext@dir
725          \or   \let\box@dir\dtou\@tempcnta=\dstrutbox% dtou
726          \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
727          \or   \let\box@dir\yoko\@tempcnta=\ystrutbox% yoko
728          \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
729       \fi
730     \fi
731     \setbox \@arstrutbox \hbox{\box@dir\vrule
732                \@height \arraystretch
733                  \dimexpr \ltjgetht\@tempcnta+\extrarowheight\relax
734                \@depth \arraystretch \ltjgetdp \@tempcnta
735                \@width \z@}%
736     \fork@array@option<##1>[##2]%
737     \begingroup
738     \@mkpream{##3}%
739     \xdef\@preamble{\noexpand\ialign \noexpand \@halignto
740                     \bgroup \tabskip \z@skip \@arstrut \@preamble
741                             \tabskip \z@ \cr}%
742     \endgroup
743     \@arrayleft
744     \@begin@alignbox\bgroup\box@dir\adjustbaseline
745       \let\par\@empty
746       \let\@sharp####\let\protect\relax
747       \let\\\@arraycr\let\tabularnewline\\\let\par\@empty
748      \lineskip\z@skip\baselineskip\z@skip\@preamble}
749   \def\endarray{\crcr\egroup\egroup\@end@alignbox\@arrayright}
750 }
751 \@ifpackageloaded{array}{%
752   \let\tabular=\ltj@lltjext@orig@tabular
753   \let\array=\ltj@lltjext@orig@array
754   \ltj@lltjext@patch@array
755 }{%
756   \let\ltj@lltjext@orig@tabular\relax
757   \let\ltj@lltjext@orig@array\relax
758   \ltj@ExecuteAfterPackage{array}{\ltj@lltjext@patch@array}
759 }
760
761 %%%%%%%%%%%%%%%% LuaTeX-ja original
762
763 %%\define@key[ltj]{japaram}{autouprightnum}{%      %COUNT
764 %%  \ltj@@set@stack{AURN}{0}{10000}\z@#1 }
765
766 \endinput