OSDN Git Service

patch lltjext.sty (thanks aminophen)
[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/22 v1.2j-ltj-9 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}
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   \let\box@dir\relax
40   \if #1z\relax
41     \ifnum\ltj@ext@dir=3\relax
42       \let\box@dir\utod\@tempcnta=\zstrutbox
43     \fi
44   \else
45     \if #1y\relax
46        \let\box@dir\yoko\@tempcnta=\ystrutbox
47     \else\if #1t\relax
48        \let\box@dir\tate\@tempcnta=\tstrutbox
49     \else\if #1d\relax
50        \let\box@dir\dtou\@tempcnta=\dstrutbox
51     \else\if #1u\relax
52        \let\box@dir\utod\@tempcnta=\zstrutbox
53     \fi\fi\fi\fi
54   \fi
55   \ifx\box@dir\relax
56     \ifcase\ltj@ext@dir
57        \or   \let\box@dir\dtou\@tempcnta=\dstrutbox% dtou
58        \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
59        \or   \let\box@dir\yoko\@tempcnta=\ystrutbox% yoko
60        \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
61     \fi
62   \fi
63   \fork@array@option<#1>[#2]\@begin@alignbox
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@layoutc@ption\endcsname\relax \else
200     \@latex@info{Redeclaring capiton layout setting of '#1'}%
201   \fi
202   \expandafter
203   \gdef\csname #1@layoutc@ption\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\@pboxswtrue $\vcenter \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@pboxsw \m@th$\fi
250     \if r\caption@posb\kern\captionfloatsep\box\@captionbox\fi
251     \if r\float@pos\else\hss\fi}}%
252   \par\vskip.25\baselineskip
253   \box\@tempboxa}
254 \def\make@pcaptionbox#1{%
255   \expandafter
256   \ifx\csname\@captype @layoutc@ption\endcsname\relax
257      \@latex@warning{Default caption layout of `\@captype' unknown.}%
258        \def\caption@dir{Z}\captionwidth\z@
259        \def\caption@posa{Z}\def\caption@posb{Z}%
260   \else
261      \csname \@captype @layoutc@ption\endcsname
262   \fi
263   \@tempswafalse
264   % \@tempswa: 基本組の組方向とキャプションの組方向が直交するか?
265   \if y\caption@dir \let\captiondir\yoko
266     \ifodd\ltjgetparameter{direction}\relax\@tempswatrue\fi
267   \else\if z\caption@dir \let\captiondir\relax
268     \ifnum\ltjgetparameter{direction}=3\relax\let\captiondir\utod\fi
269   \else\if d\caption@dir \let\captiondir\dtou
270     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
271   \else\if u\caption@dir \let\captiondir\utod
272     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
273   \else\if t\caption@dir \let\captiondir\tate
274     \ifodd\ltjgetparameter{direction}\else\@tempswatrue\fi
275   \fi\fi\fi\fi\fi
276   \setbox0\hbox{\hbox{\captiondir
277      \captionfontsetup\parindent\z@\inhibitglue
278      \csname fnum@\@captype\endcsname  #1}}%"
279   \if@tempswa\@tempdima\ltjgetht0\relax\else\@tempdima\ltjgetwd0\relax\fi
280   \ifdim\@tempdima>\captionwidth \@tempdima\captionwidth \fi
281   \@pboxswfalse
282   \setbox0\hbox{%
283     \if u\caption@posb\vbox
284     \else\if d\caption@posb\vbox
285     \else\if t\caption@posa\vtop
286     \else\if b\caption@posa\vbox
287     \else\ifmmode\vcenter\else\@pboxswtrue $\vcenter\fi
288     \fi\fi\fi\fi
289     {\hsize\@tempdima\kern\z@
290     \vbox{\captiondir\hsize\@tempdima
291       \captionfontsetup\parindent\z@\inhibitglue
292       \csname fnum@\@captype\endcsname  #1}\kern\z@
293     }\if@pboxsw \m@th$\fi}%
294   \let\to@captionboxwidth\relax
295   \if l\caption@posb \else\if r\caption@posb\else
296   \def\to@captionboxwidth{to\floatwidth}\fi\fi
297   \setbox\@captionbox\hbox\to@captionboxwidth{%
298      \if t\caption@posa\else\hss\fi
299      \unhbox0\relax
300      \if b\caption@posa\else\hss\fi}}
301
302 %%% minipage and parbox
303 \def\minipage{\@ifnextchar<%>
304    {\X@minipage}{\X@minipage<Z>}}
305 \def\X@minipage<#1>{\@ifnextchar[%]
306    {\@iminipage<#1>}{\@iiiminipage<#1>{c}\relax[s]}}
307 \def\@iminipage<#1>[#2]{\@ifnextchar[%]
308    {\@iiminipage<#1>{#2}}{\@iiiminipage<#1>{#2}\relax[s]}}
309 \def\@iiminipage<#1>#2[#3]{\@ifnextchar[%]
310    {\@iiiminipage<#1>{#2}{#3}}{\@iiiminipage<#1>{#2}{#3}[#2]}}
311 \def\@iiiminipage<#1>#2#3[#4]#5{%
312   \leavevmode\bgroup
313   \setlength\@tempdima{#5}%
314   \def\@mpargs{<#1>{#2}{#3}[#4]{#5}}%
315   \let\box@dir\relax
316   \if #1z\relax
317     \ifnum\ltjgetparameter{direction}=3\relax
318       \let\box@dir\utod
319     \fi
320   \else
321     \if #1y\relax     \let\box@dir\yoko
322     \else\if #1t\relax\let\box@dir\tate
323     \else\if #1d\relax\let\box@dir\dtou
324     \else\if #1u\relax\let\box@dir\utod
325     \fi\fi\fi\fi
326   \fi
327   \ifx\box@dir\relax
328     \ifcase\ltjgetparameter{direction}\relax
329        \or   \let\box@dir\dtou
330        \or\or\let\box@dir\tate
331        \or   \let\box@dir\yoko
332        \else \let\box@dir\utod
333     \fi
334   \fi
335   \setbox\@tempboxa\vbox\bgroup\box@dir
336     \adjustbaseline
337     \color@begingroup
338       \hsize\@tempdima
339       \textwidth\hsize \columnwidth\hsize
340       \@parboxrestore
341       \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}%
342       \c@mpfootnote\z@
343       \let\@footnotetext\@mpfootnotetext
344       \let\@listdepth\@mplistdepth \@mplistdepth\z@
345       \@minipagerestore
346       \@setminipage}
347 \def\endminipage{%
348     \par
349     \unskip
350     \ifvoid\@mpfootins\else
351       \vskip\skip\@mpfootins
352       \normalcolor
353       \footnoterule
354       \unvbox\@mpfootins
355     \fi
356     \@minipagefalse   %% added 24 May 89
357   \color@endgroup
358   \egroup
359   \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}\egroup}
360 \DeclareRobustCommand\parbox{\@ifnextchar<%>
361    {\X@parbox}{\X@parbox<Z>}}
362 \def\X@parbox<#1>{\@ifnextchar[%]
363    {\@iparbox<#1>}{\@iiiparbox<#1>{c}\relax[s]}}
364 \def\@iparbox<#1>[#2]{\@ifnextchar[%]
365    {\@iiparbox<#1>{#2}}{\@iiiparbox<#1>{#2}\relax[s]}}
366 \def\@iiparbox<#1>#2[#3]{\@ifnextchar[%]%
367    {\@iiiparbox<#1>{#2}{#3}}{\@iiiparbox<#1>{#2}{#3}[#2]}}
368 \long\def\@iiiparbox<#1>#2#3[#4]#5#6{%
369   \leavevmode
370   \setlength\@tempdima{#5}%
371   \fork@parbox@option<#1>[#2]%
372   \@begin@tempboxa\vbox{\box@dir
373     \hsize\@tempdima\@parboxrestore\adjustbaseline#6\@@par}%
374     \ifx\relax#3\else
375       \setlength\@tempdimb{#3}%
376       \edef\@parboxto{to\the\@tempdimb}%
377     \fi
378     \@begin@parbox\@parboxto{\box@dir\adjustbaseline
379        \let\hss\vss\let\unhbox\unvbox
380        \csname bm@#4\endcsname}\@end@parbox
381   \@end@tempboxa}
382
383
384 % ↓中身\周囲→ yoko  tate  utod  dtou
385 % yoko          A*    B*    B     B
386 % tate          B*    A*    D     C
387 % utod          B     D*    A     C
388 % dtou          B     C     C     A
389 % A: 周囲と中身の組方向が一致.そのまま \vtop/\vcenter/\vbox
390 % B: 周囲と中身が90度ずれ.上端が和文の高さ or 下端が和文の深さに揃うように
391 % C: 周囲と中身が180度ずれ.(コードは B のものを流用)
392 % D: 上端が和文の高さ or 下端が和文の深さに揃うように(コードは B のものを流用)
393
394 \def\fork@parbox@option@@A#1{%
395   \let\@end@parbox\relax
396   \if #1t\relax     \let\@begin@parbox\vtop
397   \else\if #1b\relax\let\@begin@parbox\vbox
398   \else
399     \ifmmode
400       \let\@begin@parbox\vcenter\let\@end@parbox\relax
401     \else
402       \def\@begin@parbox{\null$\vcenter}%
403       \def\@end@parbox{\m@th$\null}%
404     \fi
405   \fi\fi}
406 \def\lltjext@getjablshift{%
407   \ifnum\ltj@ext@dir=3 \ltjgetparameter{tjabaselineshift}\else
408   \ltjgetparameter{yjabaselineshift}\fi}
409 \def\fork@parbox@option@@B#1{%
410   \if #1t\relax
411     \def\@begin@parbox{\raise\dimexpr\cht-\lltjext@getjablshift\vtop\bgroup\kern\z@\vbox}%
412     \let\@end@parbox\egroup
413   \else\if #1b\relax
414     \def\@begin@parbox{\lower\dimexpr\cdp+\lltjext@getjablshift\vbox\bgroup\vbox}%
415     \def\@end@parbox{\kern\z@\egroup}%
416   \else
417     \ifmmode
418       \let\@begin@parbox\vcenter\let\@end@parbox\relax
419     \else
420       \def\@begin@parbox{\null$\vcenter}%
421       \def\@end@parbox{\m@th$\null}%
422     \fi
423   \fi\fi}
424 \let\fork@parbox@option@@C=\fork@parbox@option@@B
425 \def\fork@parbox@option<#1>[#2]{%
426   \let\box@dir\relax \ltj@ext@dir=\ltjgetparameter{direction}\relax
427   \if #1z\relax
428     \ifnum\ltj@ext@dir=3\relax
429       \let\box@dir\utod
430     \fi
431   \else
432     \if #1y\relax     \let\box@dir\yoko
433     \else\if #1t\relax\let\box@dir\tate
434     \else\if #1d\relax\let\box@dir\dtou
435     \else\if #1u\relax\let\box@dir\utod
436     \fi\fi\fi\fi
437   \fi
438   \ifx\box@dir\relax
439     \ifcase\ltj@ext@dir
440        \or   \let\box@dir\dtou
441        \or\or\let\box@dir\tate
442        \or   \let\box@dir\yoko
443        \else \let\box@dir\utod
444     \fi
445   \fi
446 \ifnum\ltj@ext@dir=4 % yoko
447   \ifx\box@dir\yoko      \fork@parbox@option@@A{#2}%
448   \else                  \fork@parbox@option@@B{#2}%
449   \fi
450 \else\ifnum\ltj@ext@dir=1 % dtou
451   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
452   \else\ifx\box@dir\dtou \fork@parbox@option@@A{#2}%
453   \else                  \fork@parbox@option@@C{#2}%
454   \fi\fi
455 \else\ifnum\ltj@ext@dir=3 % tate
456   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
457   \else\ifx\box@dir\tate \fork@parbox@option@@A{#2}%
458   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
459   \else                  \fork@parbox@option@@B{#2}% D
460   \fi\fi\fi
461 \else % utod
462   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
463   \else\ifx\box@dir\utod \fork@parbox@option@@A{#2}%
464   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
465   \else                  \fork@parbox@option@@B{#2}% D
466   \fi\fi\fi
467 \fi\fi\fi}
468
469 %%% pbox
470 \DeclareRobustCommand\pbox{\leavevmode\@ifnextchar<{\X@makePbox}{\X@makePbox<Z>}}
471 \def\X@makePbox<#1>{%
472   \@ifnextchar[{\@imakePbox<#1>}{\@imakePbox<#1>[-5\p@]}}
473 \def\@imakePbox<#1>[#2]{\@ifnextchar[%]
474   {\@iimakePbox<#1>{#2}}{\@iimakePbox<#1>{#2}[c]}}
475 \def\@iimakePbox<#1>#2[#3]#4{%
476   \bgroup\let\box@dir\relax
477   \if #1z\relax
478     \ifnum\ltjgetparameter{direction}=3 \relax
479       \let\box@dir\utod
480     \fi
481   \else
482     \if #1y\relax     \let\box@dir\yoko
483     \else\if #1t\relax\let\box@dir\tate
484     \else\if #1d\relax\let\box@dir\dtou
485     \else\if #1u\relax\let\box@dir\utod
486     \fi\fi\fi\fi
487   \fi
488   \ifx\box@dir\relax
489     \ifcase\ltjgetparameter{direction}
490        \or   \let\box@dir\dtou
491        \or\or\let\box@dir\tate
492        \or   \let\box@dir\yoko
493        \else \let\box@dir\utod
494     \fi
495   \fi
496     \setlength{\@tempdima}{#2}%
497     \ifdim\@tempdima<\z@ \hbox{\box@dir#4}\else
498     \hb@xt@\@tempdima{\box@dir
499                \if #3l\relax\else\hss\fi
500                #4\relax
501                \if #3r\relax\else\hss\fi}\fi\egroup}
502
503 %%% picture
504 \def\picture{\@ifnextchar<%>
505    {\X@picture}{\X@picture<Z>}}
506 \def\X@picture<#1>(#2,#3){\@ifnextchar(%)
507    {\@@picture<#1>(#2,#3)}{\@@picture<#1>(#2,#3)(0,0)}}
508 \newdimen\@picwd
509 \def\ltj@@pic@reset@blshift{%
510   \ltj@yablshift\z@\ltj@ykblshift\z@
511   \ltj@tablshift\z@\ltj@tkblshift\z@
512 }%
513 \def\@@picture<#1>(#2,#3)(#4,#5){%
514   \edef\ltj@@pic@save@blshift{%
515     \noexpand\ltj@yablshift\the\ltj@yablshift\noexpand\relax
516     \noexpand\ltj@ykblshift\the\ltj@ykblshift\noexpand\relax
517     \noexpand\ltj@tablshift\the\ltj@tablshift\noexpand\relax
518     \noexpand\ltj@tkblshift\the\ltj@tkblshift\noexpand\relax
519   }%
520   \bgroup\let\box@dir\relax
521   \if #1z\relax
522     \ifnum\ltjgetparameter{direction}=3 \relax
523       \let\box@dir\utod
524     \fi
525   \else
526     \if #1y\relax     \let\box@dir\yoko
527     \else\if #1t\relax\let\box@dir\tate
528     \else\if #1d\relax\let\box@dir\dtou
529     \else\if #1u\relax\let\box@dir\utod
530     \fi\fi\fi\fi
531   \fi
532   \ifx\box@dir\relax
533     \ifcase\ltjgetparameter{direction}
534        \or   \let\box@dir\dtou
535        \or\or\let\box@dir\tate
536        \or   \let\box@dir\yoko
537        \else \let\box@dir\utod
538     \fi
539   \fi
540   \@picwd=#2\unitlength \@picht=#3\unitlength
541   \setbox\@picbox\hbox to\@picwd\bgroup\box@dir
542   \hskip-#4\unitlength\lower#5\unitlength\hbox\bgroup
543   \ltj@@pic@reset@blshift
544   \ignorespaces}
545 \def\endpicture{%
546   \egroup\hss\egroup
547   \setbox0=\hbox{\box@dir%
548     \ltjsetht\@picbox\@picht \ltjsetdp\@picbox\z@
549   }%
550   \@tempswafalse
551   \ifnum\ltjgetparameter{direction}=3  \@tempswatrue\fi
552   \ifnum\ltjgetparameter{direction}=11  \@tempswatrue\fi
553   \if@tempswa
554     \ifx\box@dir\yoko % この場合だけ垂直位置補正が必要
555      \ltjsetht\@picbox\dimexpr\ltjgetht\@picbox+\ltjgetdp\@picbox\relax
556       \ltjsetdp\@picbox\z@
557     \fi
558   \fi
559   \mbox{\box\@picbox}%
560   \egroup\ltj@@pic@save@blshift}
561 \let\org@put\put
562 \def\put{\ltj@@pic@reset@blshift\org@put}
563 \let\org@line\line
564 \def\line{\ltj@@pic@reset@blshift\org@line}
565 \let\org@vector\vector
566 \def\vector{\ltj@@pic@reset@blshift\org@vector}
567 \let\org@dashbox\dashbox
568 \def\dashbox{\ltj@@pic@reset@blshift\org@dashbox}
569 \let\org@oval\oval
570 \def\oval{\ltj@@pic@reset@blshift\org@oval}
571 \let\org@circle\circle
572 \def\circle{\ltj@@pic@reset@blshift\org@circle}
573
574 %%% rensuji
575 \newif\ifnot@advanceline
576 \newskip\rensujiskip
577 \rensujiskip=0.25\chs plus.25\zw minus.25\zw
578 \DeclareRobustCommand\rensuji{%
579   \@ifstar{\not@advancelinetrue\@rensuji}{\@rensuji}}
580 \def\@rensuji{\@ifnextchar[{\@@rensuji}{\@@rensuji[c]}}
581 \def\@@rensuji[#1]#2{%
582   \ifvmode\leavevmode\fi
583   \ifnum\ltjgetparameter{direction}=4\relax\hbox{#2}\else
584   \hskip\rensujiskip
585   \setbox\tw@\hbox{漢}% 「あ」では仮名書体使用時がまずそう
586   \@tempdimb\ltjgetht\tw@ \advance\@tempdimb\ltjgetdp\tw@
587   \ifnot@advanceline\not@advancelinefalse\else
588     \setbox\z@\hbox{\yoko#2}%
589     \@tempdima\ltjgetht\z@ \advance\@tempdima\ltjgetdp\z@
590     \ifnum\ltjgetparameter{direction}=1\relax
591       % 周囲が dtou の場合には,高さ \ltjgetht\tw@, 深さ \ltjgetdp\tw@ のボックスを基準としている.
592       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
593                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
594       \else\if #1l\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
595       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
596       \fi\fi
597     \else
598       % 周囲が tate, utod の場合も同じ
599       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
600                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
601       \else\if #1r\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
602       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
603       \fi\fi
604     \fi
605   \fi
606   \ifnum\ltjgetparameter{direction}=1\relax
607     \if #1c\relax\hbox to\@tempdimb{\yoko\hss#2\hss\kern-\ltjgetdp\tw@}%
608     \else\if #1r\relax\vbox{\hbox to\@tempdimb{\yoko\hss#2\kern-\ltjgetdp\tw@}}%
609     \else\lower\ltjgetdp\tw@\vtop{\hbox to\@tempdimb{\yoko#2\hss}}%
610     \fi\fi
611   \else
612     \if #1c\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
613         \hbox to\@tempdimb{\yoko \hss#2\hss}%
614     \else\if #1r\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
615         \vbox{\hbox to\@tempdimb{\yoko\hss#2}}%
616     \else\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
617          \vtop{\hbox to\@tempdimb{\yoko #2\hss}}%
618     \fi\fi
619   \fi
620   \hskip\rensujiskip
621 \fi}
622 \let\Rensuji\rensuji
623 \let\prensuji\rensuji
624
625 %%% kanji
626 \def\Kanji#1{\expandafter\@Kanji\csname c@#1\endcsname}
627 \def\@Kanji#1{\kansuji #1}
628 \def\kanji{\ifnum\ltjgetparameter{direction}=3 \expandafter\kansuji\fi}
629
630 %%% bou
631 %%%
632 \def\boutenchar{\char\euc"A1A2}%"
633 \def\bou#1{\ifvmode\leavevmode\fi\@bou#1\end}
634 \def\@bou#1{%
635   \ifx#1\end \let\ltj@@next=\relax
636   \else
637     \ifnum\ltjgetparameter{direction}=3\relax
638       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
639         \vss\moveleft0.2\zw\hbox{\yoko\boutenchar}\nointerlineskip
640         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
641     \else
642       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
643         \vss\moveleft-0.2\zw\hbox{\boutenchar}\nointerlineskip
644         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
645     \fi
646     \let\ltj@@next=\@bou
647   \fi\ltj@@next}
648
649 %%% kasen
650 \def\kasen#1{%
651   \ifnum\ltjgetparameter{direction}=3\relax
652     \setbox\z@\hbox{#1}\leavevmode\raise.7\zw
653     \hbox to\z@{\vrule\@width\wd\z@ \@depth\z@ \@height.4\p@\hss}%
654     \box\z@
655   \else\underline{#1}\fi}
656
657 %%% references
658 \def\@eqnnum{{\reset@font\rmfamily \normalcolor
659   \ifnum\ltjgetparameter{direction}=11\raise.25\zh\hbox{\yoko(\theequation)}%
660   \else (\theequation)\fi}}
661 \def\@thecounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
662 \def\@thmcounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
663
664 %% Compatibility with array package
665
666 \def\ltj@lltjext@patch@array{%
667   \patchcmd{\@tabular}{\hbox\bgroup}{%
668         \hbox\bgroup\ltj@ext@dir=\ltjgetparameter{direction}}{}{}
669   \pretocmd{\array}%
670         {\ltj@ext@dir=\ltjgetparameter{direction}\relax}{}{}
671   \expandafter\let\csname tabular*\endcsname=\ltj@lltjext@orig@tabularS
672   \patchcmd{\p@stabular}{\p@tabular}{\@tabular}{}{}
673   \def\@startpbox##1{\bgroup
674    \box@dir\adjustbaseline%%% これを追加
675    \setlength\hsize{##1}\@arrayparboxrestore
676      \everypar{%
677         \vrule \@height \ltjgetht\@arstrutbox \@width \z@
678         \everypar{}}%
679      }
680   \def\@tabarray{\@ifnextchar<\p@tabarray{\p@tabarray<z>}}
681   \def\p@array<##1>[##2]##3{%
682     \let\box@dir\relax
683     \if ##1z\relax
684       \ifnum\ltj@ext@dir=3\relax
685         \let\box@dir\utod\@tempcnta=\zstrutbox
686       \fi
687     \else
688       \if ##1y\relax
689         \let\box@dir\yoko\@tempcnta=\ystrutbox
690       \else\if ##1t\relax
691         \let\box@dir\tate\@tempcnta=\tstrutbox
692       \else\if ##1d\relax
693          \let\box@dir\dtou\@tempcnta=\dstrutbox
694       \else\if ##1u\relax
695          \let\box@dir\utod\@tempcnta=\zstrutbox
696       \fi\fi\fi\fi
697     \fi
698     \ifx\box@dir\relax
699       \ifcase\ltj@ext@dir
700          \or   \let\box@dir\dtou\@tempcnta=\dstrutbox% dtou
701          \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
702          \or   \let\box@dir\yoko\@tempcnta=\ystrutbox% yoko
703          \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
704       \fi
705     \fi
706     \setbox \@arstrutbox \hbox{\box@dir\vrule
707                \@height \arraystretch
708                  \dimexpr \ltjgetht\@tempcnta+\extrarowheight\relax
709                \@depth \arraystretch \ltjgetdp \@tempcnta
710                \@width \z@}%
711     \fork@array@option<##1>[##2]%
712     \begingroup
713     \@mkpream{##3}%
714     \xdef\@preamble{\ialign \noexpand \@halignto
715                     \bgroup \tabskip \z@skip \@arstrut \@preamble
716                             \tabskip \z@ \cr}%
717     \endgroup
718     \@arrayleft
719     \@begin@alignbox\bgroup\box@dir\adjustbaseline
720       \let\par\@empty
721       \let\@sharp####\let\protect\relax
722       \let\\\@arraycr\let\tabularnewline\\\let\par\@empty
723      \lineskip\z@skip\baselineskip\z@skip\@preamble}
724   \def\endarray{\crcr\egroup\egroup\@end@alignbox\@arrayright}
725 }
726
727 \@ifpackageloaded{array}{%
728   \let\tabular=\ltj@lltjext@orig@tabular
729   \let\array=\ltj@lltjext@orig@array
730   \ltj@lltjext@patch@array
731 }{%
732   \let\ltj@lltjext@orig@tabular\relax
733   \let\ltj@lltjext@orig@array\relax
734   \RequirePackage{filehook,etoolbox}
735   \AtEndOfPackageFile{array}{\ltj@lltjext@patch@array}
736 }
737
738 %%%%%%%%%%%%%%%% LuaTeX-ja original
739
740 %%\define@key[ltj]{japaram}{autouprightnum}{%      %COUNT
741 %%  \ltj@@set@stack{AURN}{0}{10000}\z@#1 }
742
743 \endinput