Difference between \the, \showthe and \show commands?
\show
lets you see (in the log) what the definition of a control sequence is. If it is a macro, you get the definition, for others it tells how it is defined (e.g. whether it is a counter, token list, or length, etc.)
For a non-macro, \the
typesets its value. And \showthe
shows that value in the log file.
\documentclass{article}
\begin{document}
\newlength\somelength
\somelength=10pt
\show\somelength
\the\somelength
\showthe\somelength
\newcommand{\somemacro}[2]{this has #1 and #2}
\show\somemacro
\end{document}
In the log file you get three shows:
> \somelength=\skip43.
l.5 \show\somelength
> 10.0pt.
l.7 \showthe\somelength
> \somemacro=\long macro:
#1#2->this has #1 and #2.
l.9 \show\somemacro
and \the\somelength
prints 10.0pt
in the output document.
Basically, the difference between \the
and \showthe
is that the former inserts its result into the current token stream, for example among other material that TeX is typesetting, while the latter displays its result on the terminal (and in the transcript file) in the form of an error message. See The \the command for a description of what these commands do.
The \show
command is similar to \showthe
in that it displays it results as an error message shown on the terminal, but, instead of returning the current value of some internal quantity, as \showthe
does, it gives the current meaning of a token (typically a control sequence, but, as @egreg has remarked in his comment, \show
works with any token). In practice, the returned information is meaningful only if this token, or control sequence, represents a macro, in which case \show
displays its current definition on the terminal. When the token represent a TeX primitive, \show
just informs you of this fact.
Let’s make an example that can shed some light on the difference: if you say
\show\parindent
TeX will answer with
> \parindent=\parindent.
which is its way of saying that \parindent
is a primitive command (more exactly, in this case, it is a <dimen parameter>
, see The TeXbook, p. 274). On the other hand, if you ask for
\showthe\parindent
TeX might answer, for example
> 20.00003pt.
displaying the current value of the \parindent
parameter. And here’s an example of applying \show
to a token that represents a macro: if you say
\show\mbox
you’ll get the answer
> \mbox=\long macro:
#1->\leavevmode \hbox {#1}.
It works in the same way for macro tokens that are not control sequences: for instance,
\show ~
causes the following reply
> ~=macro:
->\nobreakspace {}.
Last example: \show
applied to a token that represents a primitive command:
\show x
yields
> the letter x.
showing that x
is a primitive command that instructs TeX to add the character for the letter “x” (in the current font) to the current horizontal list.
A loose analogue of \the
for the \show
command is \meaning
, that inserts into the current token stream (for example, into the text being typeset) essentially the same information that \show
would display on the terminal.
It should also be noted that the \the
operation is performed during token expansion (on the contrary, \show
and \showthe
are commands that are executed in TeX’s stomach), and that its result can be used for purposes quite different than typesetting, e.g., they can be used to initialize a macro. A typical idiom is
\edef\savedParindentValue{\the\parindent}
that saves the current value of \parindent
for later use.
As explained in the answers to Using \show in nonstopmode causes TeXmaker to raise false alarms. Any fix?, \show
and \showthe
interrupt TeX just in the same way as for errors (and they cause the process to exit with nonzero code).
If you want to record the value of some parameters in the log file and the terminal, the best is to use \typeout
:
\newcommand{\recordvalue}[1]{%
\typeout{%
*** Vesnog message ***^^J%
Value of \detokenize{#1}: \the#1^^J%
******%
}%
}
Full example:
\documentclass{article}
\newcommand{\recordvalue}[1]{%
\typeout{%
*** Vesnog message ***^^J%
Value of \detokenize{#1}: \the#1^^J%
******%
}%
}
\begin{document}
\recordvalue{\textwidth}
\recordvalue{\count0}
\recordvalue{\value{page}}
\end{document}
Output on the terminal:
*** Vesnog message ***
Value of \textwidth : 345.0pt
******
*** Vesnog message ***
Value of \count 0: 1
******
*** Vesnog message ***
Value of \value {page}: 1
******
Using a distinctive string makes it easier to find the information in the log file.