| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 1993-2025 |
| 4 |
% |
| 5 |
% The LaTeX Project and any individual authors listed elsewhere |
| 6 |
% in this file. |
| 7 |
% |
| 8 |
% This file is part of the Standard LaTeX `Tools Bundle'. |
| 9 |
% ------------------------------------------------------- |
| 10 |
% |
| 11 |
% It may be distributed and/or modified under the |
| 12 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 13 |
% of this license or (at your option) any later version. |
| 14 |
% The latest version of this license is in |
| 15 |
% https://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 17 |
% version 2005/12/01 or later. |
| 18 |
% |
| 19 |
% The list of all files belonging to the LaTeX `Tools Bundle' is |
| 20 |
% given in the file `manifest.txt'. |
| 21 |
% |
| 22 |
% \fi |
| 23 |
% \iffalse |
| 24 |
%% File: tabularx.dtx Copyright (C) 1991-1999 2012 2014 2016 2017 David Carlisle |
| 25 |
% |
| 26 |
%<*dtx> |
| 27 |
\ProvidesFile{tabularx.dtx} |
| 28 |
%</dtx> |
| 29 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 30 |
%<package>\ProvidesPackage{tabularx} |
| 31 |
%<driver> \ProvidesFile{tabularx.drv} |
| 32 |
% \fi |
| 33 |
% \ProvidesFile{tabularx.dtx} |
| 34 |
[2023/12/11 v2.12a `tabularx' package (DPC)] |
| 35 |
% \iffalse |
| 36 |
%<*driver> |
| 37 |
\documentclass{ltxdoc} |
| 38 |
\usepackage[infoshow]{tabularx} |
| 39 |
\begin{document} |
| 40 |
\DocInput{tabularx.dtx} |
| 41 |
\end{document} |
| 42 |
%</driver> |
| 43 |
% \fi |
| 44 |
% |
| 45 |
% \changes{v1.00}{1992/01/30}{Initial version.} |
| 46 |
% \changes{v1.01}{1992/07/07}{Re-issue for the new doc and docstrip.} |
| 47 |
% \changes{v1.02}{1992/07/17}{Added some support for \cmd\verb} |
| 48 |
% \changes{v1.03}{1992/08/17} |
| 49 |
% {Added \cs{ifnum0}!=`\{\cs{fi}\} brackets after report by |
| 50 |
% Andreas Maassen} |
| 51 |
% \changes{v1.04}{1992/09/02} |
| 52 |
% {fixed \cmd\verb, and support footnotes.} |
| 53 |
% \changes{v1.05}{1992/11/06} |
| 54 |
% {preserve all LaTeX counters} |
| 55 |
% \changes{v1.06}{1993/08/02} |
| 56 |
% {(Martin Schroeder) Support the optional [t] or [b] argument. |
| 57 |
% Also now works with delarray.sty.} |
| 58 |
% \changes{v1.07}{1993/08/27} |
| 59 |
% {Modifications to make this style compatible with calc.sty.} |
| 60 |
% \changes{v2.00}{1994/03/14} |
| 61 |
% {Update to LaTeX2e} |
| 62 |
% \changes{v2.01}{1994/05/22} |
| 63 |
% {New Tracing format.} |
| 64 |
% |
| 65 |
% |
| 66 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 67 |
% |
| 68 |
% |
| 69 |
% |
| 70 |
% \GetFileInfo{tabularx.dtx} |
| 71 |
% \title{The \textsf{tabularx} package\thanks{This file |
| 72 |
% has version number \fileversion, last |
| 73 |
% revised \filedate.}} |
| 74 |
% \author{David Carlisle} |
| 75 |
% \date{\filedate} |
| 76 |
% \MaintainedByLaTeXTeam{tools} |
| 77 |
% \maketitle |
| 78 |
% \DeleteShortVerb{\|} |
| 79 |
% \MakeShortVerb{\"} |
| 80 |
% |
| 81 |
% \begin{abstract} |
| 82 |
% A new environment, {\ttfamily tabularx}, is defined, which takes the |
| 83 |
% same arguments as {\ttfamily tabular*}, but modifies the widths of |
| 84 |
% certain columns, rather than the inter column space, to set a table |
| 85 |
% with the requested total width. The columns that may stretch are |
| 86 |
% marked with the new token {\ttfamily X} in the preamble argument. |
| 87 |
% |
| 88 |
% This package requires the {\ttfamily array} package. |
| 89 |
% \end{abstract} |
| 90 |
% |
| 91 |
% \section{Introduction} |
| 92 |
% This package implements a version of the {\ttfamily tabular} |
| 93 |
% environment in which the widths of certain columns are calculated so |
| 94 |
% that the table is a specified width. Requests for such an |
| 95 |
% environment seem to occur quite regularly in {\ttfamily |
| 96 |
% comp.text.tex}. |
| 97 |
% |
| 98 |
% \DescribeEnv{tabularx} |
| 99 |
% "\begin{tabularx}{"\meta{width}"}["\meta{pos}"]{"\meta{preamble}"}"\\ |
| 100 |
% The arguments of "tabularx" are essentially the same as those of |
| 101 |
% the standard "tabular*" environment. However rather than adding space |
| 102 |
% between the columns to achieve the desired width, it adjusts the |
| 103 |
% widths of some of the columns. The columns which are affected by the |
| 104 |
% {\ttfamily tabularx} environment should be denoted with the letter |
| 105 |
% {\ttfamily X} in the preamble argument. The {\ttfamily X} column |
| 106 |
% specification will be converted to "p{"\meta{some value}"}" once the |
| 107 |
% correct column width has been calculated. |
| 108 |
% |
| 109 |
% \section{Examples} |
| 110 |
% |
| 111 |
% The following table is set with |
| 112 |
% "\begin{tabularx}{250pt}{|c|X|c|X|} ...". |
| 113 |
% |
| 114 |
% \begin{center} |
| 115 |
% \begin{tabularx}{250pt}{|c|X|c|X|} |
| 116 |
% \hline |
| 117 |
% \multicolumn{2}{|c|}{Multicolumn entry!}& |
| 118 |
% THREE& |
| 119 |
% FOUR\\ |
| 120 |
% \hline |
| 121 |
% one& |
| 122 |
% \raggedright\arraybackslash The width of this column depends on the |
| 123 |
% width of the table.\footnote |
| 124 |
% {You can now use {\ttfamily \bslash footnote} inside {\ttfamily |
| 125 |
% tabularx}!}& |
| 126 |
% three& |
| 127 |
% \raggedright\arraybackslash Column four will act in the same way as |
| 128 |
% column two, with the same width.\\ |
| 129 |
% \hline |
| 130 |
% \end{tabularx} |
| 131 |
% \end{center} |
| 132 |
% If we change the first line to "\begin{tabularx}{300pt}{|c|X|c|X|}" we |
| 133 |
% get: |
| 134 |
% \begin{center} |
| 135 |
% \begin{tabularx}{300pt}{|c|X|c|X|} |
| 136 |
% \hline |
| 137 |
% \multicolumn{2}{|c|}{Multicolumn entry!}& |
| 138 |
% THREE& |
| 139 |
% FOUR\\ |
| 140 |
% \hline |
| 141 |
% one& |
| 142 |
% \raggedright\arraybackslash The width of this column depends on the |
| 143 |
% width of the table.& |
| 144 |
% three& |
| 145 |
% \raggedright\arraybackslash Column four will act in the same way as |
| 146 |
% column two, with the same width.\\ |
| 147 |
% \hline |
| 148 |
% \end{tabularx} |
| 149 |
% \end{center} |
| 150 |
% |
| 151 |
% \edef\mytt{\expandafter\noexpand\csname |
| 152 |
% mdseries\endcsname\noexpand\ttfamily} |
| 153 |
% \section{Differences between {\mytt tabularx} and {\mytt tabular*}} |
| 154 |
% These two environments take the same arguments, to produce a table of |
| 155 |
% a specified width. The main differences between them are: |
| 156 |
% \begin{itemize} |
| 157 |
% \item {\ttfamily tabularx} modifies the widths of the \emph{columns}, |
| 158 |
% whereas {\ttfamily tabular*} modifies the widths of the inter-column |
| 159 |
% \emph{spaces}. |
| 160 |
% \item {\ttfamily tabular} and {\ttfamily tabular*} environments may be |
| 161 |
% nested with no restriction, however if one {\ttfamily tabularx} |
| 162 |
% environment occurs inside another, then the inner one {\em must\/} be |
| 163 |
% enclosed by "{ }". |
| 164 |
% \item The body of the {\ttfamily tabularx} environment is in fact the |
| 165 |
% argument to a command, and so certain constructions which are not |
| 166 |
% allowed in command arguments (like "\verb") may not be used.\footnote |
| 167 |
% {Since Version 1.02, {\ttfamily\bslash verb} and {\ttfamily\bslash |
| 168 |
% verb*} may be used, but they may treat spaces incorrectly, and the |
| 169 |
% argument can not contain an unmatched {\ttfamily\char`\{} or |
| 170 |
% {\ttfamily\char`\}}, or a {\ttfamily\char`\%} character.} |
| 171 |
% \item {\ttfamily tabular*} uses a primitive capability of \TeX\ to |
| 172 |
% modify the inter column space of an alignment. {\ttfamily tabularx} |
| 173 |
% has to set the table several times as it searches for the best column |
| 174 |
% widths, and is therefore much slower. Also the fact that the body is |
| 175 |
% expanded several times may break certain \TeX\ constructs. |
| 176 |
% \end{itemize} |
| 177 |
% |
| 178 |
% \section{Customising the behaviour of {\mytt tabularx}} |
| 179 |
% |
| 180 |
% \subsection{Terminal output} |
| 181 |
% \DescribeMacro{\tracingtabularx} |
| 182 |
% If this declaration is made, say in the document preamble, then all |
| 183 |
% following {\ttfamily tabularx} environments will print information |
| 184 |
% about column widths as they repeatedly re-set the tables to find the |
| 185 |
% correct widths. |
| 186 |
% |
| 187 |
% As an alternative to using the "\tracingtabularx" declaration, either |
| 188 |
% of the options "infoshow" or "debugshow" may be given, either in the |
| 189 |
% "\usepackage" command that loads "tabularx", or as a global option |
| 190 |
% in the "\documentclass" command. |
| 191 |
% |
| 192 |
% \subsection{The environment used to typeset the {\mytt X} columns} |
| 193 |
% By default the {\ttfamily X} specification is turned into |
| 194 |
% "p{"\meta{some value}"}". Such narrow columns often |
| 195 |
% require a special format, this may be achieved using the ">" syntax |
| 196 |
% of {\ttfamily array.sty}. So for example you may give a specification |
| 197 |
% of ">{\small}X". Another format which is useful in narrow columns is |
| 198 |
% ragged right, however \LaTeX's "\raggedright" macro redefines |
| 199 |
% "\\" in a way which conflicts with its use in a tabular or array |
| 200 |
% environments. |
| 201 |
%\DescribeMacro{\arraybackslash} |
| 202 |
% For this reason this package introduces the command "\arraybackslash", |
| 203 |
% this may be used after a "\raggedright", "\raggedleft" or |
| 204 |
% "\centering" declaration. Thus a {\ttfamily tabularx} preamble may |
| 205 |
% specify\\ |
| 206 |
% ">{\raggedright\arraybackslash}X". |
| 207 |
% |
| 208 |
% \DescribeMacro{\newcolumntype} |
| 209 |
% These preamble specifications may of course be saved using the |
| 210 |
% command "\newcolumntype" defined in {\ttfamily array.sty}. Thus we |
| 211 |
% may say\\ |
| 212 |
% "\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}"\\ |
| 213 |
% and then use {\ttfamily Y} in the {\ttfamily tabularx} preamble |
| 214 |
% argument. |
| 215 |
% |
| 216 |
% \DescribeMacro{\tabularxcolumn} |
| 217 |
% The {\ttfamily X} columns are set using the {\ttfamily p} column which |
| 218 |
% corresponds to "\parbox[t]". You may want them set using, say, the |
| 219 |
% {\ttfamily m} column, which corresponds to "\parbox[c]". It is not |
| 220 |
% possible to change the column type using the ">" syntax, so another |
| 221 |
% system is provided. "\tabularxcolumn" should be defined to be a macro |
| 222 |
% with one argument, which expands to the {\ttfamily tabular} preamble |
| 223 |
% specification that you want to correspond to {\ttfamily X}. The |
| 224 |
% argument will be replaced by the calculated width of a column. |
| 225 |
% |
| 226 |
% The default is "\newcommand{\tabularxcolumn}[1]{p{#1}}". So we may |
| 227 |
% change this with a command such as:\\ |
| 228 |
% "\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}" |
| 229 |
% |
| 230 |
% \subsection{Column widths} |
| 231 |
% Normally all {\ttfamily X} columns in a single table are set to the |
| 232 |
% same width, however it is possible to make {\ttfamily tabularx} set |
| 233 |
% them to different widths. |
| 234 |
% A preamble argument of |
| 235 |
% "{>{\hsize=.5\hsize\linewidth=\hsize}X"\\ |
| 236 |
% " >{\hsize=1.5\hsize\linewidth=\hsize}X}"\\ |
| 237 |
% specifies two columns, the second will be three times as wide as the |
| 238 |
% first. However if you want to play games like this you should follow |
| 239 |
% the following two rules. |
| 240 |
% \begin{itemize} |
| 241 |
% \item Make sure that the sum of the widths of all the {\ttfamily X} |
| 242 |
% columns is unchanged. (In the above example, the new widths still add |
| 243 |
% up to twice the default width, the same as two standard {\ttfamily X} |
| 244 |
% columns.) |
| 245 |
% \item Do not use "\multicolumn" entries which cross any {\ttfamily X} |
| 246 |
% column. |
| 247 |
% \end{itemize} |
| 248 |
% As with most rules, these may be broken if you know what you are |
| 249 |
% doing. |
| 250 |
% |
| 251 |
% \subsection{If the algorithm fails\ldots} |
| 252 |
% It may be that the widths of the `normal' columns of the table |
| 253 |
% already total more than the requested total |
| 254 |
% width. \textsf{tabularx} refuses to set the |
| 255 |
% \texttt{X} columns to a negative width, so in this case you get a |
| 256 |
% warning ``X Columns too narrow (table too wide)''. |
| 257 |
% |
| 258 |
% The \texttt{X} columns will in this case be set to a width of 1em |
| 259 |
% and so the table itself will be wider than the requested total width |
| 260 |
% given in the argument to the environment. |
| 261 |
% This behaviour of the package can be customised slightly |
| 262 |
% as noted in the documentation of the code section. |
| 263 |
% |
| 264 |
% \section{Support for tagged PDF} |
| 265 |
% |
| 266 |
% With version 2.12a the package is made tagging aware, which means that |
| 267 |
% it will automatically produce tagged tables (necessary, for example, for |
| 268 |
% accessibility) if tagging is requested via \cs{DocumentMetadata}. |
| 269 |
% |
| 270 |
% More granular control, e.g., explicitly deciding which cells are |
| 271 |
% header cells, etc., is currently under development, but syntax for |
| 272 |
% this will not appear in this package. Instead it will become |
| 273 |
% available across all tabular-generating packages and then |
| 274 |
% automatically apply here as well. |
| 275 |
% |
| 276 |
% Enabling \LaTeX{} to automatically produce tagged PDF is a long-term |
| 277 |
% project and this is a tiny step in this puzzle. For more information |
| 278 |
% on the project and already available functionality, see |
| 279 |
% \url{https://latex-project.org/publications/indexbytopic/pdf} and |
| 280 |
% \url{https://github.com/latex3/tagging-project}. |
| 281 |
% |
| 282 |
% |
| 283 |
% \MaybeStop{} |
| 284 |
% |
| 285 |
% \section{The Macros} |
| 286 |
% |
| 287 |
% \begin{macrocode} |
| 288 |
%<*package> |
| 289 |
% \end{macrocode} |
| 290 |
% |
| 291 |
% We only need two changes for tagging support, but they require |
| 292 |
% that a recent \LaTeX{} kernel is used (which should be no problem |
| 293 |
% if \texttt{tools} is distributed in parallel with the kernel. |
| 294 |
% \changes{v2.12a}{2023/12/11}{Require newer LaTeX kernel} |
| 295 |
% \begin{macrocode} |
| 296 |
\NeedsTeXFormat{LaTeX2e}[2024/06/01] |
| 297 |
% \end{macrocode} |
| 298 |
% |
| 299 |
% \changes{v2.00}{1994/02/07} |
| 300 |
% {New Option Handling} |
| 301 |
% \begin{macrocode} |
| 302 |
\DeclareOption{infoshow}{\AtEndOfPackage\tracingtabularx} |
| 303 |
\DeclareOption{debugshow}{\AtEndOfPackage\tracingtabularx} |
| 304 |
\ProcessOptions |
| 305 |
% \end{macrocode} |
| 306 |
% |
| 307 |
% This requires {\ttfamily array.sty}. |
| 308 |
% \changes{v2.00}{1994/02/07} |
| 309 |
% {Use LaTeX2e's \cmd{\RequirePackage} to load array} |
| 310 |
% \begin{macrocode} |
| 311 |
\RequirePackage{array}[1994/02/03] |
| 312 |
% \end{macrocode} |
| 313 |
% |
| 314 |
% First some registers etc.\ that we need. |
| 315 |
% \begin{macrocode} |
| 316 |
\newdimen\TX@col@width |
| 317 |
\newdimen\TX@old@table |
| 318 |
\newdimen\TX@old@col |
| 319 |
\newdimen\TX@target |
| 320 |
\newdimen\TX@delta |
| 321 |
\newcount\TX@cols |
| 322 |
\newif\ifTX@ |
| 323 |
% \end{macrocode} |
| 324 |
% |
| 325 |
% Now a trick to get the body of an environment into a token register, |
| 326 |
% without doing any expansion. This does not do any real checking of |
| 327 |
% nested environments, so if you should need to nest one {\ttfamily |
| 328 |
% tabularx} inside another, the inner one must be surrounded by "{ }". |
| 329 |
% |
| 330 |
% \begin{macro}{\tabularx} |
| 331 |
% Prior to v1.06, this macro took two arguments, which were saved in |
| 332 |
% separate registers before the table body was saved by "\TX@get@body". |
| 333 |
% Unfortunately this disables the "[t]" optional argument. Now just save |
| 334 |
% the width specification separately, then clear the token register |
| 335 |
% "\toks@". |
| 336 |
% Finally call "\TX@get@body" to begin saving the body of the table. |
| 337 |
% The "{\ifnum0=`}\fi" was added at v1.03, to allow "tabularx" to appear |
| 338 |
% inside a "\halign".^^A |
| 339 |
% \setbox0=\hbox{\footnotesize"\iffalse{\fi\ifnum0=`}\fi"}^^A |
| 340 |
% \setbox2=\hbox{\footnotesize"\ifnum0=`{}\fi"}^^A |
| 341 |
% \footnote{This adds an extra level of grouping, |
| 342 |
% which is not really needed. Instead, I could use \box0\ here, and |
| 343 |
% \box2\ below, however the code here would then have to be moved after |
| 344 |
% the first line, because of the footnote to page 386 of the \TeX{}book, |
| 345 |
% and I do not think I should be writing code that is so obscure as to |
| 346 |
% be documented in a footnote in an appendix called ``Dirty Tricks''!} |
| 347 |
% |
| 348 |
% This mechanism of grabbing an environment body does have the |
| 349 |
% disadvantage (shared with the AMS alignment environments) that you |
| 350 |
% can not make extension environments by code such as |
| 351 |
%\begin{verbatim} |
| 352 |
%\newenvironment{foo}{\begin{tabularx}{XX}}{\end{tabularx}} |
| 353 |
%\end{verbatim} |
| 354 |
% as the code is looking for a literal string "\end{tabularx}" to stop |
| 355 |
% scanning. Since version 2.02, one may avoid this problem by using |
| 356 |
% "\tabularx" and "\endtabularx" directly in the definition: |
| 357 |
%\begin{verbatim} |
| 358 |
%\newenvironment{foo}{\tabularx{XX}}{\endtabularx} |
| 359 |
%\end{verbatim} |
| 360 |
% The scanner now looks for the end of the current environment ("foo" in |
| 361 |
% this example). There are some restrictions on this usage, the |
| 362 |
% principal one being that "\endtabularx" must not be inside any "{ }" pairs, |
| 363 |
% so that the code before "\endtabularx" may be extracted and added to the table body |
| 364 |
% (prior to version 2.09 "\endtabularx" had to be |
| 365 |
% the \emph{first} token of the `end code' of the environment). |
| 366 |
% \begin{macrocode} |
| 367 |
\def\tabularx#1{% |
| 368 |
% \end{macrocode} |
| 369 |
% \changes{v2.02}{1995/03/20} |
| 370 |
% {New local setting of \cs{TX@}} |
| 371 |
% \changes{v2.09}{1998/05/13} |
| 372 |
% {Use \cs{setlength}, so that calc extensions apply. tools/2793} |
| 373 |
% \changes{v2.11c}{2020/01/15}{Delete duplicated . at end of message} |
| 374 |
% Allow "\tabularx" "\endtabularx" (but not "\begin{tabularx}" |
| 375 |
% "\end{tabularx}") to be used in "\newenvironment" definitions. |
| 376 |
% \begin{macrocode} |
| 377 |
\edef\TX@{\@currenvir}% |
| 378 |
{\ifnum0=`}\fi |
| 379 |
% \end{macrocode} |
| 380 |
% "\relax" added at v1.05 so that non-expandable length tokens, like |
| 381 |
% "\textwidth" do not generate an extra space, and an overfull box. |
| 382 |
% "\relax" removed again at v2.09 in favour of "\setlength" so if you |
| 383 |
% use the calc package you can use a width of "(\textwidth-12pt)/2". |
| 384 |
% \begin{macrocode} |
| 385 |
\setlength\TX@target{#1}% |
| 386 |
\TX@typeout{Target width: #1 = \the\TX@target}% |
| 387 |
\toks@{}\TX@get@body} |
| 388 |
% \end{macrocode} |
| 389 |
% \end{macro} |
| 390 |
% |
| 391 |
|
| 392 |
% \begin{macro}{\endtabularx} |
| 393 |
% This does not do very much\ldots |
| 394 |
% \changes{v2.02}{1995/03/20} |
| 395 |
% {Macro added} |
| 396 |
% \begin{macrocode} |
| 397 |
\let\endtabularx\relax |
| 398 |
% \end{macrocode} |
| 399 |
% \end{macro} |
| 400 |
% |
| 401 |
% \begin{macro}{\TX@get@body} |
| 402 |
% Place all tokens as far as the first "\end" into a token register. |
| 403 |
% Then call "\TX@find@end" to see if we are at "\end{tabularx}". |
| 404 |
% \begin{macrocode} |
| 405 |
\long\def\TX@get@body#1\end |
| 406 |
{\toks@\expandafter{\the\toks@#1}\TX@find@end} |
| 407 |
% \end{macrocode} |
| 408 |
% \end{macro} |
| 409 |
% |
| 410 |
% \begin{macro}{\TX@find@end} |
| 411 |
% If we are at "\end{tabularx}", call "\TX@endtabularx", otherwise |
| 412 |
% add "\end{...}" to the register, and call "\TX@get@body" again. |
| 413 |
% \begin{macrocode} |
| 414 |
\def\TX@find@end#1{% |
| 415 |
\def\@tempa{#1}% |
| 416 |
\ifx\@tempa\TX@\expandafter\TX@endtabularx |
| 417 |
\else\toks@\expandafter |
| 418 |
{\the\toks@\end{#1}}\expandafter\TX@get@body\fi} |
| 419 |
% \end{macrocode} |
| 420 |
% \end{macro} |
| 421 |
% |
| 422 |
% \begin{macro}{\TX@find@endtabularxa} |
| 423 |
% \changes{v2.09}{2014/04/22}{macro added} |
| 424 |
% \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}} |
| 425 |
% \changes{v2.11}{2016/01/03}{Fix to previous change to guard against empty arg 2. (Ulrike Fischer)} |
| 426 |
% Split up the end code, and extract the part that lives in the table body. |
| 427 |
% \begin{macrocode} |
| 428 |
\long\def\TX@find@endtabularxa |
| 429 |
#1\endtabularx#2\endtabularx#3\TX@find@endtabularxa{% |
| 430 |
\ifx\TX@#2\relax\else |
| 431 |
\toks@\expandafter{\the\toks@#1}% |
| 432 |
\fi} |
| 433 |
% \end{macrocode} |
| 434 |
% \end{macro} |
| 435 |
% \begin{macro}{\TX@find@endtabularxb} |
| 436 |
% \changes{v2.09}{2014/04/22}{macro added} |
| 437 |
% \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}} |
| 438 |
% Split up the end code, and extract the part that lives outside the table body. |
| 439 |
% \begin{macrocode} |
| 440 |
\long\def\TX@find@endtabularxb |
| 441 |
#1\endtabularx#2\endtabularx#3\TX@find@endtabularxb{% |
| 442 |
\ifx\TX@#2% |
| 443 |
\expandafter\@firstoftwo |
| 444 |
\else |
| 445 |
\expandafter\@secondoftwo |
| 446 |
\fi |
| 447 |
{#1}{#2}} |
| 448 |
% \end{macrocode} |
| 449 |
% \end{macro} |
| 450 |
% |
| 451 |
% \begin{macro}{\TX@find@endtabularxbb} |
| 452 |
% \changes{v2.10}{2014/05/13}{macro added} |
| 453 |
% Helper to avoid needing 15 consecutive "expandafter" |
| 454 |
% \begin{macrocode} |
| 455 |
\def\TX@find@endtabularxbb{% |
| 456 |
\expandafter\expandafter\expandafter |
| 457 |
\TX@find@endtabularxb |
| 458 |
} |
| 459 |
% \end{macrocode} |
| 460 |
% \end{macro} |
| 461 |
% |
| 462 |
% \begin{macro}{\TX@} |
| 463 |
% The string {\ttfamily tabularx} as a macro for testing with "\ifx". |
| 464 |
% \begin{macrocode} |
| 465 |
\def\TX@{tabularx} |
| 466 |
% \end{macrocode} |
| 467 |
% \end{macro} |
| 468 |
% |
| 469 |
% Now that all the parts of the table specification are stored in |
| 470 |
% registers, we can begin the work of setting the table. |
| 471 |
% |
| 472 |
% The algorithm for finding the correct column widths is as follows. |
| 473 |
% Firstly set the table with each {\ttfamily X} column the width of the |
| 474 |
% final table. Assuming that there is at least one {\ttfamily X} column, |
| 475 |
% this will produce a table that is too wide. Divide the excess width by |
| 476 |
% the number of {\ttfamily X} columns, and reduce the column width by |
| 477 |
% this amount. Reset the table. If the table is not now the correct |
| 478 |
% width, a "\multicolumn" entry must be `hiding' one of the {\ttfamily |
| 479 |
% X} columns, and so there is one less {\ttfamily X} column affecting |
| 480 |
% the width of the table. So we reduce by 1 the number of X columns and |
| 481 |
% repeat the process. |
| 482 |
% |
| 483 |
% \begin{macro}{\TX@endtabularx} |
| 484 |
% Although I have tried to make {\ttfamily tabularx} look like an |
| 485 |
% environment, it is in fact a command, all the work is done by this |
| 486 |
% macro. |
| 487 |
% \begin{macrocode} |
| 488 |
\def\TX@endtabularx{% |
| 489 |
% \end{macrocode} |
| 490 |
% \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxa} added} |
| 491 |
% \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}} |
| 492 |
% \begin{macrocode} |
| 493 |
\expandafter\expandafter\expandafter |
| 494 |
\TX@find@endtabularxa\csname end\TX@\endcsname |
| 495 |
\endtabularx\TX@\endtabularx\TX@find@endtabularxa |
| 496 |
% \end{macrocode} |
| 497 |
% Define the {\ttfamily X} column, with an internal version of the |
| 498 |
% "\newcolumntype" command. The "\expandafter" commands enable |
| 499 |
% "\NC@newcol" to get the {\em expansion} of\\ |
| 500 |
% "\tabularxcolumn{\TX@col@width}" as its |
| 501 |
% argument. This will be the definition of an {\ttfamily X} column, as |
| 502 |
% discussed in section 4. |
| 503 |
% \begin{macrocode} |
| 504 |
\expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}% |
| 505 |
% \end{macrocode} |
| 506 |
% Initialise the column width, and the number of {\ttfamily X} columns. |
| 507 |
% The number of {\ttfamily X} columns is set to one, which means that |
| 508 |
% the initial count will be one too high, but this value is decremented |
| 509 |
% before it is used in the main loop. |
| 510 |
% |
| 511 |
% Since v1.02, switch the definition of "\verb". |
| 512 |
% \begin{macrocode} |
| 513 |
\let\verb\TX@verb |
| 514 |
% \end{macrocode} |
| 515 |
% Since v1.05, save the values of all \LaTeX\ counters, the list |
| 516 |
% "\cl@@ckpt" contains the names of all the \LaTeX\ counters that have |
| 517 |
% been defined so far. We expand "\setcounter" at this point, as it |
| 518 |
% results in fewer tokens being stored in "\TX@ckpt", but the actual |
| 519 |
% resetting of the counters occurs when "\TX@ckpt" is expanded after |
| 520 |
% each trial run. |
| 521 |
% Actually since v1.07, use something equivalent to the expansion of the |
| 522 |
% original definition of "\setcounter", so that "tabularx" works in |
| 523 |
% conjunction with "calc.sty". |
| 524 |
% \begin{macrocode} |
| 525 |
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}% |
| 526 |
\edef\TX@ckpt{\cl@@ckpt}% |
| 527 |
\let\@elt\relax |
| 528 |
\TX@old@table\maxdimen |
| 529 |
\TX@col@width\TX@target |
| 530 |
\global\TX@cols\@ne |
| 531 |
% \end{macrocode} |
| 532 |
% Type out some headings (unless this is disabled). |
| 533 |
% \begin{macrocode} |
| 534 |
\TX@typeout@ |
| 535 |
{\@spaces Table Width\@spaces Column Width\@spaces X Columns}% |
| 536 |
% \end{macrocode} |
| 537 |
% |
| 538 |
% While we do trial typesetting we suspend any tagging if that is |
| 539 |
% active: |
| 540 |
% \changes{v2.12a}{2023/12/11} |
| 541 |
% {Suspend any tagging while doing trial typesetting} |
| 542 |
% \begin{macrocode} |
| 543 |
\SuspendTagging {tabularx}% |
| 544 |
% \end{macrocode} |
| 545 |
% First attempt. Modify the {\ttfamily X} definition to count {\ttfamily |
| 546 |
% X} columns. |
| 547 |
% \begin{macrocode} |
| 548 |
\TX@trial{\def\NC@rewrite@X{% |
| 549 |
\global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}% |
| 550 |
% \end{macrocode} |
| 551 |
% Repeatedly decrease column width until table is the correct width, |
| 552 |
% or stops shrinking, or the columns become too narrow. |
| 553 |
% If there are no multicolumn entries, this will only take one attempt. |
| 554 |
% \begin{macrocode} |
| 555 |
\loop |
| 556 |
\TX@arith |
| 557 |
\ifTX@ |
| 558 |
\TX@trial{}% |
| 559 |
\repeat |
| 560 |
% \end{macrocode} |
| 561 |
% |
| 562 |
% And here we restart it again: |
| 563 |
% \begin{macrocode} |
| 564 |
\ResumeTagging {tabularx}% |
| 565 |
% \end{macrocode} |
| 566 |
% |
| 567 |
% One last time, with warnings back on (see appendix D) |
| 568 |
% use {\ttfamily tabular*} to put it in a box of the right size, in case |
| 569 |
% the algorithm failed to find the correct size. |
| 570 |
% |
| 571 |
% Since v1.04, locally make "\footnotetext" save its argument in a token |
| 572 |
% register. |
| 573 |
% Since v1.06, "\toks@" contains the preamble specification, |
| 574 |
% and possible optional argument, as well as the table body. |
| 575 |
% \begin{macrocode} |
| 576 |
{\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext |
| 577 |
\csname tabular*\expandafter\endcsname\expandafter\TX@target |
| 578 |
\the\toks@ |
| 579 |
\csname endtabular*\endcsname}% |
| 580 |
% \end{macrocode} |
| 581 |
% Now the alignment is finished, and the "}" has restored the original |
| 582 |
% meaning of "\@footnotetext" expand the register "\TX@ftn" which will |
| 583 |
% execute a series of\\ |
| 584 |
% "\footnotetext["\meta{num}"]{"\meta{note}"}"\\ |
| 585 |
% commands. We need to be careful about clearing the register as we may |
| 586 |
% be inside a nested {\ttfamily tabularx}. |
| 587 |
% \begin{macrocode} |
| 588 |
\global\TX@ftn\expandafter{\expandafter}\the\TX@ftn |
| 589 |
% \end{macrocode} |
| 590 |
% Now finish off the {\ttfamily tabularx} environment. Note that we need |
| 591 |
% "\end{tabularx}" here as the "\end{tabularx}" in the user's |
| 592 |
% file is never expanded. Now use "\TX@" rather than "tabularx". |
| 593 |
% \changes{v2.02}{1995/03/20} |
| 594 |
% {Close the environment \cs{TX@} rather than `tabularx'} |
| 595 |
% |
| 596 |
% We also need to finish off the group started by "{\ifnum0=`}\fi" in |
| 597 |
% the macro "\tabularx". |
| 598 |
% \begin{macrocode} |
| 599 |
\ifnum0=`{\fi}% |
| 600 |
% \end{macrocode} |
| 601 |
% \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxb} added} |
| 602 |
% \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}} |
| 603 |
% \begin{macrocode} |
| 604 |
\expandafter\expandafter\expandafter |
| 605 |
\TX@find@endtabularxbb |
| 606 |
\expandafter\end\expandafter{\TX@}% |
| 607 |
\endtabularx\TX@\endtabularx\TX@find@endtabularxb |
| 608 |
} |
| 609 |
% \end{macrocode} |
| 610 |
% \end{macro} |
| 611 |
% |
| 612 |
% |
| 613 |
% \begin{macro}{\TX@arith} |
| 614 |
% Calculate the column width for the next try, setting the flag |
| 615 |
% "\ifTX@" to false if the loop should be aborted. |
| 616 |
% \begin{macrocode} |
| 617 |
\def\TX@arith{% |
| 618 |
\TX@false |
| 619 |
% \end{macrocode} |
| 620 |
% \changes{v2.08}{2012/02/06}{Avoid exceeding maxdimen during trials} |
| 621 |
% \begin{macrocode} |
| 622 |
\@tempdimb\maxdimen |
| 623 |
\divide\@tempdimb\TX@cols |
| 624 |
\ifdim\TX@col@width>\@tempdimb |
| 625 |
\TX@typeout@{Don't exceed \maxdimen}% |
| 626 |
\wd\@tempboxa\maxdimen |
| 627 |
\fi |
| 628 |
\ifdim\TX@old@table=\wd\@tempboxa |
| 629 |
% \end{macrocode} |
| 630 |
% If we have reduced the column width, but the table width has not |
| 631 |
% changed, we stop the loop, and output the table (which will cause an |
| 632 |
% over-full alignment) with the previous value of "\TX@col@width". |
| 633 |
% \begin{macrocode} |
| 634 |
\TX@col@width\TX@old@col |
| 635 |
\TX@typeout@{Reached minimum width, backing up.}% |
| 636 |
\else |
| 637 |
% \end{macrocode} |
| 638 |
% Otherwise calculate the amount by which the current table is too wide. |
| 639 |
% \begin{macrocode} |
| 640 |
\dimen@\wd\@tempboxa |
| 641 |
\advance\dimen@ -\TX@target |
| 642 |
\ifdim\dimen@<\TX@delta |
| 643 |
% \end{macrocode} |
| 644 |
% If this amount is less than "\TX@delta", stop. ("\TX@delta" |
| 645 |
% should be non-zero, otherwise we may miss the target due to rounding |
| 646 |
% error.) |
| 647 |
% \begin{macrocode} |
| 648 |
\TX@typeout@{Reached target.}% |
| 649 |
\else |
| 650 |
% \end{macrocode} |
| 651 |
% Reduce the number of effective {\ttfamily X} columns by one. (Checking |
| 652 |
% that we do not get 0, as this would produce an error later.) Then |
| 653 |
% divide excess width by the number of effective columns, and calculate |
| 654 |
% the new column width. Temporarily store this value (times $-1$) in |
| 655 |
% "\dimen@". |
| 656 |
% \begin{macrocode} |
| 657 |
\ifnum\TX@cols>\@ne |
| 658 |
\advance\TX@cols\m@ne |
| 659 |
\fi |
| 660 |
\divide\dimen@\TX@cols |
| 661 |
\advance\dimen@ -\TX@col@width |
| 662 |
\ifdim \dimen@ >\z@ |
| 663 |
% \end{macrocode} |
| 664 |
% If the new width would be too narrow, abort the loop. At the moment |
| 665 |
% too narrow means less than 0\,pt! |
| 666 |
% |
| 667 |
% Prior to v2.03, if the loop was aborted here, the X columns were left |
| 668 |
% with the width of the previous run, but this may make the table far |
| 669 |
% too wide as initial guesses are always too big. Now force to |
| 670 |
% "\TX@error@width" which defaults to be 1em. If you want to |
| 671 |
% get the old behaviour stick\\ |
| 672 |
% "\renewcommand\TX@error@width{\TX@col@width}"\\ |
| 673 |
% in a package file loaded after \textsf{tabularx}. |
| 674 |
% \changes{v2.03}{1997/02/20}{Improve warning message and force to 1em.} |
| 675 |
% \begin{macrocode} |
| 676 |
\PackageWarning{tabularx}% |
| 677 |
{X Columns too narrow (table too wide)\MessageBreak}% |
| 678 |
\TX@col@width\TX@error@width\relax |
| 679 |
\else |
| 680 |
% \end{macrocode} |
| 681 |
% Otherwise save the old settings, and set the new column width. Set the |
| 682 |
% flag to true so that the table will be set, and the loop will be |
| 683 |
% executed again. |
| 684 |
% \begin{macrocode} |
| 685 |
\TX@old@col\TX@col@width |
| 686 |
\TX@old@table\wd\@tempboxa |
| 687 |
\TX@col@width-\dimen@ |
| 688 |
\TX@true |
| 689 |
\fi |
| 690 |
\fi |
| 691 |
\fi} |
| 692 |
% \end{macrocode} |
| 693 |
% \end{macro} |
| 694 |
% |
| 695 |
% \begin{macro}{\TX@error@width} |
| 696 |
% \changes{v2.03}{1997/02/20}{macro added.} |
| 697 |
% \changes{v2.04}{1997/02/26}{spurious brace removed.} |
| 698 |
% If the calculated width is negative, use this instead. |
| 699 |
% \begin{macrocode} |
| 700 |
\def\TX@error@width{1em} |
| 701 |
% \end{macrocode} |
| 702 |
% \end{macro} |
| 703 |
% |
| 704 |
% \begin{macro}{\TX@delta} |
| 705 |
% Accept a table that is within "\hfuzz" of the correct width. |
| 706 |
% \begin{macrocode} |
| 707 |
\TX@delta\hfuzz |
| 708 |
% \end{macrocode} |
| 709 |
% \end{macro} |
| 710 |
% |
| 711 |
% Initialise the {\ttfamily X} column. The definition can be empty here, |
| 712 |
% as it is set for each {\ttfamily tabularx} environment. |
| 713 |
% \begin{macrocode} |
| 714 |
\newcolumntype{X}{} |
| 715 |
% \end{macrocode} |
| 716 |
% |
| 717 |
% \begin{macro}{\tabularxcolumn} |
| 718 |
% The default definition of {\ttfamily X} is "p{#1}". |
| 719 |
% \begin{macrocode} |
| 720 |
\def\tabularxcolumn#1{p{#1}} |
| 721 |
% \end{macrocode} |
| 722 |
% \end{macro} |
| 723 |
% |
| 724 |
% \begin{macro}{\TX@newcol} |
| 725 |
% A little macro just used to cut down the number of "\expandafter" |
| 726 |
% commands needed. |
| 727 |
% \begin{macrocode} |
| 728 |
\def\TX@newcol{\newcol@{X}[0]} |
| 729 |
% \end{macrocode} |
| 730 |
% \end{macro} |
| 731 |
% |
| 732 |
% \begin{macro}{\TX@trial} |
| 733 |
% Make a test run. |
| 734 |
% \begin{macrocode} |
| 735 |
\def\TX@trial#1{% |
| 736 |
\setbox\@tempboxa\hbox{% |
| 737 |
% \end{macrocode} |
| 738 |
% Any extra commands. This is used on the first run to count the number |
| 739 |
% of {\ttfamily X} columns. |
| 740 |
% \begin{macrocode} |
| 741 |
#1\relax |
| 742 |
% \end{macrocode} |
| 743 |
% Since v1.04, make "\footnotetext" gobble its arguments. Also locally |
| 744 |
% clear "\TX@vwarn" so that the warning is generated by the {\ttfamily |
| 745 |
% final} run, and does not appear in the middle of the table if |
| 746 |
% "\tracingtabularx". |
| 747 |
% \begin{macrocode} |
| 748 |
\let\@footnotetext\TX@trial@ftn |
| 749 |
\let\TX@vwarn\@empty |
| 750 |
% \end{macrocode} |
| 751 |
% Do not nest {\ttfamily tabularx} environments during trial runs. This |
| 752 |
% would waste time, and the global setting of "\TX@cols" would break the |
| 753 |
% algorithm. |
| 754 |
% \begin{macrocode} |
| 755 |
\expandafter\let\expandafter\tabularx\csname tabular*\endcsname |
| 756 |
\expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname |
| 757 |
% \end{macrocode} |
| 758 |
% Added at v1.05: disable "\write"s during a trial run. This trick is |
| 759 |
% from the \TeX{}book.\footnote{Actually the \TeX{}book trick does |
| 760 |
% not work correctly, so changed for v2.05.} |
| 761 |
% \changes{v2.05}{1997/09/18} |
| 762 |
% {New \cs{write} trick. tools/2607} |
| 763 |
% \changes{v2.07}{1999/01/07} |
| 764 |
% {Newer \cs{write} trick. tools/2792} |
| 765 |
% \begin{macrocode} |
| 766 |
\def\write{\begingroup |
| 767 |
\def\let{\afterassignment\endgroup\toks@}% |
| 768 |
\afterassignment\let\count@}% |
| 769 |
% \end{macrocode} |
| 770 |
% Turn off warnings (see appendix D). Also prevent them being turned |
| 771 |
% back on by setting the parameter names to be registers. |
| 772 |
% \begin{macrocode} |
| 773 |
\hbadness\@M |
| 774 |
\hfuzz\maxdimen |
| 775 |
\let\hbadness\@tempcnta |
| 776 |
\let\hfuzz\@tempdima |
| 777 |
% \end{macrocode} |
| 778 |
% Make the table, and finish the hbox. |
| 779 |
% Since v1.06, "\toks@" contains the preamble specification, |
| 780 |
% and possible optional argument, as well as the table body. |
| 781 |
% |
| 782 |
% \begin{macrocode} |
| 783 |
\expandafter\tabular\the\toks@ |
| 784 |
\endtabular}% |
| 785 |
% \end{macrocode} |
| 786 |
% Since v1.05 reset all \LaTeX\ counters, by executing "\TX@ckpt". |
| 787 |
% \begin{macrocode} |
| 788 |
\TX@ckpt |
| 789 |
% \end{macrocode} |
| 790 |
% Print some statistics. |
| 791 |
% Added "\TX@align" in v1.05, to line up the columns. |
| 792 |
% \begin{macrocode} |
| 793 |
\TX@typeout@{\@spaces |
| 794 |
\expandafter\TX@align |
| 795 |
\the\wd\@tempboxa\space\space\space\space\space\@@ |
| 796 |
\expandafter\TX@align |
| 797 |
\the\TX@col@width\space\space\space\space\space\@@ |
| 798 |
\@spaces\the\TX@cols}} |
| 799 |
% \end{macrocode} |
| 800 |
% \end{macro} |
| 801 |
% |
| 802 |
% \begin{macro}{\TX@align} |
| 803 |
% Macro added at v1.05, to improve the printing of the tracing info. |
| 804 |
% \begin{macrocode} |
| 805 |
\def\TX@align#1.#2#3#4#5#6#7#8#9\@@{% |
| 806 |
\ifnum#1<10 \space\fi |
| 807 |
\ifnum#1<100 \space\fi |
| 808 |
\ifnum#1<\@m\space\fi |
| 809 |
\ifnum#1<\@M\space\fi |
| 810 |
#1.#2#3#4#5#6#7#8\space\space} |
| 811 |
% \end{macrocode} |
| 812 |
% \end{macro} |
| 813 |
% |
| 814 |
% \begin{macro}{\arraybackslash} |
| 815 |
% "\\" hack. |
| 816 |
% \changes{v2.08}{2012/02/06}{Don't define this if already defined by newer array package and use tabularnewline now this is in 2e.} |
| 817 |
% \begin{macrocode} |
| 818 |
\ifx\arraybackslash\@undefined |
| 819 |
\def\arraybackslash{\let\\\tabularnewline} |
| 820 |
\fi |
| 821 |
% \end{macrocode} |
| 822 |
% \end{macro} |
| 823 |
% |
| 824 |
% \begin{macro}{\tracingtabularx} |
| 825 |
% Print statistics on column and table widths. |
| 826 |
% \begin{macrocode} |
| 827 |
\def\tracingtabularx{% |
| 828 |
\def\TX@typeout{\PackageWarningNoLine{tabularx}}% |
| 829 |
\def\TX@typeout@##1{\typeout{(tabularx) ##1}}} |
| 830 |
% \end{macrocode} |
| 831 |
% \end{macro} |
| 832 |
% |
| 833 |
% \begin{macro}{\TX@typeout} |
| 834 |
% The default is to be quiet. |
| 835 |
% \begin{macrocode} |
| 836 |
\let\TX@typeout\@gobble |
| 837 |
\let\TX@typeout@\@gobble |
| 838 |
% \end{macrocode} |
| 839 |
% \end{macro} |
| 840 |
% |
| 841 |
% \begin{macro}{\TX@ftn} |
| 842 |
% A token register for saving footnote texts. |
| 843 |
% \begin{macrocode} |
| 844 |
\newtoks\TX@ftn |
| 845 |
% \end{macrocode} |
| 846 |
% \end{macro} |
| 847 |
% |
| 848 |
% \begin{macro}{\TX@ftntext} |
| 849 |
% \begin{macro}{\TX@xftntext} |
| 850 |
% Inside the alignment just save up the footnote text in a token |
| 851 |
% register. |
| 852 |
% \begin{macrocode} |
| 853 |
\long\def\TX@ftntext#1{% |
| 854 |
\edef\@tempa{\the\TX@ftn\noexpand\footnotetext |
| 855 |
[\the\csname c@\@mpfn\endcsname]}% |
| 856 |
\global\TX@ftn\expandafter{\@tempa{#1}}}% |
| 857 |
\long\def\TX@xftntext[#1]#2{% |
| 858 |
\global\TX@ftn\expandafter{\the\TX@ftn\footnotetext[#1]{#2}}} |
| 859 |
% \end{macrocode} |
| 860 |
% \end{macro} |
| 861 |
% \end{macro} |
| 862 |
% |
| 863 |
% \begin{macro}{\TX@trial@ftn} |
| 864 |
% On trial runs, gobble footnote texts. |
| 865 |
% \begin{macrocode} |
| 866 |
\long\def\TX@trial@ftn#1{} |
| 867 |
% \end{macrocode} |
| 868 |
% \end{macro} |
| 869 |
% |
| 870 |
% This last section was added at Version 1.02. Previous versions |
| 871 |
% documented the fact that "\verb" did not work inside {\ttfamily |
| 872 |
% tabularx}, but that did not stop people using it! This usually put |
| 873 |
% \LaTeX\ into an irrecoverable error position, with error messages that |
| 874 |
% did not mention the cause of the error. The `poor man's "\verb"' (and |
| 875 |
% "\verb*") defined here is based on page 382 of the \TeX{}book. As |
| 876 |
% explained there, doing verbatim this way means that spaces are not |
| 877 |
% treated correctly, and so "\verb*" may well be useless, however I |
| 878 |
% consider this section of code to be error-recovery, rather than a real |
| 879 |
% implementation of verbatim. |
| 880 |
% |
| 881 |
% The mechanism is quite general, and any macro which wants to allow a |
| 882 |
% form of "\verb" to be used within its argument may |
| 883 |
% "\let\verb=\TX@verb". (Making sure to restore the real definition |
| 884 |
% later!) |
| 885 |
% |
| 886 |
% "\verb" and "\verb*" are subject to the following restrictions: |
| 887 |
% \begin{enumerate} |
| 888 |
% \item Spaces in the argument are not read verbatim, but may be skipped |
| 889 |
% according to \TeX's usual rules. |
| 890 |
% \item Spaces will be added to the output after control words, even if |
| 891 |
% they were not present in the input. |
| 892 |
% \item Unless the argument is a single space, any trailing space, |
| 893 |
% whether in the original argument, or added as in (2), |
| 894 |
% will be omitted. |
| 895 |
% \item The argument must not end with "\", so "\verb|\|" is not |
| 896 |
% allowed, however, because of (3), "\verb|\ |" produces |
| 897 |
% "\". |
| 898 |
% \item The argument must be balanced with respect to "{" and "}". So |
| 899 |
% "\verb|{|" is not allowed. |
| 900 |
% \item A comment character like "%" will not appear verbatim. It will |
| 901 |
% act as usual, commenting out the rest of the input line! |
| 902 |
% \item The combinations "?`" and "!`" will appear as |
| 903 |
% {\ttfamily?`} and {\ttfamily!`} if the {\ttfamily cmtt} font is |
| 904 |
% being used. |
| 905 |
% \end{enumerate} |
| 906 |
% |
| 907 |
% \begin{macro}{\TX@verb} |
| 908 |
% The internal definition of "\verb". Spaces will be replaced by "~", so |
| 909 |
% for the star-form, "\let" "~" be \verb*| |, which we obtain as |
| 910 |
% "\uppercase{*}". Use "{\ifnum0=`}\fi" rather than "\bgroup" to allow |
| 911 |
% "&" to appear in the argument. |
| 912 |
% \begin{macrocode} |
| 913 |
{\uccode`\*=`\ % |
| 914 |
\uppercase{\gdef\TX@verb{% |
| 915 |
\leavevmode\null\TX@vwarn |
| 916 |
{\ifnum0=`}\fi\ttfamily\let\\\ignorespaces |
| 917 |
\@ifstar{\let~*\TX@vb}{\TX@vb}}}} |
| 918 |
% \end{macrocode} |
| 919 |
% \end{macro} |
| 920 |
% |
| 921 |
% \begin{macro}{\TX@vb} |
| 922 |
% Get the `almost verbatim' text using "\meaning". The `"!"' is added to |
| 923 |
% the front of the user supplied text, to ensure that the whole argument |
| 924 |
% does not consist of a single "{ }" group. \TeX\ would strip the outer |
| 925 |
% braces from such a group. The `"!"' will be removed later. |
| 926 |
% |
| 927 |
% Originally I followed Knuth, and had "\def\@tempa{##1}", however, this |
| 928 |
% did not allow "#" to appear in the argument. So in v1.04, I changed |
| 929 |
% this to use a token register, and "\edef". This allows "#" to appear |
| 930 |
% but makes each one appear twice, so later we loop through, replacing |
| 931 |
% "##" by "#". |
| 932 |
% \begin{macrocode} |
| 933 |
\def\TX@vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}% |
| 934 |
\expandafter\TX@v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!} |
| 935 |
% \end{macrocode} |
| 936 |
% \end{macro} |
| 937 |
% |
| 938 |
% \begin{macro}{\TX@v} |
| 939 |
% Strip the initial segment of the "\meaning", including the `"!"' |
| 940 |
% added earlier. |
| 941 |
% \begin{macrocode} |
| 942 |
\def\TX@v#1!{\afterassignment\TX@vfirst\let\@tempa= } |
| 943 |
% \end{macrocode} |
| 944 |
% \end{macro} |
| 945 |
% |
| 946 |
% As explained above we are going to replace "##" pairs by "#". To do |
| 947 |
% this we need non-special "#" tokens. Make "*" into a parameter |
| 948 |
% token so that we can define macros with arguments. The normal meanings |
| 949 |
% will be restored by the "\endgroup" later. |
| 950 |
% \begin{macrocode} |
| 951 |
\begingroup |
| 952 |
\catcode`\*=\catcode`\# |
| 953 |
\catcode`\#=12 |
| 954 |
% \end{macrocode} |
| 955 |
% |
| 956 |
% \begin{macro}{\TX@vfirst} |
| 957 |
% As a special case, prevent the first character from being dropped. |
| 958 |
% This makes "\verb*| |" produce \verb*| |. Then call "\TX@v@". |
| 959 |
% This is slightly tricky since v1.04, as I have to ensure that an |
| 960 |
% actual "#" rather than a command "\let" to "#" is passed on if the |
| 961 |
% first character is "#". |
| 962 |
% \begin{macrocode} |
| 963 |
\gdef\TX@vfirst{% |
| 964 |
\if\@tempa#% |
| 965 |
\def\@tempb{\TX@v@#}% |
| 966 |
\else |
| 967 |
\let\@tempb\TX@v@ |
| 968 |
\if\@tempa\space~\else\@tempa\fi |
| 969 |
\fi |
| 970 |
\@tempb} |
| 971 |
% \end{macrocode} |
| 972 |
% \end{macro} |
| 973 |
% |
| 974 |
% \begin{macro}{\TX@v@} |
| 975 |
% Loop through the "\meaning", replacing all spaces by "~". If the last |
| 976 |
% character is a space it is dropped, so that "\verb*|\LaTeX|" produces |
| 977 |
% "\LaTeX" not \verb*|\LaTeX |. The rewritten tokens are then further |
| 978 |
% processed to replace "##" pairs. |
| 979 |
% \begin{macrocode} |
| 980 |
\gdef\TX@v@*1 *2{% |
| 981 |
\TX@v@hash*1##\relax\if*2\\\else~\expandafter\TX@v@\fi*2} |
| 982 |
% \end{macrocode} |
| 983 |
% \end{macro} |
| 984 |
% |
| 985 |
% \begin{macro}{\TX@v@hash} |
| 986 |
% The inner loop, replacing "##" by "#". |
| 987 |
% \begin{macrocode} |
| 988 |
\gdef\TX@v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX@v@hash\fi*2} |
| 989 |
% \end{macrocode} |
| 990 |
% \end{macro} |
| 991 |
% |
| 992 |
% As promised, we now restore the normal meanings of "#" and "*". |
| 993 |
% \begin{macrocode} |
| 994 |
\endgroup |
| 995 |
% \end{macrocode} |
| 996 |
% |
| 997 |
% \begin{macro}{\TX@vwarn} |
| 998 |
% Warn the user the first time this "\verb" is used. |
| 999 |
% \begin{macrocode} |
| 1000 |
\def\TX@vwarn{% |
| 1001 |
\@warning{\noexpand\verb may be unreliable inside tabularx}% |
| 1002 |
\global\let\TX@vwarn\@empty} |
| 1003 |
% \end{macrocode} |
| 1004 |
% \end{macro} |
| 1005 |
% |
| 1006 |
% |
| 1007 |
% \begin{macrocode} |
| 1008 |
%</package> |
| 1009 |
% \end{macrocode} |
| 1010 |
% |
| 1011 |
% \Finale |
| 1012 |
\endinput |