It is often useful to print out the values of variables in the log
file or on the terminal. Three possible ways to print out the
contents of \textheight
variable are:
\showthe
\textheight
\message
{The text height is \the
\textheight
}
\typeout
{The text height is \the
\textheight
}
\the
(which provides
the value of a variable), \showthe
(print a variable to the
terminal and the log, on a line of its own), and \message
, which
interpolates something into the log. The command \typeout
is
LaTeX’s general message output mechanism.
In each case, the variable’s value is printed as a number of points.
To typeset the value of \textheight
, just
\the
\textheight
is enough, but a more flexible alternative is
to use the printlen package. Printlen allows you
to choose the units in which you print a variable; this is useful,
given that the most ordinary people don’t think in points
(particularly Knuth’s points, of which there are 72.27 to the inch).
So, using printlen, we could say:
and get:\newlength{\foo} \setlength{\foo}{12pt} \verb|\foo| is \printlength{\foo}
\foo
is 12pt
while, if we say:
we get:\newlength{\foo} \setlength{\foo}{12pt} \uselengthunit{mm} \verb|foo| is \printlength{\foo}
\foo
is 4.21747mm
This answer last edited: 2012-03-16
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=printvar