%
% lltjext.sty: derived from plext.sty in pLaTeX.
%
+
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lltjext}
- [2014/07/26 v1.2-ltj-1 ...]
+ [2014/09/06 v1.2-ltj-3 Macros for vertical writing]
\RequirePackage{luatexja}
-\newif\if@rotsw
+\let\ltj@lltjext@orig@tabular=\tabular
+\let\ltj@lltjext@orig@array=\array
+
%%% array and tabular
\def\array{\let\@acol\@arrayacol \let\@classz\@arrayclassz
\let\@classiv\@arrayclassiv
\@depth\arraystretch\ltjgetdp\@tempcnta \@width\z@}%
\fork@array@option<#1>[#2]%
\@mkpream{#3}\edef\@preamble{\ialign \noexpand\@halignto
- \bgroup \tabskip\z@skip \@arstrut \@preamble \tabskip\z@skip \cr}%
- \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
- \let\tabularnewline\\%
+ \bgroup\@arstrut \@preamble \tabskip\z@skip \cr}%
+ \let\tabularnewline\\%
\@begin@alignbox\bgroup\box@dir\adjustbaseline
\let\par\@empty
\let\@sharp##\let\protect\relax
\lineskip\z@skip\baselineskip\z@skip\@preamble}
\def\endarray{\crcr\egroup\egroup\@end@alignbox}
-\def\endtabular{\crcr\egroup\egroup\@end@alignbox$\egroup}
+\def\endtabular{\endarray$\egroup}
\expandafter \let \csname endtabular*\endcsname = \endtabular
\def\fork@array@option<#1>[#2]{%
\ifnum\ltjgetparameter{direction}=4 % yoko
{\X@picture}{\X@picture<Z>}}
\def\X@picture<#1>(#2,#3){\@ifnextchar(%)
{\@@picture<#1>(#2,#3)}{\@@picture<#1>(#2,#3)(0,0)}}
-\newdimen\save@ybaselineshift
-\newdimen\save@tbaselineshift
\newdimen\@picwd
+\def\ltj@@pic@reset@blshift{%
+ \ltj@yablshift\z@\ltj@ykblshift\z@
+ \ltj@tablshift\z@\ltj@tkblshift\z@
+}%
\def\@@picture<#1>(#2,#3)(#4,#5){%
- \save@ybaselineshift\ybaselineshift
- \save@tbaselineshift\tbaselineshift
- \iftdir
- \if#1y\let\box@dir\yoko
- \@picwd=#3\unitlength \@picht=#2\unitlength
- \@tempdima=#5\unitlength \@tempdimb=#4\unitlength
- \else\let\box@dir\tate
- \@picwd=#2\unitlength \@picht=#3\unitlength
- \@tempdima=#4\unitlength \@tempdimb=#5\unitlength
+ \edef\ltj@@pic@save@blshift{%
+ \noexpand\ltj@yablshift\the\ltj@yablshift\noexpand\relax
+ \noexpand\ltj@ykblshift\the\ltj@ykblshift\noexpand\relax
+ \noexpand\ltj@tablshift\the\ltj@tablshift\noexpand\relax
+ \noexpand\ltj@tkblshift\the\ltj@tkblshift\noexpand\relax
+ }%
+ \bgroup\let\box@dir\relax
+ \if #1z\relax
+ \ifnum\ltjgetparameter{direction}=3 \relax
+ \let\box@dir\utod
\fi
\else
- \if#1t\let\box@dir\tate
- \@picwd=#3\unitlength \@picht=#2\unitlength
- \@tempdima=#5\unitlength \@tempdimb=#4\unitlength
- \else\let\box@dir\yoko
- \@picwd=#2\unitlength \@picht=#3\unitlength
- \@tempdima=#4\unitlength \@tempdimb=#5\unitlength
+ \if #1y\relax \let\box@dir\yoko
+ \else\if #1t\relax\let\box@dir\tate
+ \else\if #1d\relax\let\box@dir\dtou
+ \else\if #1u\relax\let\box@dir\utod
+ \fi\fi\fi\fi
+ \fi
+ \ifx\box@dir\relax
+ \ifcase\ltjgetparameter{direction}
+ \or \let\box@dir\dtou
+ \or\or\let\box@dir\tate
+ \or \let\box@dir\yoko
+ \else \let\box@dir\utod
\fi
\fi
+ \@picwd=#2\unitlength \@picht=#3\unitlength
\setbox\@picbox\hbox to\@picwd\bgroup\box@dir
- \hskip-\@tempdima\lower\@tempdimb\hbox\bgroup
- \ybaselineshift\z@ \tbaselineshift\z@
+ \hskip-#4\unitlength\lower#5\unitlength\hbox\bgroup
+ \ltj@@pic@reset@blshift
\ignorespaces}
\def\endpicture{%
\egroup\hss\egroup
- \ht\@picbox\@picht \wd\@picbox\@picwd \dp\@picbox\z@
+ \setbox0=\hbox{\box@dir%
+ \ltjsetht\@picbox\@picht \ltjsetdp\@picbox\z@
+ }%
+ \@tempswafalse
+ \ifnum\ltjgetparameter{direction}=3 \@tempswatrue\fi
+ \ifnum\ltjgetparameter{direction}=11 \@tempswatrue\fi
+ \if@tempswa
+ \ifx\box@dir\yoko % この場合だけ垂直位置補正が必要
+ \ltjsetht\@picbox\dimexpr\ltjgetht\@picbox+\ltjgetdp\@picbox\relax
+ \ltjsetdp\@picbox\z@
+ \fi
+ \fi
\mbox{\box\@picbox}%
- \ybaselineshift\save@ybaselineshift
- \tbaselineshift\save@tbaselineshift}
+ \egroup\ltj@@pic@save@blshift}
\let\org@put\put
-\def\put{\ybaselineshift\z@\tbaselineshift\z@\org@put}
+\def\put{\ltj@@pic@reset@blshift\org@put}
\let\org@line\line
-\def\line{\ybaselineshift\z@\tbaselineshift\z@\org@line}
+\def\line{\ltj@@pic@reset@blshift\org@line}
\let\org@vector\vector
-\def\vector{\ybaselineshift\z@\tbaselineshift\z@\org@vector}
+\def\vector{\ltj@@pic@reset@blshift\org@vector}
\let\org@dashbox\dashbox
-\def\dashbox{\ybaselineshift\z@\tbaselineshift\z@\org@dashbox}
+\def\dashbox{\ltj@@pic@reset@blshift\org@dashbox}
\let\org@oval\oval
-\def\oval{\ybaselineshift\z@\tbaselineshift\z@\org@oval}
+\def\oval{\ltj@@pic@reset@blshift\org@oval}
\let\org@circle\circle
-\def\circle{\ybaselineshift\z@\tbaselineshift\z@\org@circle}
+\def\circle{\ltj@@pic@reset@blshift\org@circle}
%%% rensuji
\newif\ifnot@advanceline
\hbox{#2}\else
\hskip\rensujiskip
\ifvmode\leavevmode\fi
+ \setbox\tw@\hbox{漢}% 「あ」では仮名書体使用時がまずそう
+ \@tempdimb\ltjgetht\tw@ \advance\@tempdimb\ltjgetdp\tw@
\ifnot@advanceline\not@advancelinefalse\else
\setbox\z@\hbox{\yoko#2}%
\@tempdima\ltjgetht\z@ \advance\@tempdima\ltjgetdp\z@
\ifnum\ltjgetparameter{direction}=1\relax
- \if #1c\relax\vrule \@width \z@ \@height.5\@tempdima \@depth.5\@tempdima
- \else\if #1l\relax\vrule\@width \z@\@height\z@ \@depth\@tempdima
- \else\vrule\@width \z@ \@height\@tempdima \@depth\z@
+ % 周囲が dtou の場合には,高さ \ltjgetht\tw@, 深さ \ltjgetdp\tw@ のボックスを基準としている.
+ \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
+ \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
+ \else\if #1l\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
+ \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
\fi\fi
\else
- \if #1c\relax\vrule \@width \z@ \@height.5\@tempdima \@depth.5\@tempdima
- \else\if #1r\relax\vrule\@width \z@\@height\z@ \@depth\@tempdima
- \else\vrule\@width \z@ \@height\@tempdima \@depth\z@
+ % 周囲が tate, utod の場合も同じ
+ \if #1c\relax\vrule \@width \z@ \@height\dimexpr.5\@tempdima+.5\ltjgetht\tw@-.5\ltjgetdp\tw@
+ \@depth\dimexpr.5\@tempdima-.5\ltjgetht\tw@+.5\ltjgetdp\tw@
+ \else\if #1r\relax\vrule\@width \z@\@height\ltjgetht\tw@ \@depth\dimexpr\@tempdima-\ltjgetht\tw@
+ \else\vrule\@width \z@ \@height\dimexpr\@tempdima-\ltjgetdp\tw@ \@depth\ltjgetdp\tw@
\fi\fi
\fi
\fi
\ifnum\ltjgetparameter{direction}=1\relax
- \if #1c\relax\hbox to\zw{\yoko\hss#2\hss}%
- \else\if #1r\relax\vbox{\hbox to\zw{\yoko\hss#2}\kern\z@}%
- \else\vtop{\kern\z@\hbox to\zw{\yoko#2\hss}}%
+ \if #1c\relax\hbox to\@tempdimb{\yoko\hss#2\hss\kern-\ltjgetdp\tw@}%
+ \else\if #1r\relax\vbox{\hbox to\@tempdimb{\yoko\hss#2\kern-\ltjgetdp\tw@}}%
+ \else\lower\ltjgetdp\tw@\vtop{\hbox to\@tempdimb{\yoko#2\hss}}%
\fi\fi
\else
- \if #1c\relax\hbox to\zw{\yoko\hss#2\hss}%
- \else\if #1r\relax\vtop{\kern\z@\hbox to\zw{\yoko\hss#2}}%
- \else\vbox{\hbox to\zw{\yoko #2\hss}\kern\z@}%
+ \if #1c\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
+ \hbox to\@tempdimb{\yoko \hss#2\hss}%
+ \else\if #1r\relax\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
+ \vbox{\hbox to\@tempdimb{\yoko\hss#2}}%
+ \else\raise\dimexpr.5\@tempdimb-\ltjgetdp\tw@
+ \vtop{\hbox to\@tempdimb{\yoko #2\hss}}%
\fi\fi
\fi
\hskip\rensujiskip
%%% kanji
\def\Kanji#1{\expandafter\@Kanji\csname c@#1\endcsname}
\def\@Kanji#1{\expandafter\kansuji\number #1}
-\def\kanji{\iftdir\expandafter\kansuji\fi}
+\def\kanji{\ifnum\ltjgetparameter{direction}=3 \expandafter\kansuji\fi}
%%% bou
-%%%
-\def\boutenchar{\char\euc"A1A2}
+%%%
+\def\boutenchar{\char\euc"A1A2}%"
\def\bou#1{\ifvmode\leavevmode\fi\@bou#1\end}
\def\@bou#1{%
\ifx#1\end \let\next=\relax
\else (\theequation)\fi}}
\def\@thecounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
\def\@thmcounter#1{\noexpand\rensuji{\noexpand\arabic{#1}}}
+
+%% Compatibility with array package
+
+\def\ltj@lltjext@patch@array{%
+ \def\@startpbox##1{\bgroup
+ \box@dir\adjustbaseline%%% これを追加
+ \hsize=##1\@arrayparboxrestore
+ \everypar{%
+ \vrule \@height \ltjgetht\@arstrutbox \@width \z@
+ \everypar{}}%
+ }
+ \def\@tabarray{\@ifnextchar<\p@tabarray{\p@tabarray<Z>}}
+ \def\p@array<##1>[##2]##3{%
+ \let\box@dir\relax
+ \if ##1z\relax
+ \ifnum\ltjgetparameter{direction}=3\relax
+ \let\box@dir\utod\@tempcnta=\zstrutbox
+ \fi
+ \else
+ \if ##1y\relax
+ \let\box@dir\yoko\@tempcnta=\strutbox
+ \else\if ##1t\relax
+ \let\box@dir\tate\@tempcnta=\tstrutbox
+ \else\if ##1d\relax
+ \let\box@dir\dtou\@tempcnta=\dstrutbox
+ \else\if ##1u\relax
+ \let\box@dir\utod\@tempcnta=\zstrutbox
+ \fi\fi\fi\fi
+ \fi
+ \ifx\box@dir\relax
+ \ifcase\ltjgetparameter{direction}
+ \or \let\box@dir\dtou\@tempcnta=\tabskip \z@\tabskip \z@\dstrutbox% dtou
+ \or\or\let\box@dir\tate\@tempcnta=\tstrutbox% tate
+ \or \let\box@dir\yoko\@tempcnta=\strutbox% yoko
+ \else \let\box@dir\utod\@tempcnta=\zstrutbox% utod
+ \fi
+ \fi
+ \setbox \@arstrutbox \hbox{\box@dir\vrule
+ \@height \arraystretch
+ \dimexpr \ltjgetht\@tempcnta+\extrarowheight\relax
+ \@depth \arraystretch \ltjgetdp \@tempcnta
+ \@width \z@}%
+ \fork@array@option<##1>[##2]%
+ \begingroup
+ \@mkpream{##3}%
+ \xdef\@preamble{\ialign \noexpand \@halignto
+ \bgroup \tabskip \z@skip \@arstrut \@preamble
+ \tabskip \z@ \cr}%
+ \endgroup
+ \@arrayleft
+ \@begin@alignbox\bgroup\box@dir\adjustbaseline
+ \let\par\@empty
+ \let\@sharp####\let\protect\relax
+ \let\\\@arraycr\let\tabularnewline\\\let\par\@empty
+ \lineskip\z@skip\baselineskip\z@skip\@preamble}
+ \def\endarray{\crcr\egroup\egroup\@end@alignbox}
+}
+
+\@ifpackageloaded{array}{%
+ \let\tabular=\ltj@lltjext@orig@tabular
+ \let\array=\ltj@lltjext@orig@array
+ \ltj@lltjext@patch@array
+}{%
+ \let\ltj@lltjext@orig@tabular\relax
+ \let\ltj@lltjext@orig@array\relax
+ \RequirePackage{filehook}
+ \AtEndOfPackageFile{array}{\ltj@lltjext@patch@array}
+}
+
+
\endinput
\ No newline at end of file