OSDN Git Service

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