| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX General Text Facilities |
| 4 |
% |
| 5 |
% Synopsis: This module contains definitions for blocks that are used to |
| 6 |
% format text. |
| 7 |
% |
| 8 |
% Notes: The tabbing facility was implemented by Richard A. Wells and |
| 9 |
% integrated into ZzTeX on 8/16/94. |
| 10 |
% |
| 11 |
% Authors: Paul C. Anagnostopoulos and Richard A. Wells |
| 12 |
% Created: 14 March 1990 |
| 13 |
% |
| 14 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 15 |
% under The MIT License (opensource.org/licenses/MIT) |
| 16 |
% |
| 17 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 18 |
|
| 19 |
% Text Block |
| 20 |
% ---- ----- |
| 21 |
|
| 22 |
|
| 23 |
\defineblock{\text}{\endtext}{\false}{} |
| 24 |
\resetinvcontext{\text} |
| 25 |
|
| 26 |
%~block text Type, Level |
| 27 |
% \abovepenalty = integer % Penalty above text. |
| 28 |
% \aboveskip = glue % Space b/b above text. |
| 29 |
% \def \beginformat {...} % Beginning of text formatter. |
| 30 |
% \belowpenalty = integer % Penalty below text. |
| 31 |
% \belowskip = glue % Space b/b below text. |
| 32 |
% \bodyfont = {font} % Body font. |
| 33 |
% \def \calloutformat ##1{...} % Callout formatter. |
| 34 |
% \calloutnumber = integer % Number of first callout. |
| 35 |
% \def \callouttext {...} % Callout text or \arg. |
| 36 |
% \defaulttabwidth = dimen % Default repeating tab width. |
| 37 |
% \setflag \enabletabbing = flag % Enable tabbing commands. |
| 38 |
% \def \endformat {...} % End of text formatter. |
| 39 |
% \leftindent = glue % Left indentation. |
| 40 |
% \parindent = dimen % Paragraph indentation. |
| 41 |
% \parrag = dimen % Paragraph raggedness. |
| 42 |
% \parskip = glue % Paragraph skip. |
| 43 |
% \rightindent = glue % Right indentation. |
| 44 |
% \textcolor = {...} % Color of text. |
| 45 |
% \setflag \verbatimlines = flag % Treat line breaks verbatim. |
| 46 |
% \width = dimen % Line width. |
| 47 |
%~end |
| 48 |
|
| 49 |
\definecount{\calloutnumber}{0} |
| 50 |
\setflag \enabletabbing = \false |
| 51 |
\definedimen{\defaulttabwidth}{0pt} |
| 52 |
\setflag \verbatimlines = \false |
| 53 |
|
| 54 |
|
| 55 |
\def \text #1{% {type} |
| 56 |
\beginblockscope{text}% |
| 57 |
\global\increment \textdepth |
| 58 |
\abovepenalty = \breakgood %~default hard |
| 59 |
\def \beginformat {}% %~default soft |
| 60 |
\belowpenalty = \breakgood %~default hard |
| 61 |
\calloutnumber = 1 %~default with |
| 62 |
\def \callouttext {\number\calloutnumber}% %~default soft |
| 63 |
\defaulttabwidth = \mindimen %~default soft |
| 64 |
\setflag \enabletabbing = \false %~default soft |
| 65 |
\def \endformat {}% %~default soft |
| 66 |
\textcolor = {}% %~default soft |
| 67 |
\setflag \verbatimlines = \false %~default soft |
| 68 |
\processdesign{\text}{#1\romannumeral\textdepth}% |
| 69 |
\global\increment \textnumber |
| 70 |
\textformat |
| 71 |
\def \zarg {\arg}% |
| 72 |
\if \tokeqlp{\callouttext}{\zarg}% |
| 73 |
\defineatsigncommand @##{\ztextcoformat}% |
| 74 |
\else |
| 75 |
\defineatsigncommand @##{\ztextcoformat{\callouttext}}% |
| 76 |
\fi |
| 77 |
\if \emptytoksp{\textcolor}% |
| 78 |
\bgroup |
| 79 |
\else |
| 80 |
\color{\the\textcolor}% |
| 81 |
\fi |
| 82 |
\if \enabletabbing \ztabinittabbing \fi |
| 83 |
\if \verbatimlines \obeylines \fi |
| 84 |
\if \enabletabbing \ztabstarttabbing \fi} |
| 85 |
|
| 86 |
\def \endtext {% |
| 87 |
% Must really be \par, not \endgraf, because might be redefined |
| 88 |
% for tabbing. |
| 89 |
\if \notp{\verbatimlines}% |
| 90 |
% In \verbatimlines the line preceding \endtext{...} will put |
| 91 |
% out a final \par, but if not we have to do it here. |
| 92 |
\par |
| 93 |
\fi |
| 94 |
\if \enabletabbing \ztabfinaltabbing \fi |
| 95 |
\if \emptytoksp{\textcolor}% |
| 96 |
\egroup |
| 97 |
\else |
| 98 |
\endcolor |
| 99 |
\fi |
| 100 |
\futurelet\nexttoken \zendtext} |
| 101 |
|
| 102 |
\def \zendtext {% |
| 103 |
\endtextformat |
| 104 |
\global\decrement \textdepth |
| 105 |
\endblockscope{text}% |
| 106 |
\parnext} |
| 107 |
|
| 108 |
\def \textformat {% |
| 109 |
\endgraf |
| 110 |
\the\bodyfont |
| 111 |
\bbskipabove{\abovepenalty}{\aboveskip}% |
| 112 |
\alterindentation{\leftindent}{\rightindent}% |
| 113 |
\settextwidth{\width}% |
| 114 |
\setparrag{\parrag}% |
| 115 |
\beginformat} |
| 116 |
|
| 117 |
\def \endtextformat {% |
| 118 |
\endformat |
| 119 |
\bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}} |
| 120 |
|
| 121 |
\def \ztextcoformat #1{% {text} |
| 122 |
\calloutformat{#1}% |
| 123 |
\global\increment \calloutnumber} |
| 124 |
|
| 125 |
% Tabbing Commands |
| 126 |
% ------- -------- |
| 127 |
|
| 128 |
% These commands are available in a text block if \enabletabbing is turned on. |
| 129 |
|
| 130 |
|
| 131 |
% \ztabinitalizetabbing |
| 132 |
% - Redefines \par |
| 133 |
% - Defines the @ commands for tabbing. (The real work is done in the |
| 134 |
% in the \ztabcmd* macros, defined below.) |
| 135 |
% - Initializes variables |
| 136 |
|
| 137 |
\def \ztabinittabbing {% |
| 138 |
% Redefine \par to ship out the tabbed line, \endgraf it and start a |
| 139 |
% new tabbed line |
| 140 |
\let \par = \ztabpar |
| 141 |
% Define tabbing commands |
| 142 |
\def \adjusttabbing ##1{\ztabadjusttabbing{##1}}% |
| 143 |
\defineatsigncommand @.{\ztabcmdset}% |
| 144 |
\defineatsigncommand @>{\ztabcmdforwards}% |
| 145 |
\defineatsigncommand @+{\ztabcmdindent}% |
| 146 |
\defineatsigncommand @-{\ztabcmdoutdent}% |
| 147 |
\defineatsigncommand @D{\ztabcmddiscard}% |
| 148 |
\defineatsigncommand @C{\ztabcmdclear}% |
| 149 |
\defineatsigncommand @E##1{\ztabcmdevery{##1}}% |
| 150 |
% Initialize variables |
| 151 |
\if \verbatimlines |
| 152 |
% The line with \text{...} will put out the first \par, so we |
| 153 |
% want to skip it. |
| 154 |
\ztabdiscardtrue |
| 155 |
\else |
| 156 |
\ztabdiscardfalse |
| 157 |
\fi |
| 158 |
\global\ztabindentlevel=0\relax |
| 159 |
% Clear all tab stops |
| 160 |
\ztabcmdclear} |
| 161 |
|
| 162 |
\def \ztabparfinishpreviousline {% |
| 163 |
% Set state checked by \ztabendtabcell |
| 164 |
\ztabatnltrue |
| 165 |
% End last tab cell with \ztabnltrue |
| 166 |
\ztabendtabcell |
| 167 |
\egroup% closes inner group started below in \ztabmaketabbedline |
| 168 |
\egroup% closes outer group started below in \ztabmaketabbedline |
| 169 |
% Unless discarding, deposit the line and remove the last box |
| 170 |
\if \notp{\ztabdiscardp}% |
| 171 |
\unvbox\zboxa\lastbox |
| 172 |
\else |
| 173 |
% Clear discarding flag |
| 174 |
\ztabdiscardfalse |
| 175 |
\fi |
| 176 |
\endgroup% closes outermost group started by \ztabmaketabbedline |
| 177 |
% We should be back in vertical mode now. |
| 178 |
% |
| 179 |
% Reset \ztabsbox. The new value is the set of tbd boxes |
| 180 |
% followed by the done boxes. If not all of the tbd boxes were |
| 181 |
% used this should result in the same set of boxes as the |
| 182 |
% previous value of \ztabsbox. However, if the tbd boxes were used up |
| 183 |
% then the done boxes may contain additional boxes built on the fly. |
| 184 |
\setbox\ztabsbox\hbox{\unhbox\ztabstbdbox\unhbox\ztabsdonebox}} |
| 185 |
|
| 186 |
\def \ztabparstartnextline {% |
| 187 |
\ztabmaketabbedline} |
| 188 |
|
| 189 |
\def \ztabpar {% macro used instead of \par in tabbing |
| 190 |
\ztabparfinishpreviousline |
| 191 |
\endgraf |
| 192 |
\ztabparstartnextline} |
| 193 |
|
| 194 |
\def \ztabstarttabbing {% |
| 195 |
\ztabparstartnextline} |
| 196 |
|
| 197 |
\def \ztabfinaltabbing {% |
| 198 |
% Discard and finish last tabbed line started by last \ztabpar |
| 199 |
\ztabdiscardtrue |
| 200 |
\ztabparfinishpreviousline} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
% Variables shared by \ztab* macros |
| 205 |
|
| 206 |
% Counts and dimens for building tab boxes |
| 207 |
\definecount{\ztabindentlevel}{0} |
| 208 |
\definecount{\ztabindentcounter}{0} |
| 209 |
\definedimen{\ztabcolwidth}{0pt} |
| 210 |
\definedimen{\ztabtabpos}{0pt} |
| 211 |
\definedimen{\ztabdimenii}{0pt} |
| 212 |
|
| 213 |
% Conditionals |
| 214 |
% atnlp: are we at a \nl in tab processing? |
| 215 |
\def \ztabatnlfalse {\global\setflag \ztabatnlp=\false}% |
| 216 |
\def \ztabatnltrue {\global\setflag \ztabatnlp=\true}% |
| 217 |
% discardp: are we discarding this line's output? |
| 218 |
\def \ztabdiscardfalse {\global\setflag \ztabdiscardp=\false}% |
| 219 |
\def \ztabdiscardtrue {\global\setflag \ztabdiscardp=\true}% |
| 220 |
% settingp: are we setting? |
| 221 |
\def \ztabsettingfalse {\global\setflag \ztabsettingp=\false}% |
| 222 |
\def \ztabsettingtrue {\global\setflag \ztabsettingp=\true}% |
| 223 |
% tabbingp: are we tabbing? |
| 224 |
\def \ztabtabbingfalse {\global\setflag \ztabtabbingp=\false}% |
| 225 |
\def \ztabtabbingtrue {\global\setflag \ztabtabbingp=\true}% |
| 226 |
|
| 227 |
|
| 228 |
% Boxes to hold the tabs |
| 229 |
\definebox{\ztabsbox}% hbox of hboxes for each tab column |
| 230 |
\definebox{\ztabstbdbox}% hbox of hbox tab columns still "to be done" |
| 231 |
\definebox{\ztabsdonebox}% hbox of hbox tab columns already done |
| 232 |
\definebox{\ztabsindentbox}% hbox of indents |
| 233 |
|
| 234 |
|
| 235 |
% The macros that implement the tabbing commands. \ztabcmd* are the |
| 236 |
% top-level macros called by the @ commands. Other \ztab* macros are |
| 237 |
% helpers. |
| 238 |
|
| 239 |
\def \ztabcmdset {% |
| 240 |
% Set state checked by \ztabendtabcell |
| 241 |
\ztabsettingtrue |
| 242 |
% End the current cell with \ztabsettingtrue |
| 243 |
\ztabendtabcell |
| 244 |
% Start the next cell |
| 245 |
\ztabbegintabcell\noindent\ignorespaces}% |
| 246 |
|
| 247 |
\def \ztabcmdforwards {% |
| 248 |
% Set state checked by \ztabendtabcell |
| 249 |
\ztabtabbingtrue |
| 250 |
% End the current cell with \ztabsettingtrue |
| 251 |
\ztabendtabcell |
| 252 |
% Start the next cell |
| 253 |
\ztabbegintabcell\noindent\ignorespaces}% |
| 254 |
|
| 255 |
\def \ztabcmdindent {\global\increment \ztabindentlevel\relax}% |
| 256 |
|
| 257 |
|
| 258 |
\def \ztabcmdoutdent {% |
| 259 |
\global\decrement \ztabindentlevel\relax |
| 260 |
\if \negp{\ztabindentlevel}% |
| 261 |
\zzerror{Attempt to tab dedent (with \string@-) to left of left margin}% |
| 262 |
\fi} |
| 263 |
|
| 264 |
\def \ztabcmddiscard {% |
| 265 |
\ztabdiscardtrue}% |
| 266 |
|
| 267 |
\def \ztabcmdclear {% {boolean: initialization} |
| 268 |
% First clear all boxes |
| 269 |
\ztabcleartabboxes |
| 270 |
% Surprise! Clearing tabs might actually set them, if \defaulttabwidth |
| 271 |
% has been set in the design |
| 272 |
\if \neqlp{\defaulttabwidth}{\mindimen}% |
| 273 |
\ztabcmdevery{\defaulttabwidth}% |
| 274 |
\else |
| 275 |
% Must clear indent level since we've cleared all tabs (note that |
| 276 |
% we intentionally leave indent level alone if there is a |
| 277 |
% \defaulttabwidth!) |
| 278 |
\global\ztabindentlevel=0\relax |
| 279 |
\fi\ignorespaces}% |
| 280 |
|
| 281 |
\def \ztabcmdevery #1{% |
| 282 |
% First clear all tabs |
| 283 |
\ztabcleartabboxes |
| 284 |
% Set new tab columns of the specified width into \ztabsbox |
| 285 |
\ztabsettabs{#1}% |
| 286 |
% Re-init the boxes used by \ztabmaketabbedline |
| 287 |
\ztabinittabboxes{\true}% Flag indicates this is a re-init |
| 288 |
\ignorespaces} |
| 289 |
|
| 290 |
|
| 291 |
% Implementation of the above commands |
| 292 |
|
| 293 |
|
| 294 |
\def \ztabinittabboxes #1{% Init the tab boxes {boolean: re-init} |
| 295 |
% First copy \ztabsbox into \ztabstbdbox and clear \ztabsdonebox |
| 296 |
\global\setbox\ztabstbdbox\copy\ztabsbox |
| 297 |
\global\setbox\ztabsdonebox\null |
| 298 |
% Put all of the indent boxes that might be built into an hbox |
| 299 |
% which we will emit later, but just before processing cells |
| 300 |
\global\setbox\ztabsindentbox\hbox% |
| 301 |
\bgroup% |
| 302 |
% Initialize counter for loop |
| 303 |
\ztabindentcounter=0\relax |
| 304 |
% Iterate \ztabindentlevel times, moving tabboxes from \ztabstbdbox to |
| 305 |
% \ztabsdone, maybe emitting hboxes per indent |
| 306 |
\if \lssp{\ztabindentcounter}{\ztabindentlevel}% |
| 307 |
\loop |
| 308 |
\increment \ztabindentcounter\relax% increment loop counter |
| 309 |
% Pull \lastbox off of \ztabstbdbox |
| 310 |
\global\setbox\ztabstbdbox\hbox{% |
| 311 |
\unhbox\ztabstbdbox |
| 312 |
\global\setbox\zboxb\lastbox}% |
| 313 |
\ifvoid\zboxb |
| 314 |
% This is a problem. Not allowed to indent past set tabs. |
| 315 |
\zzerror{Attempt to tab indent (with \string@+, [\the\ztabindentlevel]) past set tabs}% |
| 316 |
\else |
| 317 |
% Nothing wrong with the box: push it on \ztabsdonebox |
| 318 |
% and maybe emit it |
| 319 |
\global\setbox\ztabsdonebox\hbox{\copy\zboxb\unhbox\ztabsdonebox}% |
| 320 |
\if \notp{#1}% Not re-initializing |
| 321 |
\box\zboxb |
| 322 |
\fi |
| 323 |
\fi |
| 324 |
% Loop test |
| 325 |
\if \lssp{\ztabindentcounter}{\ztabindentlevel}\repeat |
| 326 |
\fi |
| 327 |
% End hbox |
| 328 |
\egroup} |
| 329 |
|
| 330 |
\def \ztabcleartabboxes {% Clear the tab boxes and indent level |
| 331 |
\setbox\ztabsbox\null |
| 332 |
\global\setbox\ztabstbdbox\null |
| 333 |
\global\setbox\ztabsdonebox\null} |
| 334 |
|
| 335 |
\def \ztabsettabs #1{% Deposit tab stops of a specified width in \ztabsbox |
| 336 |
\ztabcolwidth=#1\relax |
| 337 |
\ztabtabpos=0pt\relax |
| 338 |
% Loop while \ztabtabpos is less than \hsize, setting another tab |
| 339 |
\loop |
| 340 |
\ztabsetanother |
| 341 |
\if \dimlssp{\ztabtabpos}{\hsize}\repeat} |
| 342 |
|
| 343 |
\def \ztabsetanother {% Helper for \ztabsettabs, immediately preceding |
| 344 |
% Advance the counter |
| 345 |
\advance \ztabtabpos by \ztabcolwidth |
| 346 |
% Set another tab by "pushing" another hbox into the \ztabsbox hbox |
| 347 |
% followed by its old set of hboxes |
| 348 |
\setbox\ztabsbox\hbox{\hbox to\ztabcolwidth{}\unhbox\ztabsbox}} |
| 349 |
|
| 350 |
\def \ztabmaketabbedline {% Build a line of tabbed text |
| 351 |
% Start outermost group that redefines \nl |
| 352 |
\begingroup |
| 353 |
% Inittab boxes (this also builds \ztabsindentbox) |
| 354 |
\ztabinittabboxes{\false}% Flag indicates NOT a re-init |
| 355 |
% \nl is a synonym for modified \par |
| 356 |
\let\nl=\par |
| 357 |
% \zboxa will contain the entire tabbed line in a vbox. |
| 358 |
% (It is unvboxed in \nl and may be discarded if a @D is encountered.) |
| 359 |
\setbox\zboxa\vbox% |
| 360 |
% start outer group closed by \nl that holds state of \ztabatnlp |
| 361 |
\bgroup% |
| 362 |
% don't want to indent a tabbed line |
| 363 |
\noindent |
| 364 |
% Init conditionals |
| 365 |
\ztabatnlfalse |
| 366 |
\ztabsettingfalse |
| 367 |
\ztabtabbingfalse |
| 368 |
% start inner group closed by \nl that surrounds set of tabboxes |
| 369 |
% and uses \zboxc as an hbox for the current cell. |
| 370 |
\bgroup% |
| 371 |
% emit indentation box |
| 372 |
\box\ztabsindentbox |
| 373 |
% start the first cell |
| 374 |
\ztabbegintabcell} |
| 375 |
% material for a cell will follow here and be ended by |
| 376 |
% either a @ command or \nl, all of which will deposit |
| 377 |
% \ztabendtabcell. The @ commands will begin another tab cell and |
| 378 |
% \nl will also finish all of the groups started by |
| 379 |
% \ztabmaketabbedline and put out the line. |
| 380 |
|
| 381 |
\def \ztabbegintabcell {% |
| 382 |
% \zboxc contains an hbox as the current cell of tabbed material. |
| 383 |
% (It is deposited at the end of \ztabendtabcell.) |
| 384 |
\setbox\zboxc\hbox% |
| 385 |
\bgroup% opens group closed in \ztabendtabcell |
| 386 |
\ignorespaces} |
| 387 |
|
| 388 |
\def \ztabendtabcell {% |
| 389 |
\if \ztabatnlp |
| 390 |
% Processing last cell in this row. Close group opened in |
| 391 |
% \ztabbegintabcell w/o bothering to re-set tabboxes. |
| 392 |
\egroup |
| 393 |
\else |
| 394 |
% Close this cell's group (opened in \ztabbegintabcell) with \hss, |
| 395 |
% since this is not the last cell. |
| 396 |
\hss\egroup |
| 397 |
% "Pop" current tabbox from \ztabstbdbox, measure it, deposit tabbed |
| 398 |
% material into properly sized box and then "push" tabbox onto \ztabsdonebox |
| 399 |
% "Pop" from the end of \ztabstbdbox using \lastbox into \zboxb |
| 400 |
\global\setbox\ztabstbdbox\hbox{% |
| 401 |
\unhbox\ztabstbdbox |
| 402 |
\global\setbox\zboxb\lastbox}% |
| 403 |
% Process the current tabbox |
| 404 |
\ifvoid\zboxb |
| 405 |
\if \ztabtabbingp |
| 406 |
\zzerror{Attempt to tab (with \string@>) past set tabs}% |
| 407 |
\else |
| 408 |
% The current tabbox is void, so we set it to a box that is the |
| 409 |
% natural width of \zboxc (which contains the cell material). |
| 410 |
\global\setbox\zboxb\hbox to\wd\zboxc{}% |
| 411 |
\fi |
| 412 |
\else |
| 413 |
\if \ztabsettingp |
| 414 |
% Re-set previously stored tabbox to natural width of the cell (\zboxc) |
| 415 |
\global\setbox\zboxb\hbox to\wd\zboxc{}% |
| 416 |
\fi |
| 417 |
% Re-deposit the cell material into \zboxc using the width of the |
| 418 |
% current tabbox. |
| 419 |
\setbox\zboxc\hbox to\wd\zboxb{\unhbox\zboxc}% |
| 420 |
\fi |
| 421 |
% "Push" the current tabbox measure onto the \ztabsdonebox set of boxes. |
| 422 |
% (Note that this might have come from \ztabstbdbox or been measured from |
| 423 |
% \zboxc if there were no more tabboxes, so this is where an "on-the-fly" |
| 424 |
% tab is added to \ztabsdone, which will later be copied back into |
| 425 |
% \ztabsbox for the next line.) |
| 426 |
\global\setbox\ztabsdonebox\hbox{\box\zboxb\unhbox\ztabsdonebox}% |
| 427 |
\fi |
| 428 |
% Clear conditional variables |
| 429 |
\ztabsettingfalse |
| 430 |
\ztabtabbingfalse |
| 431 |
% emit box for this cell |
| 432 |
\box\zboxc} |
| 433 |
|
| 434 |
\def \ztabadjusttabbing #1{% {vertical-mode material} |
| 435 |
% Close and discard currently open tabbed line (empty, but started |
| 436 |
% by end of previous line). |
| 437 |
\ztabcmddiscard |
| 438 |
\ztabparfinishpreviousline |
| 439 |
% Insert vertical material |
| 440 |
#1\relax |
| 441 |
% If in verbatimlines must set this line to be discarded by |
| 442 |
% the newline which ends the \adjusttabbing{...} line, which will also |
| 443 |
% start the next line. |
| 444 |
\if \verbatimlines |
| 445 |
\ztabdiscardtrue |
| 446 |
\fi |
| 447 |
% Start next tabbed line |
| 448 |
\ztabparstartnextline} |
| 449 |
|
| 450 |
% Builtin Text Blocks |
| 451 |
% ------- ---- ------ |
| 452 |
|
| 453 |
% The following text block formats text in a completely normal fashion. |
| 454 |
% It can be used with \with to make small changes to the text format. |
| 455 |
|
| 456 |
\def \textnormalidesign {% |
| 457 |
\calculate \aboveskip = {\enclosingbaselineskip,+,\enclosingparskip}% |
| 458 |
\belowskip = \aboveskip |
| 459 |
\bodyfont = {}% |
| 460 |
\leftindent = \enclosingleftss |
| 461 |
\parindent = \enclosingparindent |
| 462 |
\parrag = \enclosingparrag |
| 463 |
\parskip = \enclosingparskip |
| 464 |
\rightindent = \enclosingrightss |
| 465 |
\setflag \verbatimlines = \false |
| 466 |
\width = \naturalwidth} |
| 467 |
|
| 468 |
\def \textnormaliidesign {% |
| 469 |
\textnormalidesign} |
| 470 |
\def \textnormaliiidesign {% |
| 471 |
\textnormalidesign} |
| 472 |
\def \textnormalivdesign {% |
| 473 |
\textnormalidesign} |
| 474 |
|
| 475 |
\def \setflushingleft {% |
| 476 |
\leftindent = 0pt |
| 477 |
\parfillskip = \normalparfillskip |
| 478 |
\parindent = 0pt |
| 479 |
\rightindent = 0pt |
| 480 |
\width = \naturalwidth} |
| 481 |
|
| 482 |
|
| 483 |
% This text block centers text relative to the current left and right |
| 484 |
% indentation. |
| 485 |
|
| 486 |
\def \textcenteridesign {% |
| 487 |
\textnormalidesign |
| 488 |
\setcentering} |
| 489 |
|
| 490 |
\def \textcenteriidesign {% |
| 491 |
\textcenteridesign} |
| 492 |
\def \textcenteriiidesign {% |
| 493 |
\textcenteridesign} |
| 494 |
\def \textcenterivdesign {% |
| 495 |
\textcenteridesign} |
| 496 |
|
| 497 |
\def \setcentering {% |
| 498 |
\leftindent = \centerindent |
| 499 |
\parfillskip = 0pt |
| 500 |
\parindent = 0pt |
| 501 |
\rightindent = \centerindent |
| 502 |
\width = \naturalwidth} |
| 503 |
|
| 504 |
|
| 505 |
% This text block positions text flush right. |
| 506 |
|
| 507 |
\def \textflushrightidesign {% |
| 508 |
\textnormalidesign |
| 509 |
\setflushingright} |
| 510 |
|
| 511 |
\def \textflushrightiidesign {% |
| 512 |
\textflushrightidesign} |
| 513 |
\def \textflushrightiiidesign {% |
| 514 |
\textflushrightidesign} |
| 515 |
\def \textflushrightivdesign {% |
| 516 |
\textflushrightidesign} |
| 517 |
|
| 518 |
\def \setflushingright {% |
| 519 |
\leftindent = \centerindent |
| 520 |
\parfillskip = 0pt |
| 521 |
\parindent = 0pt |
| 522 |
\rightindent = 0pt |
| 523 |
\width = \naturalwidth} |
| 524 |
|
| 525 |
% This text block squares off the last line of paragraphs. |
| 526 |
|
| 527 |
\def \textflushendidesign {% |
| 528 |
\textnormalidesign |
| 529 |
\parfillskip = 0pt} |
| 530 |
|
| 531 |
\def \textflushendiidesign {% |
| 532 |
\textflushendidesign} |
| 533 |
\def \textflushendiiidesign {% |
| 534 |
\textflushendidesign} |
| 535 |
\def \textflushendivdesign {% |
| 536 |
\textflushendidesign} |
| 537 |
|
| 538 |
\def \flushendpar {% |
| 539 |
\zskipa = \parfillskip |
| 540 |
\parfillskip = 0pt |
| 541 |
\par |
| 542 |
\parfillskip = \zskipa} |
| 543 |
|
| 544 |
% This text block sets text in the full type width. |
| 545 |
|
| 546 |
\def \texttypeareaidesign {% |
| 547 |
\textnormalidesign |
| 548 |
\leftindent = -\oddlefttextmargin |
| 549 |
\width = \typeareawidth} |
| 550 |
|
| 551 |
\def \texttypeareaiidesign {% |
| 552 |
\texttypeareaidesign} |
| 553 |
|
| 554 |
% This command centers a single line or sets multiple lines in block format. |
| 555 |
|
| 556 |
\def \centerorblockpar #1#2{% {width}{text} |
| 557 |
\measuretextwidth{\tdimena}{#2}% |
| 558 |
\if \dimlssp{\tdimena}{#1}% |
| 559 |
\centerline{#2}% |
| 560 |
\else |
| 561 |
\noindent #2\par |
| 562 |
\fi} |
| 563 |
|
| 564 |
% Code Block |
| 565 |
% ---- ----- |
| 566 |
|
| 567 |
|
| 568 |
\defineblock{\code}{\endcode}{\false}{} |
| 569 |
|
| 570 |
%~block code Type |
| 571 |
% \abovepenalty = integer % Penalty above code. |
| 572 |
% \aboveskip = glue % Space b/b above code. |
| 573 |
% \setflag \allowbreaks = boolean % Page breaks allowed? |
| 574 |
% \setflag \allowatsigncommands = boolean % Allow at-sign commands. |
| 575 |
% \setflag \allowcallouttag = boolean % Allow \tag for callout numbers. |
| 576 |
% \setflag \allowTeXcommands = boolean % Allow commands with \ { } |
| 577 |
% \setflag \allowTeXmath = boolean % Allow math with $ _ ^ |
| 578 |
% \setflag \autocallout = boolean % Automatically number lines? |
| 579 |
% \def \beginformat {...} % Beginning of code formatter. |
| 580 |
% \belowpenalty = integer % Penalty below code. |
| 581 |
% \belowskip = glue % Space b/b below code. |
| 582 |
% \bodyfont = {...} % Font for text. |
| 583 |
% \def \calloutformat ##1{...} % Callout formatter. |
| 584 |
% \calloutnumber = integer % Number of first callout. |
| 585 |
% \def \callouttext {...} % Callout text or \arg. |
| 586 |
% \codegapskip = glue % Standard code gap (see \codegap). |
| 587 |
% \def \endformat {...} % End of code formatter. |
| 588 |
% \hfuzz = dimen % Amount text can exceed \hsize. |
| 589 |
% \indentcolumns = integer % Standard indentation amount. |
| 590 |
% \leftindent = glue % Left indentation. |
| 591 |
% \metafont = {font} % Font for metasyntactic names. |
| 592 |
% \rightindent = glue % Right indentation. |
| 593 |
% \textcolor = {...} % Color of text. |
| 594 |
% \setflag \verbatimchars = flag % Take all characters verbatim? |
| 595 |
% \setflag \verbatimspaces = flag % Take all spaces verbatim? |
| 596 |
% \width = dimen % Width of code. |
| 597 |
%~end |
| 598 |
|
| 599 |
\defineskip{\codegapskip}{0pt} |
| 600 |
\definecount{\indentcolumns}{0} |
| 601 |
\definetoks{\metafont} |
| 602 |
|
| 603 |
\definecount{\codelinenumber}{0} |
| 604 |
|
| 605 |
\definecount{\zcodehyph}{0} % To remember hyphen character. |
| 606 |
|
| 607 |
\def \code #1{% {type} |
| 608 |
\blockcantbein{\code}{\code}% |
| 609 |
\beginblockscope{code}% |
| 610 |
\global\increment \codedepth |
| 611 |
\abovepenalty = \breakgood %~default hard |
| 612 |
\setflag \allowatsigncommands = \false %~default soft |
| 613 |
\setflag \allowcallouttag = \false %~default soft |
| 614 |
\setflag \allowTeXcommands = \true %~default soft |
| 615 |
\setflag \allowTeXmath = \false %~default soft |
| 616 |
\setflag \autocallout = \false %~default soft |
| 617 |
\def \beginformat {}% %~default soft |
| 618 |
\belowpenalty = \breakbetter %~default hard |
| 619 |
\calloutnumber = 1 %~default with |
| 620 |
\def \callouttext {\number\calloutnumber}% %~default soft |
| 621 |
\codegapskip = \mindimen %~default soft |
| 622 |
\def \endformat {}% %~default soft |
| 623 |
\indentcolumns = 3 %~default soft |
| 624 |
\textcolor = {}% %~default soft |
| 625 |
\setflag \verbatimchars = \true %~default soft |
| 626 |
\setflag \verbatimspaces = \true %~default soft |
| 627 |
\codelinenumber = 1\relax |
| 628 |
\processdesign{\code}{#1}% |
| 629 |
\global\increment \codenumber |
| 630 |
\codeformat |
| 631 |
\let \par = \zcodepar |
| 632 |
\obeylines |
| 633 |
\if \verbatimspaces \obeyspaces \fi |
| 634 |
\let \zrealincl = \include |
| 635 |
\let \include = \zcodeincl |
| 636 |
\let \zrealfn = \footnote |
| 637 |
\let \footnote = \zcodefn |
| 638 |
\def \zarg {\arg}% |
| 639 |
\if \tokeqlp{\callouttext}{\zarg}% |
| 640 |
\def \!{\zcodecoformat}% |
| 641 |
\else |
| 642 |
\def \!{\zcodecoformat{\callouttext}}% |
| 643 |
\fi |
| 644 |
\settaginfo{}{}% % No tag information so far. |
| 645 |
\if \notp{\emptytoksp{\textcolor}}\color{\the\textcolor}\fi |
| 646 |
\begingroup % So we can undo the following things. |
| 647 |
\if \autocallout \everyparagraph = {\!}\fi |
| 648 |
\if \verbatimchars |
| 649 |
\uncatcode{\allowTeXcommands}{\allowatsigncommands}{\allowTeXmath} |
| 650 |
\fi |
| 651 |
\zcodeflushline} |
| 652 |
|
| 653 |
{\catcode`\^^M = \catactive |
| 654 |
\gdef \zcodeflushline #1^^M{}% |
| 655 |
|
| 656 |
\gdef \endcode^^M{% |
| 657 |
%%% \columnbreak{\breakallowed}% % Allow break after last line. |
| 658 |
\endgroup % Undo the \uncatcode, |
| 659 |
\if \notp{\emptytoksp{\textcolor}}\endcolor \fi% |
| 660 |
\futurelet\nexttoken \zendcode}% % and grab onto the next character. |
| 661 |
} % \catcode |
| 662 |
|
| 663 |
\def \zendcode {% |
| 664 |
\hyphenchar\font = \zcodehyph |
| 665 |
\setlist \zcodeadjlist = {}% |
| 666 |
\endformat |
| 667 |
\forcenextpenalty |
| 668 |
\bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}% |
| 669 |
\global\decrement \codedepth |
| 670 |
\endblockscope{code}% |
| 671 |
\parnext} |
| 672 |
|
| 673 |
\def \codeformat {% |
| 674 |
\endgraf |
| 675 |
\alterindentation{\leftindent}{\rightindent}% |
| 676 |
\settextwidth{\width}% |
| 677 |
\setparrag{0pt}% |
| 678 |
\the\bodyfont |
| 679 |
\zcodehyph = \hyphenchar\font |
| 680 |
\hyphenchar\font = -1 |
| 681 |
\parskip = 0pt \parindent = 0pt |
| 682 |
\bbskipabove{\abovepenalty}{\aboveskip} |
| 683 |
\beginformat} |
| 684 |
|
| 685 |
\def \zcodepar {% |
| 686 |
\increment \codelinenumber |
| 687 |
\if \hmodep |
| 688 |
\endgraf |
| 689 |
\if \notp{\allowbreaks}\nobreak \relax \fi |
| 690 |
\zchkcodeadj |
| 691 |
\else |
| 692 |
\if \notp{\allowbreaks}\nobreak \relax \fi |
| 693 |
\zchkcodeadj |
| 694 |
\vskip \baselineskip |
| 695 |
\fi} |
| 696 |
|
| 697 |
% This macro allows the compositor to noninvasively adjust pages between |
| 698 |
% lines of code. |
| 699 |
|
| 700 |
\setlist \zcodeadjlist = {} |
| 701 |
|
| 702 |
\long\def \codeadjustment #1#2{% {line-number}{commands} |
| 703 |
\append{{#1}{#2}}{\zcodeadjlist}} |
| 704 |
|
| 705 |
\long\def \zchkcodeadj {% |
| 706 |
\maplist{\zchkcodeadjb##1}{\zcodeadjlist}} |
| 707 |
|
| 708 |
\long\def \zchkcodeadjb #1#2{% {line-number}{commands} |
| 709 |
\if \eqlp{#1}{\codelinenumber}% |
| 710 |
#2\relax |
| 711 |
\fi} |
| 712 |
|
| 713 |
\def \zcodecoformat #1{% {text} |
| 714 |
\ensurepar |
| 715 |
{\ztoksa = {}% |
| 716 |
\zcodecocln #1\zmark |
| 717 |
\calloutformat{\the\ztoksa}}% |
| 718 |
\if \allowcallouttag \settaginfo{#1}{???}\fi |
| 719 |
\global\increment \calloutnumber} |
| 720 |
|
| 721 |
\def \zcodecocln #1#2\zmark{% |
| 722 |
\ifx #1\ \else \ztoksa = \expandafter{\the\ztoksa#1}\fi |
| 723 |
\if \notp{\emptyargp{#2}}\zcodecocln #2\zmark \fi} |
| 724 |
|
| 725 |
% Code Tools |
| 726 |
% ---- ----- |
| 727 |
|
| 728 |
|
| 729 |
%~ This command is used to place a math expression in a |
| 730 |
%~ code block that doesn't allow dollar signs. |
| 731 |
|
| 732 |
\def \codemath {% $math$ %^code |
| 733 |
$% |
| 734 |
\catcodemath |
| 735 |
\let \znext = } % Discard opening $. |
| 736 |
|
| 737 |
%~ This command produces a vertical ellipsis in code, |
| 738 |
%~ with optional text explaining the omission. |
| 739 |
|
| 740 |
\def \codeellipsis #1{% {text} %^code |
| 741 |
\ensurepar |
| 742 |
{\lower .85\baselineskip \hbox{% |
| 743 |
\vbox{\baselineskip = .5\baselineskip \lineskiplimit = 0pt |
| 744 |
\kern \baselineskip \hbox{.}\hbox{.}\hbox{.}\kern \baselineskip}}% |
| 745 |
\unbreakable\quad {\the\metafont #1}}}% |
| 746 |
|
| 747 |
{\catcode`\^^M = \catactive |
| 748 |
|
| 749 |
% The \include macro is redefined to use this version, which eats |
| 750 |
% the newline at the end of the line. |
| 751 |
|
| 752 |
\gdef \zcodeincl #1^^M{\zrealincl{#1}}% |
| 753 |
|
| 754 |
% The \footnote macro is redefined so that it turns off \obeylines. |
| 755 |
|
| 756 |
\gdef \zcodefn {% |
| 757 |
\bgroup% |
| 758 |
\let ^^M = \space% |
| 759 |
\zcodefnb}% |
| 760 |
|
| 761 |
\gdef \zcodefnb #1{% |
| 762 |
\zrealfn{#1}% |
| 763 |
\egroup}% |
| 764 |
|
| 765 |
%~ This command allows a vertical adjustment between two lines |
| 766 |
%~ of code. A typical use would be |
| 767 |
%~ \adjustcode{\fullpagebreak} |
| 768 |
|
| 769 |
\gdef \adjustcode #1#2^^M{#1}% {command} %^code |
| 770 |
|
| 771 |
%~ Blank lines in code should be produced with this command. |
| 772 |
%~ A regular blank line produces too much space. |
| 773 |
|
| 774 |
\gdef \codegap #1^^M{% %^code |
| 775 |
\if \dimnegp{\codegapskip}% |
| 776 |
\vspace{\baselineskip}% |
| 777 |
\else% |
| 778 |
\vspace{\codegapskip}% |
| 779 |
\fi}% |
| 780 |
|
| 781 |
} % \catcode |
| 782 |
|
| 783 |
% Code Fragment |
| 784 |
% ---- -------- |
| 785 |
|
| 786 |
|
| 787 |
%~ A "code fragment" is a short sequence of program code in the running text. |
| 788 |
%~ Most books use |\mono|, which is defined in terms of this command. |
| 789 |
|
| 790 |
\def \codefragment #1#2#3#4{% {prefix}{suffix}{font}{text} |
| 791 |
{#1% |
| 792 |
\measurespacewidth{\tdimena}% |
| 793 |
#3% |
| 794 |
\if \monoencodingp \spaceskip = 1.2\tdimena \fi |
| 795 |
\relax #4% |
| 796 |
#2}} |
| 797 |
|
| 798 |
% Multicolumn Block |
| 799 |
% ----------- ----- |
| 800 |
|
| 801 |
|
| 802 |
\defineblock{\multicolumn}{\endmulticolumn}{\false}{} |
| 803 |
|
| 804 |
%~block multicolumn Type |
| 805 |
% \abovepenalty = integer % Penalty above block. |
| 806 |
% \aboveskip = glue % Visual space above block. |
| 807 |
% \belowpenalty = integer % Penalty below block. |
| 808 |
% \belowskip = glue % Visual space below block. |
| 809 |
% \brokenpenalty = penalty % For hyphenation at bottom of column. |
| 810 |
% \columngutter = dimen % Width of column gutter. |
| 811 |
% \columnrulecolor = {color} % Color of rule separating columns. |
| 812 |
% \columnrulewidth = dimen % Width of rule. |
| 813 |
% \columns = integer % Number of columns. |
| 814 |
% \setflag \flushbottom = flag % Should bottoms be flush? |
| 815 |
% \leftindent = glue % Indentation for left edge. |
| 816 |
% \margins = {left,right,top,bottom} % Four margins. |
| 817 |
% \parrag = dimen % Paragraph raggedness. |
| 818 |
% \setflag \preservelistdepth = flag % Preserve list depth? |
| 819 |
% \siderulecolor = {color} % Color of rules on sides. |
| 820 |
% \siderulewidth = dimen % Width of rules. |
| 821 |
% \vshift = dimen % Vertical shift for entire element. |
| 822 |
% \width = dimen % Width of each column. |
| 823 |
%~end |
| 824 |
|
| 825 |
\definetoks{\columnrulecolor} |
| 826 |
\definedimen{\columnrulewidth}{0pt} |
| 827 |
\definecount{\columns}{0} |
| 828 |
\definetoks{\margins} |
| 829 |
\definetoks{\siderulecolor} |
| 830 |
\definedimen{\siderulewidth}{0pt} |
| 831 |
|
| 832 |
\definebox{\zmctext} |
| 833 |
\definecount{\zmccolumn}{0} |
| 834 |
\definecount{\zentrylistdepth}{0} |
| 835 |
\definebox{\zmccoli} |
| 836 |
\definebox{\zmccolii} |
| 837 |
\definebox{\zmccoliii} |
| 838 |
\definebox{\zmccoliv} |
| 839 |
\definebox{\zmccolv} |
| 840 |
\definebox{\zmccolvi} |
| 841 |
\definebox{\zmccolvii} |
| 842 |
\definebox{\zmccolviii} |
| 843 |
\definedimen{\zmcmaxht}{0pt} |
| 844 |
\definebox{\zmcbox} |
| 845 |
|
| 846 |
|
| 847 |
\def \multicolumn #1{% {type} |
| 848 |
\beginblockscope{multicolumn}% |
| 849 |
\global\increment \multicolumndepth |
| 850 |
\abovepenalty = \breakgood %~default hard |
| 851 |
\belowpenalty = \breakgood %~default hard |
| 852 |
\brokenpenalty = \breaknever %~default soft |
| 853 |
\setflag \preservelistdepth = \false %~default soft |
| 854 |
\vshift = 0pt %~default soft |
| 855 |
\processdesign{\multicolumn}{#1}% |
| 856 |
\global\increment \multicolumnnumber |
| 857 |
\expandafter\zmcparse \the\margins\zmark |
| 858 |
\setbox \zmctext = \vtop\bgroup |
| 859 |
\zentrylistdepth = \listdepth |
| 860 |
\zpushvcontext |
| 861 |
\if \preservelistdepth \global\listdepth = \zentrylistdepth \fi |
| 862 |
\settextwidth{\width}% |
| 863 |
\setparrag{\parrag}} |
| 864 |
|
| 865 |
\def \endmulticolumn {% |
| 866 |
\endgraf |
| 867 |
\zpopvcontext |
| 868 |
\egroup % \vtop |
| 869 |
\zbuildmc |
| 870 |
\global\decrement \multicolumndepth |
| 871 |
\endblockscope{multicolumn}} |
| 872 |
|
| 873 |
\def \zbuildmc {% |
| 874 |
\splitmaxdepth = \dp\strutbox |
| 875 |
\vbadness = 10000 % Do we want this? |
| 876 |
\setbox \zmctext = \vbox{% |
| 877 |
\vskip \splittopskip |
| 878 |
\vskip -\ht\zmctext |
| 879 |
\unvbox \zmctext |
| 880 |
\unskip \unpenalty \unskip}% |
| 881 |
\zbuildmca |
| 882 |
\zbuildmcb |
| 883 |
\bbskipabove{\abovepenalty}{\aboveskip}% |
| 884 |
\hfuzz=999pc |
| 885 |
\hindent{\leftindent} \lower \vshift \box\zmcbox \par |
| 886 |
\prevdepth = 0pt % Nothing better to do. |
| 887 |
\bbskipbelowblock{\belowpenalty}{\belowskip}} |
| 888 |
|
| 889 |
\def \zbuildmca {% |
| 890 |
\zmccolumn = \columns |
| 891 |
\zmcmaxht = 0pt |
| 892 |
\loop |
| 893 |
\calculate \tdimena = |
| 894 |
{\ht\zmctext,-,\splittopskip,/,\zmccolumn,+,\splittopskip}% |
| 895 |
\setbox \name{\zmccol\romannumeral\zmccolumn} = |
| 896 |
\if \onep{\zmccolumn}\box\zmctext \else |
| 897 |
\vsplit \zmctext to \tdimena \fi |
| 898 |
\tdimena = \ht\name{\zmccol\romannumeral\zmccolumn}% |
| 899 |
\if \dimgtrp{\tdimena}{\zmcmaxht}\zmcmaxht = \tdimena \fi |
| 900 |
\decrement \zmccolumn |
| 901 |
\if \posp{\zmccolumn}\repeat} |
| 902 |
|
| 903 |
\def \zbuildmcb {% |
| 904 |
\setbox \zmcbox = \hbox{% |
| 905 |
\vrule width \siderulewidth |
| 906 |
\hskip -\siderulewidth |
| 907 |
\hskip \zmcleft |
| 908 |
\zmccolumn = \columns |
| 909 |
\loop |
| 910 |
\tdimena = \dp\name{\zmccol\romannumeral\zmccolumn}% |
| 911 |
\setbox \zboxa = \vbox to \zmcmaxht {% |
| 912 |
\unvbox \name{\zmccol\romannumeral\zmccolumn}% |
| 913 |
\if \notp{\flushbottom}\vfil \fi |
| 914 |
\vskip -\tdimena |
| 915 |
\vskip \zmcbottom}% |
| 916 |
\calculate \tdimena = {\ht\zboxa,-,\splittopskip}% |
| 917 |
\lower \tdimena \hbox{\box\zboxa}% |
| 918 |
\if \gtrp{\zmccolumn}{1}% |
| 919 |
\hskip .5\columngutter |
| 920 |
\hskip -.5\columnrulewidth |
| 921 |
\vrule width \columnrulewidth |
| 922 |
\hskip -.5\columnrulewidth |
| 923 |
\hskip .5\columngutter |
| 924 |
\fi |
| 925 |
\decrement \zmccolumn |
| 926 |
\if \posp{\zmccolumn}\repeat |
| 927 |
\hskip \zmcright |
| 928 |
\hskip -\siderulewidth |
| 929 |
\vrule width \siderulewidth}} |
| 930 |
|
| 931 |
\def \zmcparse #1,#2,#3,#4\zmark{% |
| 932 |
\def \zmcleft {#1\relax}% |
| 933 |
\def \zmcright {#2\relax}% |
| 934 |
\splittopskip = #3\relax |
| 935 |
\def \zmcbottom {#4\relax}} |