OSDN Git Service

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