summaryrefslogtreecommitdiff
path: root/macros/lamstex/inputs/ptmatrix.tex
blob: 21d54bbcd9b7e9fc66c0c49a9c74a4f8bbd1be84 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
% PTMATRIX.TEX   VERSION 2.0
% COPYRIGHT (C) 1991 BY THE TEXPLORATORS CORPORATION
% ALL RIGHTS RESERVED

% THIS FILE SHOULD NOT BE CHANGED IN ANY WAY.

\catcode`\@=11
\let\alloc@\alloc@@
\newif\ifformat@
\newcount\ptmrowcount@
\newcount\ptmcolcount@
\newcount\ptmColcount@
\newcount\maxptmrow@
\newbox\ptmbox@
\def\qstrut@{\ifnum\ptmrowcount@<\@ne\Mathstrut@\fi}
\def\GAM@{\global\advance\ptmcolcount@\@ne}
\newif\iflastmrow@
\def\partition\matrix{\global\format@false\bgroup
 \let\endmatrix\ptmendmatrix@
 \null\,\vcenter\bgroup\hbox\bgroup$\global\setbox\ptmbox@\vbox\bgroup
 \Let@\vspace@\normalbaselines\openup\spreadmlines@
 \global\ptmrowcount@\m@ne\global\ptmcolcount@\z@\global\ptmColcount@\z@
 \everycr{\noalign{\iflastmrow@\else\global\advance\ptmrowcount@\@ne
  \ifnum\ptmcolcount@<\ptmColcount@\else\global\ptmColcount@\ptmcolcount@
  \global\maxptmrow@\ptmrowcount@\fi\global\ptmcolcount@\z@\fi}}%
 \tabskip\z@skip\halign\bgroup\hfil\qstrut@$\m@th##$\hfil\GAM@
  &&\quad\hfil$\m@th##$\hfil\GAM@\crcr}
\def\format{\crcr\egroup\iffalse{\fi\ifnum`}=\z@\fi
 \global\advance\ptmrowcount@\m@ne
 \global\format@true\format@}
\def\format@#1\\{\def\preamble@{#1}%
 \def\l{\noexpand\qstrut@$\m@th\the\hashtoks@$\hfil\noexpand\GAM@}%
 \def\c{\noexpand\qstrut@\hfil$\m@th\the\hashtoks@$\hfil\noexpand\GAM@}%
 \def\r{\noexpand\qstrut@\hfil$\m@th\the\hashtoks@$\noexpand\GAM@}%
 \edef\Preamble@{\preamble@}\global\let\Preamble@@\Preamble@
 \ifnum`{=\z@\fi\iffalse}\fi\tabskip\z@skip\halign\bgroup\span\Preamble@\crcr}
\def\formatmatrixgap@{\global\let\matrixgap@\empty
 \setbox4=\vbox{\ialign{\span\Preamble@@\cr\the\toks@\cr}}%
 \setbox4=\vbox{\unvbox4 
  \setboxzl@
  \setboxz@h{\unhbox\z@\count@\z@
   \loop\unskip\setboxzl@\ifvoid\z@\else
   {\let\or\relax\xdef\matrixgap@{\matrixgap@
    \ifnum\count@=\z@\else\or\fi\the\wdz@}}%
   \advance\count@\@ne
   \repeat}%
   {\let\or\relax
   \xdef\matrixgap@##1{\noexpand\ifcase##1 \matrixgap@\noexpand\fi}}%
  }%
}
\newcount\mcolcount@
\newcount\bordercount@
\def\ptmendmatrix@{\crcr\noalign{\global\lastmrow@true}\Mathstrut@\crcr
 \noalign{\global\lastmrow@false\kern-\baselineskip}%
 \egroup\egroup
 \bordercount@\ptmrowcount@\advance\bordercount@\m@ne
 \setbox\z@\vbox   
  {\unvcopy\ptmbox@\unkern\setboxzl@\unskip\setboxzl@
   \count@\ptmrowcount@
   \loop
    \ifnum\count@>\maxptmrow@
    \unskip\setboxzl@\advance\count@\m@ne
   \repeat 
   \global\let\matrixgap@\empty\global\mcolcount@\tw@
   \setbox\tw@\hbox
    {\unhcopy\z@\unskip\setboxzl@\unskip\setboxzl@
     \loop\unskip\setboxzl@
     \ifvoid\z@\else\global\advance\mcolcount@\@ne
     {\let\or\relax\xdef\matrixgap@{\matrixgap@\or10pt}}%
    \repeat}%
   {\let\or\relax\xdef\matrixgap@##1{\noexpand
    \ifcase##1 10pt\matrixgap@\or0pt\noexpand\fi}}%
   \ifformat@
    \toks@{&}\count@\tw@
    \loop
     \ifnum\count@<\mcolcount@\advance\count@\@ne
     \toks@\expandafter{\the\toks@&}%
    \repeat
    \formatmatrixgap@
   \fi
   \xdef\rowbot@{\ifdim\dp\z@>\dp\Mathstrutbox@-\the\dp\z@\else
    -\the\dp\Mathstrutbox@\fi}%
   \xdef\rowtop@{\ifdim\ht\z@>\ht\Mathstrutbox@\the\ht\z@
    \else\the\ht\Mathstrutbox@\fi}%
   \xdef\midrow@{\the\ht\z@}\xdef\midcol@{0pt}%
   \dimen@\z@
   \setbox\tw@\hbox
    {\unhbox\z@ 
     \count@\z@
     \loop
     \unskip\setboxzl@
     \ifvoid\z@\else
     \advance\dimen@\wdz@
     \dimen@ii\matrixgap@\count@
     \advance\dimen@-.5\dimen@ii
     {\let\or\relax\xdef\midcol@{\the\dimen@\or\midcol@}}%
     \advance\dimen@-.5\dimen@ii
     {\let\or\relax\xdef\leftcol@{\the\dimen@\ifnum\count@=\z@\else
      \or\leftcol@\fi}}%
     {\advance\dimen@-\wdz@\advance\dimen@\dimen@ii\let\or\relax
      \xdef\rightcol@{\the\dimen@\ifnum\count@=\z@\else\or\rightcol@\fi}}%
     \advance\dimen@\dimen@ii\advance\count@\@ne
     \repeat
    }%
   \global\let\matrixgap@\relax 
   {\let\or\relax\xdef\midcol@##1{\noexpand
    \ifcase##1 \midcol@\noexpand\else\noexpand\Err@{##1 too large}%
    \noexpand\fi}%
   \xdef\leftcol@##1{\noexpand\ifcase##1 \noexpand\or\leftcol@\noexpand\fi}%
   \xdef\rightcol@##1{\noexpand\ifcase##1 \noexpand\or\rightcol@\noexpand\fi}%
   }%
  }%
  \setbox\z@\vbox
   {\unvcopy\ptmbox@\unkern\setboxzl@\unskip
    \setboxzl@
    \xdef\rowbl@{0pt}%
    \dimen@ii\ht\z@
    \dimen@\midrow@\relax\skip@\lastskip\unskip
    \advance\skip@\lastskip\unskip
    \advance\dimen@.5\skip@\xdef\midrow@{\the\dimen@}%
    \loop
     \setboxzl@
     \ifvoid\z@\else
      \advance\dimen@ii\skip@
      {\let\or\relax\xdef\rowbot@{\rowbot@\or\the\dimen@ii}}%
      \advance\dimen@ii\dp\z@
      {\let\or\relax\xdef\rowbl@{\rowbl@\or\the\dimen@ii}}%
      \advance\dimen@ii\ht\z@
      {\let\or\relax\xdef\rowtop@{\rowtop@\or\the\dimen@ii}}%
      \advance\dimen@.5\skip@
      \advance\dimen@\dp\z@\advance\dimen@\ht\z@
      \skip@\lastskip\unskip\advance\skip@\lastskip\unskip
      \advance\dimen@.5\skip@
      {\let\or\relax\xdef\midrow@{\midrow@\or\the\dimen@}}%
    \repeat
    {\let\or\relax\xdef\midrow@##1{\noexpand
     \ifcase##1 0pt\or\midrow@\noexpand\else
     \noexpand\Err@{##1 too large}\noexpand\fi}%
    \xdef\rowbot@##1{\noexpand\ifcase##1 \or\rowbot@\noexpand\fi}% 
    \xdef\rowbl@##1{\noexpand\ifcase##1 \or\rowbl@\noexpand\fi}%
    \xdef\rowtop@##1{\noexpand\ifcase##1 \or\rowtop@\noexpand\fi}%
    }%
   }%
  \box\ptmbox@
  \let\midcol\midcol@\global\let\midcol@\relax
  \let\midrow\midrow@\global\let\midrow@\relax
}
\def\endpartition{$\egroup\egroup\,\egroup
 \global\let\leftcol@\relax \global\let\rightcol@\relax
 \global\let\rowbot@\relax \global\let\rowtop@\relax
 \global\let\rowbl@\relax}
\newcount\count@@@@@
\edef\countdimen@#1{\setboxz@h{\def\noexpand\next@{\global\dimen@i}%
 \afterassignment\noexpand\next@\global
 \count@@@@@\noexpand\strip@#1 \space0pt}}
\def\hsolid{\ifnum\catcode`\:=\active\expandafter\hsolidA@\else
 \expandafter\hsolidO@\fi}
\def\hsolidO@#1:#2#3{\hsolid@{#1}{#2}{#3}}
\def\hsolid@#1#2#3{\def\HLEADERS{\hsolidleaders}\HPARTITION{#1}{#2}{#3}}
\def\hdashed{\ifnum\catcode`\:=\active\expandafter\hdashedA@\else
 \expandafter\hdashedO@\fi}
\def\hdashedO@#1:#2#3{\hdashed@{#1}{#2}{#3}}
\def\hdashed@#1#2#3{\def\HLEADERS{\hdashedleaders}\HPARTITION{#1}{#2}{#3}}
\def\HPARTITION#1#2#3{\countdimen@{#1}\dimen@\midrow\count@@@@@
 \advance\dimen@\dimen@i\advance\dimen@\dp\Mathstrutbox@
 \smash{\llap{\raise\dimen@
  \hbox{\countdimen@{#2}\dimen@\midcol\count@@@@@\advance\dimen@-\dimen@i
  \countdimen@{#3}\dimen@ii\midcol\count@@@@@\advance\dimen@ii-\dimen@i
  \advance\dimen@-\dimen@ii
  \HLEADERS\hskip\dimen@\hskip\dimen@ii}}}}
\def\vsolid{\ifnum\catcode`\:=\active\expandafter\vsolidA@\else
 \expandafter\vsolidO@\fi}
\def\vsolidO@#1:#2#3{\vsolid@{#1}{#2}{#3}}
\def\vsolid@#1#2#3{\def\VLEADERS{\vsolidleaders}\VPARTITION{#1}{#2}{#3}}
\def\vdashed{\ifnum\catcode`\:=\active\expandafter\vdashedA@\else
 \expandafter\vdashedO@\fi}
\def\vdashedO@#1:#2#3{\vdashed@{#1}{#2}{#3}}
\def\vdashed@#1#2#3{\def\VLEADERS{\vdashedleaders}\VPARTITION{#1}{#2}{#3}}
\newdimen\vextra@
\def\VPARTITION#1#2#3{\countdimen@{#3}\dimen@\midrow\count@@@@@
 \advance\dimen@\dimen@i\advance\dimen@\dp\Mathstrutbox@
 \countdimen@{#2}\dimen@ii\midrow\count@@@@@
 \advance\dimen@ii\dimen@i\advance\dimen@ii\dp\Mathstrutbox@
 \setbox\z@\vbox to\p@{\VLEADERS\vfil}\vextra@\wdz@
 \llap{\hbox{\smash{\vbox to\dimen@{\VLEADERS\vfil\vskip\dimen@ii}}%
  \hskip-\vextra@\relax\countdimen@{#1}\hskip\midcol\count@@@@@
  \hskip-\dimen@i}}}
\def\vleft{\ifnum\catcode`\:=\active\expandafter\vleftA@\else
 \expandafter\vleftO@\fi}
\def\vleftO@#1#2:#3#4{\vleft@#1{#2}{#3}{#4}}
\def\vleft@#1#2#3#4{\dimen@\rowtop@{#4}\advance\dimen@-\rowbot@{#3}%
 \dimen@ii\rowbl@{#3}\advance\dimen@ii.5\dimen@\advance\dimen@ii-\mathaxis@
 \countdimen@{#2}%
 \llap{\hbox{\smash{\raise\dimen@ii\hbox{$\left#1\vcenter{\vbox to
  \dimen@{}}\right.$}}\hskip\leftcol@\count@@@@@\hskip-\dimen@i}}}
\def\vright{\ifnum\catcode`\:=\active\expandafter\vrightA@\else
 \expandafter\vrightO@\fi}
\def\vrightO@#1#2:#3#4{\vright@#1{#2}{#3}{#4}}
\def\vright@#1#2#3#4{\dimen@\rowtop@{#4}\advance\dimen@-\rowbot@{#3}%
 \dimen@ii\rowbl@{#3}\advance\dimen@ii.5\dimen@\advance\dimen@ii-\mathaxis@
 \countdimen@{#2}%
 \llap{\hbox{\smash{\raise\dimen@ii\hbox{\setboxz@h{$\left.\vcenter{\vbox to
  \dimen@{}}\right#1$}\global\dimen\thr@@\wdz@\boxz@}}}%
  \hskip\rightcol@\count@@@@@\hskip-\dimen@i\hskip-\dimen\thr@@}}%
{\catcode`\:=\active
 \gdef\hsolidA@#1:#2#3{\hsolid@{#1}{#2}{#3}}
 \gdef\hdashedA@#1:#2#3{\hdashed@{#1}{#2}{#3}}
 \gdef\vsolidA@#1:#2#3{\vsolid@{#1}{#2}{#3}}
 \gdef\vdashedA@#1:#2#3{\vdashed@{#1}{#2}{#3}}
 \gdef\vleftA@#1#2:#3#4{\vleft@#1{#2}{#3}{#4}}
 \gdef\vrightA@#1#2:#3#4{\vright@#1{#2}{#3}{#4}}
}
\def\bdmatrix#1\\#2\\#3\endbdmatrix{\partition
 \matrix\format\c&\quad\hskip\jot\c&&\quad\c\\
 #1\\\vspace{\jot}\Mathstrut@#2\\#3\endmatrix
 \vleft@(21\bordercount@
 \vright@)\ptmColcount@1\bordercount@\endpartition}
\def\alloc@#1#2#3#4#5{\global\advance\count1#1by\@ne
  \ch@ck#1#4#2%
  \allocationnumber=\count1#1%
  \global#3#5=\allocationnumber
  \wlog{\string#5=\string#2\the\allocationnumber}}
\catcode`\@=\active

\def\hsolidleaders{\leaders\hrule}

\def\vsolidleaders{\leaders\vrule}

\def\hdashedleaders{\xleaders\hbox to5pt{\hfil
  \leaders\hrule\hskip2.5pt\hfil}}

\def\vdashedleaders{\xleaders\vbox to5pt{\vfil\leaders\vrule\vskip2.5pt}}