summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/zztex/zztabbing.tex
blob: 08257a45f4148586dbddc65f1ad3c64383b7ee79 (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module:    ZzTeX Tabbing Facilities
%
% Synopsis:  This module contains the definition of the block that is
%            used to format text with tab stops.
%
% Authors:   Paul C. Anagnostopoulos
% Created:   27 May 2016
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%                       Tabbing Block
%                       ------- -----


\defineblock{\tabbing}{\endtabbing}{\false}{}
\resetinvcontext{\tabbing}

%~block tabbing Type
% \abovepenalty = integer               % Penalty above text.
% \aboveskip = glue                     % Space b/b above text.
% \setflag \autocallout = boolean       % Automatically number lines?
% \def \beginformat {...}               % Beginning of text formatter.
% \belowpenalty = integer               % Penalty below text.
% \belowskip = glue                     % Space b/b below text.
% \bodyfont = {font}                    % Body font.
% \def \calloutformat ##1{...}          % Callout formatter.
% \calloutnumber = integer              % Number of first callout.
% \def \callouttext {...}               % Callout text or \arg.
% \defaulttabwidth = dimen              % Default repeating tab width.
% \def \endformat {...}                 % End of text formatter.
% \leftindent = glue                    % Left indentation.
% \rightindent = glue                   % Right indentation.
% \tabbinggapskip = glue                % Standard tabbing gap.
% \textcolor = {...}                    % Color of text.
% \width = dimen                        % Line width.
%~end

\defineskip{\tabbinggapskip}{0pt}

\def \tabbing #1{%                                         {type}
  \blockcantbein{\tabbing}{\tabbing}%
  \beginblockscope{tabbing}%
  \global\increment \tabbingdepth
  \abovepenalty = \breakgood                            %~default hard
  \setflag \autocallout = \false                        %~default soft
  \def \beginformat {}%                                 %~default soft
  \belowpenalty = \breakgood                            %~default hard
  \calloutnumber = 1                                    %~default with
  \def \callouttext {\number\calloutnumber}%            %~default soft
  \defaulttabwidth = \mindimen                          %~default soft
  \def \endformat {}%                                   %~default soft
  \tabbinggapskip = \enclosingbaselineskip              %~default soft
  \textcolor = {}%                                      %~default soft
  \parindent = 0pt
  \parrag = 0pt
  \parskip = 0pt
  \processdesign{\tabbing}{#1}%
  \global\increment \tabbingnumber
  \tabbingformat
  \def \zarg {\arg}%
  \if \tokeqlp{\callouttext}{\zarg}%
    \defineatsigncommand @##{\ztbngatcallout}%
  \else
    \defineatsigncommand @##{\ztbngatcallout{\callouttext}}%
  \fi
  \if \emptytoksp{\textcolor}%          % Must have a group around \ztbnginit.
    \bgroup
  \else
    \color{\the\textcolor}%
  \fi
    \ztbnginit
    \ztbngstartline}

\def \endtabbing {%
    \ztbngfinal
  \if \emptytoksp{\textcolor}%
    \egroup % \tabbing group
  \else
    \endcolor
  \fi
  \futurelet\nexttoken \zendtabbing}

\def \zendtabbing {%
  \endtabbingformat
  \global\decrement \tabbingdepth
  \endblockscope{tabbing}%
  \parnext}

\def \tabbingformat {%
  \endgraf
  \the\bodyfont
  \bbskipabove{\abovepenalty}{\aboveskip}%
  \alterindentation{\leftindent}{\rightindent}%
  \settextwidth{\width}%
  \beginformat}

\def \endtabbingformat {%
  \endformat
  \bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}}

%~ Use this command in between lines in a |\tabbing| block to
%~ perform a vertical adjustment between those two lines. For example,
%~
%~   \adjusttabbing{\fullpagebreak}

\long\def \adjusttabbing #1{%                           {commands}
  \ztbngadjust{#1}}

%                       Initialize and Finalize
%                       ---------- --- --------


\definecount{\ztbngstopcount}{0}
\definecount{\ztbngstopindex}{0}

\definebox{\ztbngline}
\definebox{\ztbngfragment}


\def \ztbnginit {%
  \let \par = \ztbngshouldntbepar
  \def \nl {\ztbngfinishline{\false}}%
  \defineatsigncommand @.{\ztbngatsetstop}%
  \defineatsigncommand @>{\ztbngattab}%
  \defineatsigncommand @C{\ztbngatclear}%
  \defineatsigncommand @D{\ztbngatdiscard}%
  \ztbngsetdefaultstops{\defaulttabwidth}}

\def \ztbngsetdefaultstops #1{%                         {width}
  \global\ztbngstopcount = 0
  \def \ztbngstop {0pt}%
  \if \dimgtrp{#1}{0pt}%
    \tdimena = 0pt
    \loop
      \global\increment \ztbngstopcount
      \advance \tdimena by #1\relax
      \withname\edef {\ztbngstop\romannumeral\ztbngstopcount}{\the\tdimena}%
    \if \dimlssp{\tdimena}{\hsize}%
    \repeat
  \fi}

\def \ztbngfinal {%
  \ztbngfinishline{\true}}

%                       Build Lines
%                       ----- -----


\def \ztbngstartline {%
  \ztbngstopindex = 0
  \setbox\ztbngline = \hbox{}%
  \global\setflag \ztbngdiscardp = \false
  \settaginfo{\number\calloutnumber}{???title???}%
  \ztbngstartfragment}

\def \ztbngstartfragment {%
  \setbox \ztbngfragment = \hbox\bgroup
    \ignorespaces}

\def \ztbngfinishfragment {%
  \egroup % \ztbngfragment box
  \setbox\ztbngline = \hbox{%
    \unhbox\ztbngline
    \tdimena = \name{\ztbngstop\romannumeral\ztbngstopindex}%
    \hskip \tdimena
    \tdimenb = \hsize
    \advance \tdimenb by -\tdimena
    \hbox to \tdimenb{\copy\ztbngfragment \hfil}%
    \hskip -\tdimenb
    \hskip -\tdimena}}

\def \ztbngfinishline #1{%                              {end-of-block?}
  \ztbngfinishfragment
  \if \notp{\ztbngdiscardp}%
    \if \orp{\posp{\ztbngstopindex}}{\dimposp{\wd\ztbngfragment}}%
      \noindent
        \if \autocallout
          \llap{\calloutformat{\the\calloutnumber}}%
          \increment \calloutnumber
        \fi
        \box\ztbngline
      \endgraf
    \else\if \notp{#1}%
      \vspace{\tabbinggapskip}%
    \fi\fi
  \fi
  \if #1\let \znext = \relax \else \let \znext = \ztbngstartline \fi
  \znext}

%                       At-sign Commands
%                       ------- --------


% @#{callout}text...

\def \ztbngatcallout #1{%                               {callout}
  \ztbngfinishfragment
  \if \andp{\zerop{\ztbngstopindex}}{\dimzerop{\wd\ztbngfragment}}
    \setbox\ztbngfragment = \hbox\bgroup
      \llap{\calloutformat{#1}}%
    \ztbngfinishfragment
  \else
    \error{badtabcallout}{Callout command (\noexpand@##) must appear
                          at the beginning of the line}%
  \fi
  \increment \calloutnumber
  \ztbngstartfragment}

% text@.more text...

\def \ztbngatsetstop {%
  \ztbngfinishfragment
  \tdimena = \name{\ztbngstop\romannumeral\ztbngstopindex}%
  \advance \tdimena by \wd\ztbngfragment
  \increment \ztbngstopindex
  \if \gtrp{\ztbngstopindex}{\ztbngstopcount}%
    \withname\edef {\ztbngstop\romannumeral\ztbngstopindex}{\the\tdimena}%
    \increment \ztbngstopcount
  \else
    \error{badtabstop}{There is already a tab stop}%
  \fi
  \ztbngstartfragment}

% text@>more text...

\def \ztbngattab {%
  \ztbngfinishfragment
  \if \lssp{\ztbngstopindex}{\ztbngstopcount}%
    \increment \ztbngstopindex
  \else
    \warning{toomanytabs}{Too many tabs on line; extra tabs ignored}%
  \fi
  \ztbngstartfragment}

% @Ctext...\nl

\def \ztbngatclear {%
  \if \zerop{\ztbngstopindex}%
    \global\ztbngstopcount = 0\relax
  \else
    \error{badtabclear}{Tabs must be cleared at the beginning of the line}%
  \fi}

% text@D\nl

\def \ztbngatdiscard {%
  \global\setflag \ztbngdiscardp = \true \relax}

%                       Adjustment
%                       ----------


\long\def \ztbngadjust #1{%                             {commands}
  \ztbngfinishfragment
  \if \andp{\zerop{\ztbngstopindex}}{\dimzerop{\wd\ztbngfragment}}
    #1%
  \else
    \error{badtabadjust}{The \noexpand\adjusttabbing command must appear
                         in between lines}%
  \fi
  \ztbngstartfragment}