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 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % \GetFileInfo{tabularx.dtx}
72 % \title{The \textsf{tabularx} package\thanks{This file
73 % has version number \fileversion, last
74 % revised \filedate.}}
75 % \author{David Carlisle}
77 % \MaintainedByLaTeXTeam{tools}
79 % \DeleteShortVerb{\|}
83 % A new environment, {\ttfamily tabularx}, is defined, which takes the
84 % same arguments as {\ttfamily tabular*}, but modifies the widths of
85 % certain columns, rather than the inter column space, to set a table
86 % with the requested total width. The columns that may stretch are
87 % marked with the new token {\ttfamily X} in the preamble argument.
89 % This package requires the {\ttfamily array} package.
92 % \section{Introduction}
93 % This package implements a version of the {\ttfamily tabular}
94 % environment in which the widths of certain columns are calculated so
95 % that the table is a specified width. Requests for such an
96 % environment seem to occur quite regularly in {\ttfamily
99 % \DescribeEnv{tabularx}
100 % "\begin{tabularx}{"\meta{width}"}{"\meta{preamble}"}"\\
101 % The arguments of "tabularx" are essentially the same as those of
102 % the standard "tabular*" environment. However rather than adding space
103 % between the columns to achieve the desired width, it adjusts the
104 % widths of some of the columns. The columns which are affected by the
105 % {\ttfamily tabularx} environment should be denoted with the letter
106 % {\ttfamily X} in the preamble argument. The {\ttfamily X} column
107 % specification will be converted to "p{"\meta{some value}"}" once the
108 % correct column width has been calculated.
112 % The following table is set with
113 % "\begin{tabularx}{250pt}{|c|X|c|X|} ...".
116 % \begin{tabularx}{250pt}{|c|X|c|X|}
118 % \multicolumn{2}{|c|}{Multicolumn entry!}&
123 % \raggedright\arraybackslash The width of this column depends on the
124 % width of the table.\footnote
125 % {You can now use {\ttfamily \bslash footnote} inside {\ttfamily
128 % \raggedright\arraybackslash Column four will act in the same way as
129 % column two, with the same width.\\
133 % If we change the first line to "\begin{tabularx}{300pt}{|c|X|c|X|}" we
136 % \begin{tabularx}{300pt}{|c|X|c|X|}
138 % \multicolumn{2}{|c|}{Multicolumn entry!}&
143 % \raggedright\arraybackslash The width of this column depends on the
144 % width of the table.&
146 % \raggedright\arraybackslash Column four will act in the same way as
147 % column two, with the same width.\\
152 % \edef\mytt{\expandafter\noexpand\csname
153 % mdseries\endcsname\noexpand\ttfamily}
154 % \section{Differences between {\mytt tabularx} and {\mytt tabular*}}
155 % These two environments take the same arguments, to produce a table of
156 % a specified width. The main differences between them are:
158 % \item {\ttfamily tabularx} modifies the widths of the \emph{columns},
159 % whereas {\ttfamily tabular*} modifies the widths of the inter-column
161 % \item {\ttfamily tabular} and {\ttfamily tabular*} environments may be
162 % nested with no restriction, however if one {\ttfamily tabularx}
163 % environment occurs inside another, then the inner one {\em must\/} be
165 % \item The body of the {\ttfamily tabularx} environment is in fact the
166 % argument to a command, and so certain constructions which are not
167 % allowed in command arguments (like "\verb") may not be used.\footnote
168 % {Since Version 1.02, {\ttfamily\bslash verb and \ttfamily\bslash
169 % verb*} may be used, but they may treat spaces incorrectly, and the
170 % argument can not contain an unmatched {\ttfamily\char`\{} or
171 % {\ttfamily\char`\}}, or a {\ttfamily\char`\%} character.}
172 % \item {\ttfamily tabular*} uses a primitive capability of \TeX\ to
173 % modify the inter column space of an alignment. {\ttfamily tabularx}
174 % has to set the table several times as it searches for the best column
175 % widths, and is therefore much slower. Also the fact that the body is
176 % expanded several times may break certain \TeX\ constructs.
179 % \section{Customising the behaviour of {\mytt tabularx}}
181 % \subsection{Terminal output}
182 % \DescribeMacro{\tracingtabularx}
183 % If this declaration is made, say in the document preamble, then all
184 % following {\ttfamily tabularx} environments will print information
185 % about column widths as they repeatedly re-set the tables to find the
188 % As an alternative to using the "\tracingtabularx" declaration, either
189 % of the options "infoshow" or "debugshow" may be given, either in the
190 % "\usepackage" command that loads "tabularx", or as a global option
191 % in the "\documentclass" command.
193 % \subsection{The environment used to typeset the {\mytt X} columns}
194 % By default the {\ttfamily X} specification is turned into
195 % "p{"\meta{some value}"}". Such narrow columns often
196 % require a special format, this may be achieved using the ">" syntax
197 % of {\ttfamily array.sty}. So for example you may give a specification
198 % of ">{\small}X". Another format which is useful in narrow columns is
199 % ragged right, however \LaTeX's "\raggedright" macro redefines
200 % "\\" in a way which conflicts with its use in a tabular or array
202 %\DescribeMacro{\arraybackslash}
203 % For this reason this package introduces the command "\arraybackslash",
204 % this may be used after a "\raggedright", "\raggedleft" or
205 % "\centering" declaration. Thus a {\ttfamily tabularx} preamble may
207 % ">{\raggedright\arraybackslash}X".
209 % \DescribeMacro{\newcolumntype}
210 % These preamble specifications may of course be saved using the
211 % command, "\newcolumntype", defined in {\ttfamily array.sty}. Thus we
213 % "\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}"\\
214 % and then use {\ttfamily Y} in the {\ttfamily tabularx} preamble
217 % \DescribeMacro{\tabularxcolumn}
218 % The {\ttfamily X} columns are set using the {\ttfamily p} column which
219 % corresponds to "\parbox[t]". You may want them set using, say, the
220 % {\ttfamily m} column, which corresponds to "\parbox[c]". It is not
221 % possible to change the column type using the ">" syntax, so another
222 % system is provided. "\tabularxcolumn" should be defined to be a macro
223 % with one argument, which expands to the {\ttfamily tabular} preamble
224 % specification that you want to correspond to {\ttfamily X}. The
225 % argument will be replaced by the calculated width of a column.
227 % The default is "\newcommand{\tabularxcolumn}[1]{p{#1}}". So we may
228 % change this with a command such as:\\
229 % "\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}"
231 % \subsection{Column widths}
232 % Normally all {\ttfamily X} columns in a single table are set to the
233 % same width, however it is possible to make {\ttfamily tabularx} set
234 % them to different widths.
235 % A preamble argument of "{>{\hsize=.5\hsize}X>{\hsize=1.5\hsize}X}"
236 % specifies two columns, the second will be three times as wide as the
237 % first. However if you want to play games like this you should follow
238 % the following two rules.
240 % \item Make sure that the sum of the widths of all the {\ttfamily X}
241 % columns is unchanged. (In the above example, the new widths still add
242 % up to twice the default width, the same as two standard {\ttfamily X}
244 % \item Do not use "\multicolumn" entries which cross any {\ttfamily X}
247 % As with most rules, these may be broken if you know what you are
250 % \subsection{If the algorithm fails\ldots}
251 % It may be that the widths of the `normal' columns of the table
252 % already total more than the requested total
253 % width. \textsf{tabularx} refuses to set the
254 % \texttt{X} columns to a negative width, so in this case you get a
255 % warning ``X Columns too narrow (table too wide)''.
257 % The \texttt{X} columns will in this case be set to a width of 1em
258 % and so the table itself will be wider than the requested total width
259 % given in the argument to the environment.
260 % This behaviour of the package can be customised slightly
261 % as noted in the documentation of the code section.
265 % \section{The Macros}
271 % \changes{v2.00}{1994/02/07}
272 % {New Option Handling}
274 \DeclareOption{infoshow}{\AtEndOfPackage\tracingtabularx}
275 \DeclareOption{debugshow}{\AtEndOfPackage\tracingtabularx}
279 % This requires {\ttfamily array.sty}.
280 % \changes{v2.00}{1994/02/07}
281 % {Use LaTeX2e's \cmd{\RequirePackage} to load array}
283 \RequirePackage{array}[1994/02/03]
286 % First some registers etc.\ that we need.
288 \newdimen\TX@col@width
289 \newdimen\TX@old@table
297 % Now a trick to get the body of an environment into a token register,
298 % without doing any expansion. This does not do any real checking of
299 % nested environments, so if you should need to nest one {\ttfamily
300 % tabularx} inside another, the inner one must be surrounded by "{ }".
302 % \begin{macro}{\tabularx}
303 % Prior to v1.06, this macro took two arguments, which were saved in
304 % separate registers before the table body was saved by "\TX@get@body".
305 % Unfortunately this disables the "[t]" optional argument. Now just save
306 % the width specification separately, then clear the token register
308 % Finally call "\TX@get@body" to begin saving the body of the table.
309 % The "{\ifnum0=`}\fi" was added at v1.03, to allow "tabularx" to appear
310 % inside a "\halign".^^A
311 % \setbox0=\hbox{\footnotesize"\iffalse{\fi\ifnum0=`}\fi"}^^A
312 % \setbox2=\hbox{\footnotesize"\ifnum0=`{}\fi"}^^A
313 % \footnote{This adds an extra level of grouping,
314 % which is not really needed. Instead, I could use \box0\ here, and
315 % \box2\ below, however the code here would then have to be moved after
316 % the first line, because of the footnote to page 386 of the \TeX{}Book,
317 % and I do not think I should be writing code that is so obscure as to
318 % be documented in a footnote in an appendix called ``Dirty Tricks''!}
320 % This mechanism of grabbing an environment body does have the
321 % disadvantage (shared with the AMS alignment environments) that you
322 % can not make extension environments by code such as
324 %\newenvironment{foo}{\begin{tabularx}{XX}}{\end{tabularx}}
326 % as the code is looking for a literal string "\end{tabularx}" to stop
327 % scanning. Since version 2.02, one may avoid this problem by using
328 % "\tabularx" and "\endtabularx" directly in the definition:
330 %\newenvironment{foo}{\tabularx{XX}}{\endtabularx}
332 % The scanner now looks for the end of the current environment ("foo" in
333 % this example.) There are some restrictions on this usage, the
334 % principal one being that "\endtabularx" must not be inside any "{ }" pairs
335 % ao that the code before "\endtabularx" may be extracted and added to the table body
336 % (prior to version 2.09 "\endtabularx" had to be
337 % the \emph{first} token of the `end code' of the environment).
341 % \changes{v2.02}{1995/03/20}
342 % {New local setting of \cs{TX@}}
343 % \changes{v4.09}{1998/05/13}
344 % {Use \cs{setlength}, so that calc extensions apply. tools/2793}
345 % Allow "\tabularx" "\endtabularx" (but not "\begin{tabularx}"
346 % "\end{tabularx}") to be used in "\newenvironment" definitions.
348 \edef\TX@{\@currenvir}%
351 % "\relax" added at v1.05 so that non-expandable length tokens, like
352 % "\textwidth" do not generate an extra space, and an overfull box.
353 % "\relax" removed again at v4.09 in favour of "\setlength" so if you
354 % use the calc package you can use a width of "(\textwidth-12pt)/2".
356 \setlength\TX@target{#1}%
357 \TX@typeout{Target width: #1 = \the\TX@target.}%
358 \toks@{}\TX@get@body}
363 % \begin{macro}{\endtabularx}
364 % This does not do very much\ldots
365 % \changes{v2.02}{1995/03/20}
368 \let\endtabularx\relax
372 % \begin{macro}{\TX@get@body}
373 % Place all tokens as far as the first "\end" into a token register.
374 % Then call "\TX@find@end" to see if we are at "\end{tabularx}".
376 \long\def\TX@get@body#1\end
377 {\toks@\expandafter{\the\toks@#1}\TX@find@end}
381 % \begin{macro}{\TX@find@end}
382 % If we are at "\end{tabularx}", call "\TX@endtabularx", otherwise
383 % add "\end{...}" to the register, and call "\TX@get@body" again.
387 \ifx\@tempa\TX@\expandafter\TX@endtabularx
388 \else\toks@\expandafter
389 {\the\toks@\end{#1}}\expandafter\TX@get@body\fi}
393 % \begin{macro}{\TX@find@endtabularxa}
394 % \changes{v2.09}{2014/04/22}{macro added}
395 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
396 % \changes{v2.11}{2016/01/03}{Fix to previous change to guard against empty arg 2. (Ulrike Fischer)}
397 % split up the end code, and extract the part that lives in the table body.
399 \long\def\TX@find@endtabularxa
400 #1\endtabularx#2\endtabularx#3\TX@find@endtabularxa{%
401 \ifx\TX@#2\relax\else
402 \toks@\expandafter{\the\toks@#1}%
406 % \begin{macro}{\TX@find@endtabularxb}
407 % \changes{v2.09}{2014/04/22}{macro added}
408 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
409 % split up the end code, and extract the part that lives outside the table body.
411 \long\def\TX@find@endtabularxb
412 #1\endtabularx#2\endtabularx#3\TX@find@endtabularxb{%
414 \expandafter\@firstoftwo
416 \expandafter\@secondoftwo
422 % \begin{macro}{\TX@find@endtabularxbb}
423 % \changes{v2.10}{2014/05/13}{macro added}
424 % Helper to avoid needing 15 consecutive "expandafter"
426 \def\TX@find@endtabularxbb{%
427 \expandafter\expandafter\expandafter
428 \TX@find@endtabularxb
433 % \begin{macro}{\TX@}
434 % The string {\ttfamily tabularx} as a macro for testing with "\ifx".
440 % Now that all the parts of the table specification are stored in
441 % registers, we can begin the work of setting the table.
443 % The algorithm for finding the correct column widths is as follows.
444 % Firstly set the table with each {\ttfamily X} column the width of the
445 % final table. Assuming that there is at least one {\ttfamily X} column,
446 % this will produce a table that is too wide. Divide the excess width by
447 % the number of {\ttfamily X} columns, and reduce the column width by
448 % this amount. Reset the table. If the table is not now the correct
449 % width, a "\multicolumn" entry must be `hiding' one of the {\ttfamily
450 % X} columns, and so there is one less {\ttfamily X} column affecting
451 % the width of the table. So we reduce by 1 the number of X columns and
452 % repeat the process.
454 % \begin{macro}{\TX@endtabularx}
455 % Although I have tried to make {\ttfamily tabularx} look like an
456 % environment, it is in fact a command, all the work is done by this
459 \def\TX@endtabularx{%
461 % \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxa} added}
462 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
464 \expandafter\expandafter\expandafter
465 \TX@find@endtabularxa\csname end\TX@\endcsname
466 \endtabularx\TX@\endtabularx\TX@find@endtabularxa
468 % Define the {\ttfamily X} column, with an internal version of the
469 % "\newcolumntype" command. The "\expandafter" commands enable
470 % "\NC@newcol" to get the {\em expansion} of\\
471 % "\tabularxcolumn{\TX@col@width}" as its
472 % argument. This will be the definition of an {\ttfamily X} column, as
473 % discussed in section 4.
475 \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}%
477 % Initialise the column width, and the number of {\ttfamily X} columns.
478 % The number of {\ttfamily X} columns is set to one, which means that
479 % the initial count will be one too high, but this value is decremented
480 % before it is used in the main loop.
482 % Since v1.02, switch the definition of "\verb".
486 % Since v1.05, save the values of all \LaTeX\ counters, the list
487 % "\cl@@ckpt" contains the names of all the \LaTeX\ counters that have
488 % been defined so far. We expand "\setcounter" at this point, as it
489 % results in fewer tokens being stored in "\TX@ckpt", but the actual
490 % resetting of the counters occurs when "\TX@ckpt" is expanded after
492 % Actually since v1.07, use something equivalent to the expansion of the
493 % original definition of "\setcounter", so that "tabularx" works in
494 % conjunction with "calc.sty".
496 \def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
497 \edef\TX@ckpt{\cl@@ckpt}%
499 \TX@old@table\maxdimen
500 \TX@col@width\TX@target
503 % Typeout some headings (unless this is disabled).
506 {\@spaces Table Width\@spaces Column Width\@spaces X Columns}%
508 % First attempt. Modify the {\ttfamily X} definition to count {\ttfamily
511 \TX@trial{\def\NC@rewrite@X{%
512 \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}%
514 % Repeatedly decrease column width until table is the correct width,
515 % or stops shrinking, or the columns become two narrow.
516 % If there are no multicolumn entries, this will only take one attempt.
524 % One last time, with warnings back on (see appendix D)
525 % use {\ttfamily tabular*} to put it in a box of the right size, in case
526 % the algorithm failed to find the correct size.
528 % Since v1.04, locally make "\footnotetext" save its argument in a token
530 % Since v1.06, "\toks@" contains the preamble specification,
531 % and possible optional argument, as well as the table body.
533 {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext
534 \csname tabular*\expandafter\endcsname\expandafter\TX@target
536 \csname endtabular*\endcsname}%
538 % Now the alignment is finished, and the "}" has restored the original
539 % meaning of "\@footnotetext" expand the register "\TX@ftn" which will
540 % execute a series of\\
541 % "\footnotetext["\meta{num}"]{"\meta{note}"}"\\
542 % commands. We need to be careful about clearing the register as we may
543 % be inside a nested {\ttfamily tabularx}.
545 \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn
547 % Now finish off the {\ttfamily tabularx} environment. Note that we need
548 % "\end{tabularx}" here as the "\end{tabularx}" in the user's
549 % file is never expanded. Now use "\TX@" rather than "tabularx".
550 % \changes{v2.02}{1995/03/20}
551 % {Close the environment \cs{TX@} rather than `tabularx'}
553 % We also need to finish off the group started by "{\ifnum0=`}\fi" in
554 % the macro "\tabularx".
558 % \changes{v2.09}{2014/04/22}{call to \cs{TX@find@endtabularxb} added}
559 % \changes{v2.10}{2014/05/13}{macro modified to test for missing \cs{endtabularx}}
561 \expandafter\expandafter\expandafter
562 \TX@find@endtabularxbb
563 \expandafter\end\expandafter{\TX@}%
564 \endtabularx\TX@\endtabularx\TX@find@endtabularxb
570 % \begin{macro}{\TX@arith}
571 % Calculate the column width for the next try, setting the flag
572 % "\ifTX@" to false if the loop should be aborted.
577 % \changes{v2.08}{2012/02/06}{Avoid exceeding maxdimen during trials}
580 \divide\@tempdimb\TX@cols
581 \ifdim\TX@col@width>\@tempdimb
582 \TX@typeout@{Don't exceed \maxdimen}%
583 \wd\@tempboxa\maxdimen
585 \ifdim\TX@old@table=\wd\@tempboxa
587 % If we have reduced the column width, but the table width has not
588 % changed, we stop the loop, and output the table (which will cause an
589 % over-full alignment) with the previous value of "\TX@col@width".
591 \TX@col@width\TX@old@col
592 \TX@typeout@{Reached minimum width, backing up.}%
595 % Otherwise calculate the amount by which the current table is too wide.
598 \advance\dimen@ -\TX@target
599 \ifdim\dimen@<\TX@delta
601 % If this amount is less than "\TX@delta", stop. ("\TX@delta"
602 % should be non-zero otherwise we may miss the target due to rounding
605 \TX@typeout@{Reached target.}%
608 % Reduce the number of effective {\ttfamily X} columns by one. (Checking
609 % that we do not get 0, as this would produce an error later.) Then
610 % divide excess width by the number of effective columns, and calculate
611 % the new column width. Temporarily store this value (times $-1$) in
615 \advance\TX@cols\m@ne
617 \divide\dimen@\TX@cols
618 \advance\dimen@ -\TX@col@width
621 % If the new width would be too narrow, abort the loop. At the moment
622 % too narrow, means less than 0\,pt!
624 % Prior to v2.03, if the loop was aborted here, the X columns were left
625 % with the width of the previous run, but this may make the table far
626 % too wide as initial guesses are always too big. Now force to
627 % "\TX@error@width" which defaults to be 1em. If you want to
628 % get the old behaviour stick\\
629 % "\renewcommand\TX@error@width{\TX@col@width}"\\
630 % in a package file loaded after \textsf{tabularx}.
631 % \changes{v2.03}{1997/02/20}{Improve warning message and force to 1em.}
633 \PackageWarning{tabularx}%
634 {X Columns too narrow (table too wide)\MessageBreak}%
635 \TX@col@width\TX@error@width\relax
638 % Otherwise save the old settings, and set the new column width. Set the
639 % flag to true so that the table will be set, and the loop will be
642 \TX@old@col\TX@col@width
643 \TX@old@table\wd\@tempboxa
644 \TX@col@width-\dimen@
652 % \begin{macro}{\TX@error@width}
653 % \changes{v2.03}{1997/02/20}{macro added.}
654 % \changes{v2.04}{1997/02/26}{spurious brace removed.}
655 % If the calculated width is negative, use this instead.
657 \def\TX@error@width{1em}
661 % \begin{macro}{\TX@delta}
662 % Accept a table that is within "\hfuzz" of the correct width.
668 % Initialise the {\ttfamily X} column. The definition can be empty here,
669 % as it is set for each {\ttfamily tabularx} environment.
674 % \begin{macro}{\tabularxcolumn}
675 % The default definition of {\ttfamily X} is "p{#1}".
677 \def\tabularxcolumn#1{p{#1}}
681 % \begin{macro}{\TX@newcol}
682 % A little macro just used to cut down the number of "\expandafter"
685 \def\TX@newcol{\newcol@{X}[0]}
689 % \begin{macro}{\TX@trial}
693 \setbox\@tempboxa\hbox{%
695 % Any extra commands. This is used on the first run to count the number
696 % of {\ttfamily X} columns.
700 % Since v1.04, make "\footnotetext" gobble its arguments. Also locally
701 % clear "\TX@vwarn" so that the warning is generated by the {\ttfamily
702 % final} run, and does not appear in the middle of the table if
703 % "\tracingtabularx".
705 \let\@footnotetext\TX@trial@ftn
708 % Do not nest {\ttfamily tabularx} environments during trial runs. This
709 % would waste time, and the global setting of "\TX@cols" would break the
712 \expandafter\let\expandafter\tabularx\csname tabular*\endcsname
713 \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname
715 % Added at v1.05: disable "\write"s during a trial run. This trick is
716 % from the \TeX{}Book.\footnote{Actually the \TeX{}Book trick does
717 % not work correctly, so changed for v2.05.}
718 % \changes{v2.05}{1997/09/18}
719 % {New \cs{write} trick. tools/2607}
720 % \changes{v2.07}{1999/01/07}
721 % {Newer \cs{write} trick. tools/2792}
723 \def\write{\begingroup
724 \def\let{\afterassignment\endgroup\toks@}%
725 \afterassignment\let\count@}%
727 % Turn off warnings (see appendix D). Also prevent them being turned
728 % back on by setting the parameter names to be registers.
732 \let\hbadness\@tempcnta
735 % Make the table, and finish the hbox.
736 % Since v1.06, "\toks@" contains the preamble specification,
737 % and possible optional argument, as well as the table body.
739 \expandafter\tabular\the\toks@
742 % Since v1.05 reset all \LaTeX\ counters, by executing "\TX@ckpt".
746 % Print some statistics.
747 % Added "\TX@align" in v1.05, to line up the columns.
749 \TX@typeout@{\@spaces
750 \expandafter\TX@align
751 \the\wd\@tempboxa\space\space\space\space\space\@@
752 \expandafter\TX@align
753 \the\TX@col@width\space\space\space\space\space\@@
754 \@spaces\the\TX@cols}}
758 % \begin{macro}{\TX@align}
759 % Macro added at v1.05, to improve the printing of the tracing info.
761 \def\TX@align#1.#2#3#4#5#6#7#8#9\@@{%
762 \ifnum#1<10 \space\fi
763 \ifnum#1<100 \space\fi
764 \ifnum#1<\@m\space\fi
765 \ifnum#1<\@M\space\fi
766 #1.#2#3#4#5#6#7#8\space\space}
770 % \begin{macro}{\arraybackslash}
772 % \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.}
774 \ifx\arraybackslash\@undefined
775 \def\arraybackslash{\let\\\tabularnewline}
780 % \begin{macro}{\tracingtabularx}
781 % Print statistics on column and table widths.
783 \def\tracingtabularx{%
784 \def\TX@typeout{\PackageWarningNoLine{tabularx}}%
785 \def\TX@typeout@##1{\typeout{(tabularx) ##1}}}
789 % \begin{macro}{\TX@typeout}
790 % The default is to be to be quiet
792 \let\TX@typeout\@gobble
793 \let\TX@typeout@\@gobble
797 % \begin{macro}{\TX@ftn}
798 % A token register for saving footnote texts.
804 % \begin{macro}{\TX@ftntext}
805 % \begin{macro}{\TX@xftntext}
806 % Inside the alignment just save up the footnote text in a token
809 \long\def\TX@ftntext#1{%
810 \edef\@tempa{\the\TX@ftn\noexpand\footnotetext
811 [\the\csname c@\@mpfn\endcsname]}%
812 \global\TX@ftn\expandafter{\@tempa{#1}}}%
813 \long\def\TX@xftntext[#1]#2{%
814 \global\TX@ftn\expandafter{\the\TX@ftn\footnotetext[#1]{#2}}}
819 % \begin{macro}{\TX@trial@ftn}
820 % On trial runs, gobble footnote texts.
822 \long\def\TX@trial@ftn#1{}
826 % This last section was added at Version 1.02. Previous versions
827 % documented the fact that "\verb" did not work inside {\ttfamily
828 % tabularx}, but that did not stop people using it! This usually put
829 % \LaTeX\ into an irrecoverable error position, with error messages that
830 % did not mention the cause of the error. The `poor man's "\verb"' (and
831 % "\verb*") defined here is based on page 382 of the \TeX{}Book. As
832 % explained there, doing verbatim this way means that spaces are not
833 % treated correctly, and so "\verb*" may well be useless, however I
834 % consider this section of code to be error-recovery, rather than a real
835 % implementation of verbatim.
837 % The mechanism is quite general, and any macro which wants to allow a
838 % form of "\verb" to be used within its argument may
839 % "\let\verb=\TX@verb". (Making sure to restore the real definition
842 % "\verb" and "\verb*" are subject to the following restrictions:
844 % \item Spaces in the argument are not read verbatim, but may be skipped
845 % according to \TeX's usual rules.
846 % \item Spaces will be added to the output after control words, even if
847 % they were not present in the input.
848 % \item Unless the argument is a single space, any trailing space,
849 % whether in the original argument, or added as in (2),
851 % \item The argument must not end with "\", so "\verb|\|" is not
852 % allowed, however, because of (3), "\verb|\ |" produces
854 % \item The argument must be balanced with respect to "{" and "}". So
855 % "\verb|{|" is not allowed.
856 % \item A comment character like "%" will not appear verbatim. It will
857 % act as usual, commenting out the rest of the input line!
858 % \item The combinations "?`" and "!`" will appear as
859 % {\ttfamily?`} and {\ttfamily!`} if the {\ttfamily cmtt} font is
863 % \begin{macro}{\TX@verb}
864 % The internal definition of "\verb". Spaces will be replaced by "~", so
865 % for the star-form, "\let" "~" be \verb*| |, which we obtain as
866 % "\uppercase{*}". Use "{\ifnum0=`}\fi" rather than "\bgroup" to allow
867 % "&" to appear in the argument.
870 \uppercase{\gdef\TX@verb{%
871 \leavevmode\null\TX@vwarn
872 {\ifnum0=`}\fi\ttfamily\let\\\ignorespaces
873 \@ifstar{\let~*\TX@vb}{\TX@vb}}}}
877 % \begin{macro}{\TX@vb}
878 % Get the `almost verbatim' text using "\meaning". The `"!"' is added to
879 % the front of the user supplied text, to ensure that the whole argument
880 % does not consist of a single "{ }" group. \TeX\ would strip the outer
881 % braces from such a group. The `"!"' will be removed later.
883 % Originally I followed Knuth, and had "\def\@tempa{##1}", however this
884 % did not allow "#" to appear in the argument. So in v1.04, I changed
885 % this to to use a token register, and "\edef". This allows "#" appear,
886 % but makes each one appear twice!, so later we loop through, replacing
889 \def\TX@vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}%
890 \expandafter\TX@v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!}
894 % \begin{macro}{\TX@v}
895 % Strip the initial segment of the "\meaning", including the `"!"'
898 \def\TX@v#1!{\afterassignment\TX@vfirst\let\@tempa= }
902 % As explained above we are going to replace "##" pairs by "#". To do
903 % this we need non-special "#" tokens. Make "*" into a parameter
904 % token so that we can define macros with arguments. The normal meanings
905 % will be restored by the "\endgroup" later.
908 \catcode`\*=\catcode`\#
912 % \begin{macro}{\TX@vfirst}
913 % As a special case, prevent the first character from being dropped.
914 % This makes "\verb*| |" produce \verb*| |. Then call "\TX@v@".
915 % This is slightly tricky since v1.04, as I have to ensure that an
916 % actual "#" rather than a command "\let" to "#" is passed on if the
917 % first character is "#".
921 \def\@tempb{\TX@v@#}%
924 \if\@tempa\space~\else\@tempa\fi
930 % \begin{macro}{\TX@v@}
931 % Loop through the "\meaning", replacing all spaces by "~". If the last
932 % character is a space it is dropped, so that "\verb*|\LaTeX|" produces
933 % "\LaTeX" not \verb*|\LaTeX |. The rewritten tokens are then further
934 % processed to replace "##" pairs.
937 \TX@v@hash*1##\relax\if*2\\\else~\expandafter\TX@v@\fi*2}
941 % \begin{macro}{\TX@v@hash}
942 % The inner loop, replacing "##" by "#".
944 \gdef\TX@v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX@v@hash\fi*2}
948 % As promised, we now restore the normal meanings of "#" and "*".
953 % \begin{macro}{\TX@vwarn}
954 % Warn the user the first time this "\verb" is used.
957 \@warning{\noexpand\verb may be unreliable inside tabularx}%
958 \global\let\TX@vwarn\@empty}