summaryrefslogtreecommitdiff
path: root/language/japanese/platex-tools/plextarray.sty
blob: 24c8d2ca9977912a96128d05bc5fc94ab2a2644c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%
% plextarray.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the platex-tools bundle.
% https://github.com/aminophen/platex-tools
%
% This package is expected to be compatible with
%   * array.sty in latex-tools
%     (2016/10/06 v2.4d -- 2020/10/01 v2.5c)
%   * plext.sty in platex
%     (2001/09/26 v1.2  -- 2020/10/07 v1.2m)
% Largely based on lltjext.sty from LuaTeX-ja project.
%

\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{plextarray}
  [2018/10/27 v1.1d Tabular extension package for plext and array]
\RequirePackage{plext}
\RequirePackage{plarray}

%% save definitions from array.sty
%  the <dir> option will be handled later in \@tabarray
\def\array{\col@sep\arraycolsep
  \def\d@llarbegin{$}\let\d@llarend\d@llarbegin\def\@halignto{}%
  \@tabarray}
\def\tabular{\def\@halignto{}\@tabular}
%% merged definitions from array.sty and plext.sty
%  take <dir> option first as in plext.sty,
%  which will be passed to \@tabarray
\@namedef{tabular*}{\@ifnextchar<%>
   {\p@stabular}{\p@stabular<Z>}}
\def\p@stabular<#1>#2{%
   \setlength\dimen@{#2}%
   \edef\@halignto{to\the\dimen@}\@tabular<#1>}

%% patching internal code for array.sty and plext.sty
%
\@ifpackagelater{array}{2018/09/13}{\@firstoftwo}{\@secondoftwo}
{% = for 2018/09/13 v2.4i or newer
\def\@startpbox#1{\bgroup
  \color@begingroup
  \box@dir\adjustbaseline %% added
  \setlength\hsize{#1}\@arrayparboxrestore
   \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
   }%
}% =
{% = for 2018/04/30 v2.4h or older
\def\@startpbox#1{\bgroup
  \box@dir\adjustbaseline %% added
  \setlength\hsize{#1}\@arrayparboxrestore
   \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
   }%
}% =
%
\def\@tabarray{\@ifnextchar<\p@tabarray{\p@tabarray<Z>}}
%
%% merged \@array (from array.sty) and \p@array (from plext.sty)
\def\p@array<#1>[#2]#3{%
  %%%%% new code for box direction
  \let\box@dir\relax
  \iftdir
    \if #1y\relax
      \let\box@dir\yoko
      \@tempcnta=\z@    % \(y)strutbox
    \else\if #1z\relax
      \@rotswtrue
      \let\box@dir\tate
      \@tempcnta=\tw@   % \zstrutbox
    \else
      \let\box@dir\tate
      \@tempcnta=\@ne   % \tstrutbox
    \fi\fi
  \else
    \if #1t\relax
      \let\box@dir\tate
      \@tempcnta=\@ne   % \tstrutbox
    \else
      \let\box@dir\yoko
      \@tempcnta=\z@    % \(y)strutbox
    \fi
  \fi
  %%%%% new code end
  \setbox \@arstrutbox \hbox{\box@dir %% add \box@dir
      % the behavior of \strutbox has been changed
      % (box resister -> conditional macro) in pLaTeX2e 2017/04/08;
      % so, \strutbox should appear after \box@dir is applied.
      \@tempcntb=\ifcase\@tempcnta\strutbox
                 \or\tstrutbox\or\zstrutbox\or\@ctrerr\fi
      \@tempdima \ht \@tempcntb
      \advance \@tempdima by\extrarowheight
      \vrule \@height \arraystretch \@tempdima
             \@depth \arraystretch \dp \@tempcntb
             \@width \z@}%
  \fork@array@option<#1>[#2]%  %% merged from plext
  \begingroup
  \@mkpream{#3}%
  % following definition of \@preamble is from plext (\edef -> \xdef),
  % but it's not the same as the one in array; why?
  \xdef\@preamble{\ialign \noexpand \@halignto
                  \bgroup \tabskip \z@skip \@arstrut \@preamble
                          \tabskip \z@skip \cr}%
  \endgroup
  \@arrayleft
  \@begin@alignbox %% defined inside \fork@array@option
  \bgroup
  \box@dir\adjustbaseline
  \let\par\@empty
  \let\@sharp##\let\protect\relax
  \let\\\@arraycr\let\tabularnewline\\
  \lineskip\z@skip\baselineskip\z@skip\@preamble}
%
\def\endarray{\crcr \egroup \egroup \@end@alignbox \@arrayright \gdef\@preamble{}}
%
%% done

\endinput