OSDN Git Service

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