OSDN Git Service

more fix
[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/26 v1.2g-ltj-7 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\lltjext@getjablshift{%
393   \ifnum\ltj@ext@dir=3 \ltjgetparameter{tjabaselineshift}\else
394   \ltjgetparameter{yjabaselineshift}\fi}
395 \def\fork@parbox@option@@B#1{%
396   \if #1t\relax
397     \def\@begin@parbox{\raise\dimexpr\cht-\lltjext@getjablshift\vtop\bgroup\kern\z@\vbox}%
398     \let\@end@parbox\egroup
399   \else\if #1b\relax
400     \def\@begin@parbox{\lower\dimexpr\cdp+\lltjext@getjablshift\vbox\bgroup\vbox}%
401     \def\@end@parbox{\kern\z@\egroup}%
402   \else
403     \ifmmode
404       \let\@begin@parbox\vcenter\let\@end@parbox\relax
405     \else
406       \def\@begin@parbox{\null$\vcenter}%
407       \def\@end@parbox{\m@th$\null}%
408     \fi
409   \fi\fi}
410 \let\fork@parbox@option@@C=\fork@parbox@option@@B
411 \def\fork@parbox@option<#1>[#2]{%
412   \let\box@dir\relax \ltj@ext@dir=\ltjgetparameter{direction}\relax
413   \if #1z\relax
414     \ifnum\ltj@ext@dir=3\relax
415       \let\box@dir\utod
416     \fi
417   \else
418     \if #1y\relax     \let\box@dir\yoko
419     \else\if #1t\relax\let\box@dir\tate
420     \else\if #1d\relax\let\box@dir\dtou
421     \else\if #1u\relax\let\box@dir\utod
422     \fi\fi\fi\fi
423   \fi
424   \ifx\box@dir\relax
425     \ifcase\ltj@ext@dir
426        \or   \let\box@dir\dtou
427        \or\or\let\box@dir\tate
428        \or   \let\box@dir\yoko
429        \else \let\box@dir\utod
430     \fi
431   \fi
432 \ifnum\ltj@ext@dir=4 % yoko
433   \ifx\box@dir\yoko      \fork@parbox@option@@A{#2}%
434   \else                  \fork@parbox@option@@B{#2}%
435   \fi
436 \else\ifnum\ltj@ext@dir=1 % dtou
437   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
438   \else\ifx\box@dir\dtou \fork@parbox@option@@A{#2}%
439   \else                  \fork@parbox@option@@C{#2}%
440   \fi\fi
441 \else\ifnum\ltj@ext@dir=3 % tate
442   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
443   \else\ifx\box@dir\tate \fork@parbox@option@@A{#2}%
444   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
445   \else                  \fork@parbox@option@@B{#2}% D
446   \fi\fi\fi
447 \else % utod
448   \ifx\box@dir\yoko      \fork@parbox@option@@B{#2}%
449   \else\ifx\box@dir\utod \fork@parbox@option@@A{#2}%
450   \else\ifx\box@dir\dtou \fork@parbox@option@@C{#2}%
451   \else                  \fork@parbox@option@@B{#2}% D
452   \fi\fi\fi
453 \fi\fi\fi}
454
455 %%% pbox
456 \DeclareRobustCommand\pbox{\leavevmode\@ifnextchar<{\X@makePbox}{\X@makePbox<Z>}}
457 \def\X@makePbox<#1>{%
458   \@ifnextchar[{\@imakePbox<#1>}{\@imakePbox<#1>[-5\p@]}}
459 \def\@imakePbox<#1>[#2]{\@ifnextchar[%]
460   {\@iimakePbox<#1>{#2}}{\@iimakePbox<#1>{#2}[c]}}
461 \def\@iimakePbox<#1>#2[#3]#4{%
462   \bgroup\let\box@dir\relax
463   \if #1z\relax
464     \ifnum\ltjgetparameter{direction}=3 \relax
465       \let\box@dir\utod
466     \fi
467   \else
468     \if #1y\relax     \let\box@dir\yoko
469     \else\if #1t\relax\let\box@dir\tate
470     \else\if #1d\relax\let\box@dir\dtou
471     \else\if #1u\relax\let\box@dir\utod
472     \fi\fi\fi\fi
473   \fi
474   \ifx\box@dir\relax
475     \ifcase\ltjgetparameter{direction}
476        \or   \let\box@dir\dtou
477        \or\or\let\box@dir\tate
478        \or   \let\box@dir\yoko
479        \else \let\box@dir\utod
480     \fi
481   \fi
482     \setlength{\@tempdima}{#2}%
483     \ifdim\@tempdima<\z@ \hbox{\box@dir#4}\else
484     \hb@xt@\@tempdima{\box@dir
485                \if #3l\relax\else\hss\fi
486                #4\relax
487                \if #3r\relax\else\hss\fi}\fi\egroup}
488
489 %%% picture
490 \def\picture{\@ifnextchar<%>
491    {\X@picture}{\X@picture<Z>}}
492 \def\X@picture<#1>(#2,#3){\@ifnextchar(%)
493    {\@@picture<#1>(#2,#3)}{\@@picture<#1>(#2,#3)(0,0)}}
494 \newdimen\@picwd
495 \def\ltj@@pic@reset@blshift{%
496   \ltj@yablshift\z@\ltj@ykblshift\z@
497   \ltj@tablshift\z@\ltj@tkblshift\z@
498 }%
499 \def\@@picture<#1>(#2,#3)(#4,#5){%
500   \edef\ltj@@pic@save@blshift{%
501     \noexpand\ltj@yablshift\the\ltj@yablshift\noexpand\relax
502     \noexpand\ltj@ykblshift\the\ltj@ykblshift\noexpand\relax
503     \noexpand\ltj@tablshift\the\ltj@tablshift\noexpand\relax
504     \noexpand\ltj@tkblshift\the\ltj@tkblshift\noexpand\relax
505   }%
506   \bgroup\let\box@dir\relax
507   \if #1z\relax
508     \ifnum\ltjgetparameter{direction}=3 \relax
509       \let\box@dir\utod
510     \fi
511   \else
512     \if #1y\relax     \let\box@dir\yoko
513     \else\if #1t\relax\let\box@dir\tate
514     \else\if #1d\relax\let\box@dir\dtou
515     \else\if #1u\relax\let\box@dir\utod
516     \fi\fi\fi\fi
517   \fi
518   \ifx\box@dir\relax
519     \ifcase\ltjgetparameter{direction}
520        \or   \let\box@dir\dtou
521        \or\or\let\box@dir\tate
522        \or   \let\box@dir\yoko
523        \else \let\box@dir\utod
524     \fi
525   \fi
526   \@picwd=#2\unitlength \@picht=#3\unitlength
527   \setbox\@picbox\hbox to\@picwd\bgroup\box@dir
528   \hskip-#4\unitlength\lower#5\unitlength\hbox\bgroup
529   \ltj@@pic@reset@blshift
530   \ignorespaces}
531 \def\endpicture{%
532   \egroup\hss\egroup
533   \setbox0=\hbox{\box@dir%
534     \ltjsetht\@picbox\@picht \ltjsetdp\@picbox\z@
535   }%
536   \@tempswafalse
537   \ifnum\ltjgetparameter{direction}=3  \@tempswatrue\fi
538   \ifnum\ltjgetparameter{direction}=11  \@tempswatrue\fi
539   \if@tempswa
540     \ifx\box@dir\yoko % この場合だけ垂直位置補正が必要
541      \ltjsetht\@picbox\dimexpr\ltjgetht\@picbox+\ltjgetdp\@picbox\relax
542       \ltjsetdp\@picbox\z@
543     \fi
544   \fi
545   \mbox{\box\@picbox}%
546   \egroup\ltj@@pic@save@blshift}
547 \let\org@put\put
548 \def\put{\ltj@@pic@reset@blshift\org@put}
549 \let\org@line\line
550 \def\line{\ltj@@pic@reset@blshift\org@line}
551 \let\org@vector\vector
552 \def\vector{\ltj@@pic@reset@blshift\org@vector}
553 \let\org@dashbox\dashbox
554 \def\dashbox{\ltj@@pic@reset@blshift\org@dashbox}
555 \let\org@oval\oval
556 \def\oval{\ltj@@pic@reset@blshift\org@oval}
557 \let\org@circle\circle
558 \def\circle{\ltj@@pic@reset@blshift\org@circle}
559
560 %%% rensuji
561 \newif\ifnot@advanceline
562 \newskip\rensujiskip
563 \rensujiskip=0.25\chs plus.25\zw minus.25\zw
564 \DeclareRobustCommand\rensuji{%
565   \@ifstar{\not@advancelinetrue\@rensuji}{\@rensuji}}
566 \def\@rensuji{\@ifnextchar[{\@@rensuji}{\@@rensuji[c]}}
567 \def\@@rensuji[#1]#2{%
568   \ifvmode\leavevmode\fi
569   \ifnum\ltjgetparameter{direction}=4\relax\hbox{#2}\else
570   \hskip\rensujiskip
571   \setbox\tw@\hbox{漢}% 「あ」では仮名書体使用時がまずそう
572   \@tempdimb\ltjgetht\tw@ \advance\@tempdimb\ltjgetdp\tw@
573   \ifnot@advanceline\not@advancelinefalse\else
574     \setbox\z@\hbox{\yoko#2}%
575     \@tempdima\ltjgetht\z@ \advance\@tempdima\ltjgetdp\z@
576     \ifnum\ltjgetparameter{direction}=1\relax
577       % 周囲が dtou の場合には,高さ \ltjgetht\tw@, 深さ \ltjgetdp\tw@ のボックスを基準としている.
578       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
579                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
580       \else\if #1l\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
581       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
582       \fi\fi
583     \else
584       % 周囲が tate, utod の場合も同じ
585       \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
586                           \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
587       \else\if #1r\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
588       \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
589       \fi\fi
590     \fi
591   \fi
592   \ifnum\ltjgetparameter{direction}=1\relax
593     \if #1c\relax\hbox to\@tempdimb{\yoko\hss#2\hss\kern-\ltjgetdp\tw@}%
594     \else\if #1r\relax\vbox{\hbox to\@tempdimb{\yoko\hss#2\kern-\ltjgetdp\tw@}}%
595     \else\lower\ltjgetdp\tw@\vtop{\hbox to\@tempdimb{\yoko#2\hss}}%
596     \fi\fi
597   \else
598     \if #1c\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
599         \hbox to\@tempdimb{\yoko \hss#2\hss}%
600     \else\if #1r\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
601         \vbox{\hbox to\@tempdimb{\yoko\hss#2}}%
602     \else\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
603          \vtop{\hbox to\@tempdimb{\yoko #2\hss}}%
604     \fi\fi
605   \fi
606   \hskip\rensujiskip
607 \fi}
608 \let\Rensuji\rensuji
609 \let\prensuji\rensuji
610
611 %%% kanji
612 \def\Kanji#1{\expandafter\@Kanji\csname c@#1\endcsname}
613 \def\@Kanji#1{\kansuji #1}
614 \def\kanji{\ifnum\ltjgetparameter{direction}=3 \expandafter\kansuji\fi}
615
616 %%% bou
617 %%%
618 \def\boutenchar{\char\euc"A1A2}%"
619 \def\bou#1{\ifvmode\leavevmode\fi\@bou#1\end}
620 \def\@bou#1{%
621   \ifx#1\end \let\next=\relax
622   \else
623     \ifnum\ltjgetparameter{direction}=3\relax
624       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
625         \vss\moveleft0.2\zw\hbox{\yoko\boutenchar}\nointerlineskip
626         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
627     \else
628       \hbox to\z@{\vbox to\z@{\boxmaxdepth\maxdimen
629         \vss\moveleft-0.2\zw\hbox{\boutenchar}\nointerlineskip
630         \hbox{\char\euc"A1A1}}\hss}\nobreak#1\relax
631     \fi
632     \let\next=\@bou
633   \fi\next}
634
635 %%% kasen
636 \def\kasen#1{%
637   \ifnum\ltjgetparameter{direction}=3\relax
638     \setbox\z@\hbox{#1}\leavevmode\raise.7\zw
639     \hbox to\z@{\vrule\@width\wd\z@ \@depth\z@ \@height.4\p@\hss}%
640     \box\z@
641   \else\underline{#1}\fi}
642
643 %%% references
644 \def\@eqnnum{{\reset@font\rmfamily \normalcolor
645   \ifnum\ltjgetparameter{direction}=11\raise.25\zh\hbox{\yoko(\theequation)}%
646   \else (\theequation)\fi}}
647 \def\@thecounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
648 \def\@thmcounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
649
650 %% Compatibility with array package
651
652 \def\ltj@lltjext@patch@array{%
653   \patchcmd{\@tabular}{\hbox\bgroup}{%
654         \hbox\bgroup\ltj@ext@dir=\ltjgetparameter{direction}}{}{}
655   \pretocmd{\array}%
656         {\ltj@ext@dir=\ltjgetparameter{direction}\relax}{}{}
657   \def\@startpbox##1{\bgroup
658    \box@dir\adjustbaseline%%% これを追加
659    \setlength\hsize{##1}\@arrayparboxrestore
660      \everypar{%
661         \vrule \@height \ltjgetht\@arstrutbox \@width \z@
662         \everypar{}}%
663      }
664   \def\@tabarray{\@ifnextchar<\p@tabarray{\p@tabarray<z>}}
665   \def\p@array<##1>[##2]##3{%
666     \let\box@dir\relax
667     \if ##1z\relax
668       \ifnum\ltj@ext@dir=3\relax
669         \let\box@dir\utod\@tempcnta=\zstrutbox
670       \fi
671     \else
672       \if ##1y\relax
673         \let\box@dir\yoko\@tempcnta=\ystrutbox
674       \else\if ##1t\relax
675         \let\box@dir\tate\@tempcnta=\tstrutbox
676       \else\if ##1d\relax
677          \let\box@dir\dtou\@tempcnta=\dstrutbox
678       \else\if ##1u\relax
679          \let\box@dir\utod\@tempcnta=\zstrutbox
680       \fi\fi\fi\fi
681     \fi
682     \ifx\box@dir\relax
683       \ifcase\ltj@ext@dir
684          \or   \let\box@dir\dtou\@tempcnta=\dstrutbox% dtou
685          \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
686          \or   \let\box@dir\yoko\@tempcnta=\ystrutbox% yoko
687          \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
688       \fi
689     \fi
690     \setbox \@arstrutbox \hbox{\box@dir\vrule
691                \@height \arraystretch
692                  \dimexpr \ltjgetht\@tempcnta+\extrarowheight\relax
693                \@depth \arraystretch \ltjgetdp \@tempcnta
694                \@width \z@}%
695     \fork@array@option<##1>[##2]%
696     \begingroup
697     \@mkpream{##3}%
698     \xdef\@preamble{\ialign \noexpand \@halignto
699                     \bgroup \tabskip \z@skip \@arstrut \@preamble
700                             \tabskip \z@ \cr}%
701     \endgroup
702     \@arrayleft
703     \@begin@alignbox\bgroup\box@dir\adjustbaseline
704       \let\par\@empty
705       \let\@sharp####\let\protect\relax
706       \let\\\@arraycr\let\tabularnewline\\\let\par\@empty
707      \lineskip\z@skip\baselineskip\z@skip\@preamble}
708   \def\endarray{\crcr\egroup\egroup\@end@alignbox\@arrayright}
709 }
710
711 \@ifpackageloaded{array}{%
712   \expandafter\let\csname tabular*\endcsname=\ltj@lltjext@orig@tabularS
713   \let\tabular=\ltj@lltjext@orig@tabular
714   \let\array=\ltj@lltjext@orig@array
715   \ltj@lltjext@patch@array
716 }{%
717   \let\ltj@lltjext@orig@tabularS\relax
718   \let\ltj@lltjext@orig@tabular\relax
719   \let\ltj@lltjext@orig@array\relax
720   \RequirePackage{filehook,etoolbox}
721   \AtEndOfPackageFile{array}{\ltj@lltjext@patch@array}
722 }
723
724 %%%%%%%%%%%%%%%% LuaTeX-ja original
725
726 %%\define@key[ltj]{japaram}{autouprightnum}{%      %COUNT
727 %%  \ltj@@set@stack{AURN}{0}{10000}\z@#1 }
728
729 \endinput