1 % \iffalse meta-comment
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
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 % http://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.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
24 %% File: tabularx.dtx Copyright (C) 1991-1999 2012 2014 2016 David Carlisle
27 \ProvidesFile{tabularx.dtx}
29 %<package>\NeedsTeXFormat{LaTeX2e}
30 %<package>\ProvidesPackage{tabularx}
31 %<driver> \ProvidesFile{tabularx.drv}
33 % \ProvidesFile{tabularx.dtx}
34 [2016/02/03 v2.11 `tabularx' package (DPC)]
37 \documentclass{ltxdoc}
38 \usepackage[infoshow]{tabularx}
40 \DocInput{tabularx.dtx}
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
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}
62 % \changes{v2.01}{1994/05/22}
63 % {New Tracing format.}
66 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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}
76 % \MaintainedByLaTeXTeam{tools}
78 % \DeleteShortVerb{\|}
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.
88 % This package requires the {\ttfamily array} package.
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
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.
111 % The following table is set with
112 % "\begin{tabularx}{250pt}{|c|X|c|X|} ...".
115 % \begin{tabularx}{250pt}{|c|X|c|X|}
117 % \multicolumn{2}{|c|}{Multicolumn entry!}&
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
127 % \raggedright\arraybackslash Column four will act in the same way as
128 % column two, with the same width.\\
132 % If we change the first line to "\begin{tabularx}{300pt}{|c|X|c|X|}" we
135 % \begin{tabularx}{300pt}{|c|X|c|X|}
137 % \multicolumn{2}{|c|}{Multicolumn entry!}&
142 % \raggedright\arraybackslash The width of this column depends on the
143 % width of the table.&
145 % \raggedright\arraybackslash Column four will act in the same way as
146 % column two, with the same width.\\
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:
157 % \item {\ttfamily tabularx} modifies the widths of the \emph{columns},
158 % whereas {\ttfamily tabular*} modifies the widths of the inter-column
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
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.
178 % \section{Customising the behaviour of {\mytt tabularx}}
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
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.
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
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
206 % ">{\raggedright\arraybackslash}X".
208 % \DescribeMacro{\newcolumntype}
209 % These preamble specifications may of course be saved using the
210 % command, "\newcolumntype", defined in {\ttfamily array.sty}. Thus we
212 % "\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}"\\
213 % and then use {\ttfamily Y} in the {\ttfamily tabularx} preamble
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.
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}}"
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 "{>{\hsize=.5\hsize}X>{\hsize=1.5\hsize}X}"
235 % specifies two columns, the second will be three times as wide as the
236 % first. However if you want to play games like this you should follow
237 % the following two rules.
239 % \item Make sure that the sum of the widths of all the {\ttfamily X}
240 % columns is unchanged. (In the above example, the new widths still add
241 % up to twice the default width, the same as two standard {\ttfamily X}
243 % \item Do not use "\multicolumn" entries which cross any {\ttfamily X}
246 % As with most rules, these may be broken if you know what you are
249 % \subsection{If the algorithm fails\ldots}
250 % It may be that the widths of the `normal' columns of the table
251 % already total more than the requested total
252 % width. \textsf{tabularx} refuses to set the
253 % \texttt{X} columns to a negative width, so in this case you get a
254 % warning ``X Columns too narrow (table too wide)''.
256 % The \texttt{X} columns will in this case be set to a width of 1em
257 % and so the table itself will be wider than the requested total width
258 % given in the argument to the environment.
259 % This behaviour of the package can be customised slightly
260 % as noted in the documentation of the code section.
264 % \section{The Macros}
270 % \changes{v2.00}{1994/02/07}
271 % {New Option Handling}
273 \DeclareOption{infoshow}{\AtEndOfPackage\tracingtabularx}
274 \DeclareOption{debugshow}{\AtEndOfPackage\tracingtabularx}
278 % This requires {\ttfamily array.sty}.
279 % \changes{v2.00}{1994/02/07}
280 % {Use LaTeX2e's \cmd{\RequirePackage} to load array}
282 \RequirePackage{array}[1994/02/03]
285 % First some registers etc.\ that we need.
287 \newdimen\TX@col@width
288 \newdimen\TX@old@table
296 % Now a trick to get the body of an environment into a token register,
297 % without doing any expansion. This does not do any real checking of
298 % nested environments, so if you should need to nest one {\ttfamily
299 % tabularx} inside another, the inner one must be surrounded by "{ }".
301 % \begin{macro}{\tabularx}
302 % Prior to v1.06, this macro took two arguments, which were saved in
303 % separate registers before the table body was saved by "\TX@get@body".
304 % Unfortunately this disables the "[t]" optional argument. Now just save
305 % the width specification separately, then clear the token register
307 % Finally call "\TX@get@body" to begin saving the body of the table.
308 % The "{\ifnum0=`}\fi" was added at v1.03, to allow "tabularx" to appear
309 % inside a "\halign".^^A
310 % \setbox0=\hbox{\footnotesize"\iffalse{\fi\ifnum0=`}\fi"}^^A
311 % \setbox2=\hbox{\footnotesize"\ifnum0=`{}\fi"}^^A
312 % \footnote{This adds an extra level of grouping,
313 % which is not really needed. Instead, I could use \box0\ here, and
314 % \box2\ below, however the code here would then have to be moved after
315 % the first line, because of the footnote to page 386 of the \TeX{}Book,
316 % and I do not think I should be writing code that is so obscure as to
317 % be documented in a footnote in an appendix called ``Dirty Tricks''!}
319 % This mechanism of grabbing an environment body does have the
320 % disadvantage (shared with the AMS alignment environments) that you
321 % can not make extension environments by code such as
323 %\newenvironment{foo}{\begin{tabularx}{XX}}{\end{tabularx}}
325 % as the code is looking for a literal string "\end{tabularx}" to stop
326 % scanning. Since version 2.02, one may avoid this problem by using
327 % "\tabularx" and "\endtabularx" directly in the definition:
329 %\newenvironment{foo}{\tabularx{XX}}{\endtabularx}
331 % The scanner now looks for the end of the current environment ("foo" in
332 % this example.) There are some restrictions on this usage, the
333 % principal one being that "\endtabularx" must not be inside any "{ }" pairs
334 % ao that the code before "\endtabularx" may be extracted and added to the table body
335 % (prior to version 2.09 "\endtabularx" had to be
336 % the \emph{first} token of the `end code' of the environment).
340 % \changes{v2.02}{1995/03/20}
341 % {New local setting of \cs{TX@}}
342 % \changes{v4.09}{1998/05/13}
343 % {Use \cs{setlength}, so that calc extensions apply. tools/2793}
344 % Allow "\tabularx" "\endtabularx" (but not "\begin{tabularx}"
345 % "\end{tabularx}") to be used in "\newenvironment" definitions.
347 \edef\TX@{\@currenvir}%
350 % "\relax" added at v1.05 so that non-expandable length tokens, like
351 % "\textwidth" do not generate an extra space, and an overfull box.
352 % "\relax" removed again at v4.09 in favour of "\setlength" so if you
353 % use the calc package you can use a width of "(\textwidth-12pt)/2".
355 \setlength\TX@target{#1}%
356 \TX@typeout{Target width: #1 = \the\TX@target.}%
357 \toks@{}\TX@get@body}
362 % \begin{macro}{\endtabularx}
363 % This does not do very much\ldots
364 % \changes{v2.02}{1995/03/20}
367 \let\endtabularx\relax
371 % \begin{macro}{\TX@get@body}
372 % Place all tokens as far as the first "\end" into a token register.
373 % Then call "\TX@find@end" to see if we are at "\end{tabularx}".
375 \long\def\TX@get@body#1\end
376 {\toks@\expandafter{\the\toks@#1}\TX@find@end}
380 % \begin{macro}{\TX@find@end}
381 % If we are at "\end{tabularx}", call "\TX@endtabularx", otherwise
382 % add "\end{...}" to the register, and call "\TX@get@body" again.
386 \ifx\@tempa\TX@\expandafter\TX@endtabularx
387 \else\toks@\expandafter
388 {\the\toks@\end{#1}}\expandafter\TX@get@body\fi}
392 % \begin{macro}{\TX@find@endtabularxa}
393 % \changes{v2.09}{2014/04/22}{macro added}
394 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
395 % \changes{v2.11}{2016/01/03}{Fix to previous change to guard against empty arg 2. (Ulrike Fischer)}
396 % split up the end code, and extract the part that lives in the table body.
398 \long\def\TX@find@endtabularxa
399 #1\endtabularx#2\endtabularx#3\TX@find@endtabularxa{%
400 \ifx\TX@#2\relax\else
401 \toks@\expandafter{\the\toks@#1}%
405 % \begin{macro}{\TX@find@endtabularxb}
406 % \changes{v2.09}{2014/04/22}{macro added}
407 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
408 % split up the end code, and extract the part that lives outside the table body.
410 \long\def\TX@find@endtabularxb
411 #1\endtabularx#2\endtabularx#3\TX@find@endtabularxb{%
413 \expandafter\@firstoftwo
415 \expandafter\@secondoftwo
421 % \begin{macro}{\TX@find@endtabularxbb}
422 % \changes{v2.10}{2014/05/13}{macro added}
423 % Helper to avoid needing 15 consecutive "expandafter"
425 \def\TX@find@endtabularxbb{%
426 \expandafter\expandafter\expandafter
427 \TX@find@endtabularxb
432 % \begin{macro}{\TX@}
433 % The string {\ttfamily tabularx} as a macro for testing with "\ifx".
439 % Now that all the parts of the table specification are stored in
440 % registers, we can begin the work of setting the table.
442 % The algorithm for finding the correct column widths is as follows.
443 % Firstly set the table with each {\ttfamily X} column the width of the
444 % final table. Assuming that there is at least one {\ttfamily X} column,
445 % this will produce a table that is too wide. Divide the excess width by
446 % the number of {\ttfamily X} columns, and reduce the column width by
447 % this amount. Reset the table. If the table is not now the correct
448 % width, a "\multicolumn" entry must be `hiding' one of the {\ttfamily
449 % X} columns, and so there is one less {\ttfamily X} column affecting
450 % the width of the table. So we reduce by 1 the number of X columns and
451 % repeat the process.
453 % \begin{macro}{\TX@endtabularx}
454 % Although I have tried to make {\ttfamily tabularx} look like an
455 % environment, it is in fact a command, all the work is done by this
458 \def\TX@endtabularx{%
460 % \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxa} added}
461 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
463 \expandafter\expandafter\expandafter
464 \TX@find@endtabularxa\csname end\TX@\endcsname
465 \endtabularx\TX@\endtabularx\TX@find@endtabularxa
467 % Define the {\ttfamily X} column, with an internal version of the
468 % "\newcolumntype" command. The "\expandafter" commands enable
469 % "\NC@newcol" to get the {\em expansion} of\\
470 % "\tabularxcolumn{\TX@col@width}" as its
471 % argument. This will be the definition of an {\ttfamily X} column, as
472 % discussed in section 4.
474 \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}%
476 % Initialise the column width, and the number of {\ttfamily X} columns.
477 % The number of {\ttfamily X} columns is set to one, which means that
478 % the initial count will be one too high, but this value is decremented
479 % before it is used in the main loop.
481 % Since v1.02, switch the definition of "\verb".
485 % Since v1.05, save the values of all \LaTeX\ counters, the list
486 % "\cl@@ckpt" contains the names of all the \LaTeX\ counters that have
487 % been defined so far. We expand "\setcounter" at this point, as it
488 % results in fewer tokens being stored in "\TX@ckpt", but the actual
489 % resetting of the counters occurs when "\TX@ckpt" is expanded after
491 % Actually since v1.07, use something equivalent to the expansion of the
492 % original definition of "\setcounter", so that "tabularx" works in
493 % conjunction with "calc.sty".
495 \def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
496 \edef\TX@ckpt{\cl@@ckpt}%
498 \TX@old@table\maxdimen
499 \TX@col@width\TX@target
502 % Typeout some headings (unless this is disabled).
505 {\@spaces Table Width\@spaces Column Width\@spaces X Columns}%
507 % First attempt. Modify the {\ttfamily X} definition to count {\ttfamily
510 \TX@trial{\def\NC@rewrite@X{%
511 \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}%
513 % Repeatedly decrease column width until table is the correct width,
514 % or stops shrinking, or the columns become two narrow.
515 % If there are no multicolumn entries, this will only take one attempt.
523 % One last time, with warnings back on (see appendix D)
524 % use {\ttfamily tabular*} to put it in a box of the right size, in case
525 % the algorithm failed to find the correct size.
527 % Since v1.04, locally make "\footnotetext" save its argument in a token
529 % Since v1.06, "\toks@" contains the preamble specification,
530 % and possible optional argument, as well as the table body.
532 {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext
533 \csname tabular*\expandafter\endcsname\expandafter\TX@target
535 \csname endtabular*\endcsname}%
537 % Now the alignment is finished, and the "}" has restored the original
538 % meaning of "\@footnotetext" expand the register "\TX@ftn" which will
539 % execute a series of\\
540 % "\footnotetext["\meta{num}"]{"\meta{note}"}"\\
541 % commands. We need to be careful about clearing the register as we may
542 % be inside a nested {\ttfamily tabularx}.
544 \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn
546 % Now finish off the {\ttfamily tabularx} environment. Note that we need
547 % "\end{tabularx}" here as the "\end{tabularx}" in the user's
548 % file is never expanded. Now use "\TX@" rather than "tabularx".
549 % \changes{v2.02}{1995/03/20}
550 % {Close the environment \cs{TX@} rather than `tabularx'}
552 % We also need to finish off the group started by "{\ifnum0=`}\fi" in
553 % the macro "\tabularx".
557 % \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxb} added}
558 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
560 \expandafter\expandafter\expandafter
561 \TX@find@endtabularxbb
562 \expandafter\end\expandafter{\TX@}%
563 \endtabularx\TX@\endtabularx\TX@find@endtabularxb
569 % \begin{macro}{\TX@arith}
570 % Calculate the column width for the next try, setting the flag
571 % "\ifTX@" to false if the loop should be aborted.
576 % \changes{v2.08}{2012/02/06}{Avoid exceeding maxdimen during trials}
579 \divide\@tempdimb\TX@cols
580 \ifdim\TX@col@width>\@tempdimb
581 \TX@typeout@{Don't exceed \maxdimen}%
582 \wd\@tempboxa\maxdimen
584 \ifdim\TX@old@table=\wd\@tempboxa
586 % If we have reduced the column width, but the table width has not
587 % changed, we stop the loop, and output the table (which will cause an
588 % over-full alignment) with the previous value of "\TX@col@width".
590 \TX@col@width\TX@old@col
591 \TX@typeout@{Reached minimum width, backing up.}%
594 % Otherwise calculate the amount by which the current table is too wide.
597 \advance\dimen@ -\TX@target
598 \ifdim\dimen@<\TX@delta
600 % If this amount is less than "\TX@delta", stop. ("\TX@delta"
601 % should be non-zero otherwise we may miss the target due to rounding
604 \TX@typeout@{Reached target.}%
607 % Reduce the number of effective {\ttfamily X} columns by one. (Checking
608 % that we do not get 0, as this would produce an error later.) Then
609 % divide excess width by the number of effective columns, and calculate
610 % the new column width. Temporarily store this value (times $-1$) in
614 \advance\TX@cols\m@ne
616 \divide\dimen@\TX@cols
617 \advance\dimen@ -\TX@col@width
620 % If the new width would be too narrow, abort the loop. At the moment
621 % too narrow, means less than 0\,pt!
623 % Prior to v2.03, if the loop was aborted here, the X columns were left
624 % with the width of the previous run, but this may make the table far
625 % too wide as initial guesses are always too big. Now force to
626 % "\TX@error@width" which defaults to be 1em. If you want to
627 % get the old behaviour stick\\
628 % "\renewcommand\TX@error@width{\TX@col@width}"\\
629 % in a package file loaded after \textsf{tabularx}.
630 % \changes{v2.03}{1997/02/20}{Improve warning message and force to 1em.}
632 \PackageWarning{tabularx}%
633 {X Columns too narrow (table too wide)\MessageBreak}%
634 \TX@col@width\TX@error@width\relax
637 % Otherwise save the old settings, and set the new column width. Set the
638 % flag to true so that the table will be set, and the loop will be
641 \TX@old@col\TX@col@width
642 \TX@old@table\wd\@tempboxa
643 \TX@col@width-\dimen@
651 % \begin{macro}{\TX@error@width}
652 % \changes{v2.03}{1997/02/20}{macro added.}
653 % \changes{v2.04}{1997/02/26}{spurious brace removed.}
654 % If the calculated width is negative, use this instead.
656 \def\TX@error@width{1em}
660 % \begin{macro}{\TX@delta}
661 % Accept a table that is within "\hfuzz" of the correct width.
667 % Initialise the {\ttfamily X} column. The definition can be empty here,
668 % as it is set for each {\ttfamily tabularx} environment.
673 % \begin{macro}{\tabularxcolumn}
674 % The default definition of {\ttfamily X} is "p{#1}".
676 \def\tabularxcolumn#1{p{#1}}
680 % \begin{macro}{\TX@newcol}
681 % A little macro just used to cut down the number of "\expandafter"
684 \def\TX@newcol{\newcol@{X}[0]}
688 % \begin{macro}{\TX@trial}
692 \setbox\@tempboxa\hbox{%
694 % Any extra commands. This is used on the first run to count the number
695 % of {\ttfamily X} columns.
699 % Since v1.04, make "\footnotetext" gobble its arguments. Also locally
700 % clear "\TX@vwarn" so that the warning is generated by the {\ttfamily
701 % final} run, and does not appear in the middle of the table if
702 % "\tracingtabularx".
704 \let\@footnotetext\TX@trial@ftn
707 % Do not nest {\ttfamily tabularx} environments during trial runs. This
708 % would waste time, and the global setting of "\TX@cols" would break the
711 \expandafter\let\expandafter\tabularx\csname tabular*\endcsname
712 \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname
714 % Added at v1.05: disable "\write"s during a trial run. This trick is
715 % from the \TeX{}Book.\footnote{Actually the \TeX{}Book trick does
716 % not work correctly, so changed for v2.05.}
717 % \changes{v2.05}{1997/09/18}
718 % {New \cs{write} trick. tools/2607}
719 % \changes{v2.07}{1999/01/07}
720 % {Newer \cs{write} trick. tools/2792}
722 \def\write{\begingroup
723 \def\let{\afterassignment\endgroup\toks@}%
724 \afterassignment\let\count@}%
726 % Turn off warnings (see appendix D). Also prevent them being turned
727 % back on by setting the parameter names to be registers.
731 \let\hbadness\@tempcnta
734 % Make the table, and finish the hbox.
735 % Since v1.06, "\toks@" contains the preamble specification,
736 % and possible optional argument, as well as the table body.
738 \expandafter\tabular\the\toks@
741 % Since v1.05 reset all \LaTeX\ counters, by executing "\TX@ckpt".
745 % Print some statistics.
746 % Added "\TX@align" in v1.05, to line up the columns.
748 \TX@typeout@{\@spaces
749 \expandafter\TX@align
750 \the\wd\@tempboxa\space\space\space\space\space\@@
751 \expandafter\TX@align
752 \the\TX@col@width\space\space\space\space\space\@@
753 \@spaces\the\TX@cols}}
757 % \begin{macro}{\TX@align}
758 % Macro added at v1.05, to improve the printing of the tracing info.
760 \def\TX@align#1.#2#3#4#5#6#7#8#9\@@{%
761 \ifnum#1<10 \space\fi
762 \ifnum#1<100 \space\fi
763 \ifnum#1<\@m\space\fi
764 \ifnum#1<\@M\space\fi
765 #1.#2#3#4#5#6#7#8\space\space}
769 % \begin{macro}{\arraybackslash}
771 % \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.}
773 \ifx\arraybackslash\@undefined
774 \def\arraybackslash{\let\\\tabularnewline}
779 % \begin{macro}{\tracingtabularx}
780 % Print statistics on column and table widths.
782 \def\tracingtabularx{%
783 \def\TX@typeout{\PackageWarningNoLine{tabularx}}%
784 \def\TX@typeout@##1{\typeout{(tabularx) ##1}}}
788 % \begin{macro}{\TX@typeout}
789 % The default is to be to be quiet
791 \let\TX@typeout\@gobble
792 \let\TX@typeout@\@gobble
796 % \begin{macro}{\TX@ftn}
797 % A token register for saving footnote texts.
803 % \begin{macro}{\TX@ftntext}
804 % \begin{macro}{\TX@xftntext}
805 % Inside the alignment just save up the footnote text in a token
808 \long\def\TX@ftntext#1{%
809 \edef\@tempa{\the\TX@ftn\noexpand\footnotetext
810 [\the\csname c@\@mpfn\endcsname]}%
811 \global\TX@ftn\expandafter{\@tempa{#1}}}%
812 \long\def\TX@xftntext[#1]#2{%
813 \global\TX@ftn\expandafter{\the\TX@ftn\footnotetext[#1]{#2}}}
818 % \begin{macro}{\TX@trial@ftn}
819 % On trial runs, gobble footnote texts.
821 \long\def\TX@trial@ftn#1{}
825 % This last section was added at Version 1.02. Previous versions
826 % documented the fact that "\verb" did not work inside {\ttfamily
827 % tabularx}, but that did not stop people using it! This usually put
828 % \LaTeX\ into an irrecoverable error position, with error messages that
829 % did not mention the cause of the error. The `poor man's "\verb"' (and
830 % "\verb*") defined here is based on page 382 of the \TeX{}Book. As
831 % explained there, doing verbatim this way means that spaces are not
832 % treated correctly, and so "\verb*" may well be useless, however I
833 % consider this section of code to be error-recovery, rather than a real
834 % implementation of verbatim.
836 % The mechanism is quite general, and any macro which wants to allow a
837 % form of "\verb" to be used within its argument may
838 % "\let\verb=\TX@verb". (Making sure to restore the real definition
841 % "\verb" and "\verb*" are subject to the following restrictions:
843 % \item Spaces in the argument are not read verbatim, but may be skipped
844 % according to \TeX's usual rules.
845 % \item Spaces will be added to the output after control words, even if
846 % they were not present in the input.
847 % \item Unless the argument is a single space, any trailing space,
848 % whether in the original argument, or added as in (2),
850 % \item The argument must not end with "\", so "\verb|\|" is not
851 % allowed, however, because of (3), "\verb|\ |" produces
853 % \item The argument must be balanced with respect to "{" and "}". So
854 % "\verb|{|" is not allowed.
855 % \item A comment character like "%" will not appear verbatim. It will
856 % act as usual, commenting out the rest of the input line!
857 % \item The combinations "?`" and "!`" will appear as
858 % {\ttfamily?`} and {\ttfamily!`} if the {\ttfamily cmtt} font is
862 % \begin{macro}{\TX@verb}
863 % The internal definition of "\verb". Spaces will be replaced by "~", so
864 % for the star-form, "\let" "~" be \verb*| |, which we obtain as
865 % "\uppercase{*}". Use "{\ifnum0=`}\fi" rather than "\bgroup" to allow
866 % "&" to appear in the argument.
869 \uppercase{\gdef\TX@verb{%
870 \leavevmode\null\TX@vwarn
871 {\ifnum0=`}\fi\ttfamily\let\\\ignorespaces
872 \@ifstar{\let~*\TX@vb}{\TX@vb}}}}
876 % \begin{macro}{\TX@vb}
877 % Get the `almost verbatim' text using "\meaning". The `"!"' is added to
878 % the front of the user supplied text, to ensure that the whole argument
879 % does not consist of a single "{ }" group. \TeX\ would strip the outer
880 % braces from such a group. The `"!"' will be removed later.
882 % Originally I followed Knuth, and had "\def\@tempa{##1}", however this
883 % did not allow "#" to appear in the argument. So in v1.04, I changed
884 % this to to use a token register, and "\edef". This allows "#" appear,
885 % but makes each one appear twice!, so later we loop through, replacing
888 \def\TX@vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}%
889 \expandafter\TX@v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!}
893 % \begin{macro}{\TX@v}
894 % Strip the initial segment of the "\meaning", including the `"!"'
897 \def\TX@v#1!{\afterassignment\TX@vfirst\let\@tempa= }
901 % As explained above we are going to replace "##" pairs by "#". To do
902 % this we need non-special "#" tokens. Make "*" into a parameter
903 % token so that we can define macros with arguments. The normal meanings
904 % will be restored by the "\endgroup" later.
907 \catcode`\*=\catcode`\#
911 % \begin{macro}{\TX@vfirst}
912 % As a special case, prevent the first character from being dropped.
913 % This makes "\verb*| |" produce \verb*| |. Then call "\TX@v@".
914 % This is slightly tricky since v1.04, as I have to ensure that an
915 % actual "#" rather than a command "\let" to "#" is passed on if the
916 % first character is "#".
920 \def\@tempb{\TX@v@#}%
923 \if\@tempa\space~\else\@tempa\fi
929 % \begin{macro}{\TX@v@}
930 % Loop through the "\meaning", replacing all spaces by "~". If the last
931 % character is a space it is dropped, so that "\verb*|\LaTeX|" produces
932 % "\LaTeX" not \verb*|\LaTeX |. The rewritten tokens are then further
933 % processed to replace "##" pairs.
936 \TX@v@hash*1##\relax\if*2\\\else~\expandafter\TX@v@\fi*2}
940 % \begin{macro}{\TX@v@hash}
941 % The inner loop, replacing "##" by "#".
943 \gdef\TX@v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX@v@hash\fi*2}
947 % As promised, we now restore the normal meanings of "#" and "*".
952 % \begin{macro}{\TX@vwarn}
953 % Warn the user the first time this "\verb" is used.
956 \@warning{\noexpand\verb may be unreliable inside tabularx}%
957 \global\let\TX@vwarn\@empty}