OSDN Git Service

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