summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-11-02 22:51:17 +0000
committerKarl Berry <karl@freefriends.org>2011-11-02 22:51:17 +0000
commit6f714441a5f4ecd5bc220e2f50cc98472bc079d0 (patch)
treec82791cc9234223333f0ad5ba4712aa7f0d4286f /Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex
parente5cd5f13085b6988a96d8e68ac5b703be949ad24 (diff)
uk-tex-faq 3.24 (1nov11)
git-svn-id: svn://tug.org/texlive/trunk@24465 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex')
-rw-r--r--Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex109
1 files changed, 108 insertions, 1 deletions
diff --git a/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex b/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex
index ddde1de0ab1..b71fbaece6d 100644
--- a/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex
+++ b/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex
@@ -1,4 +1,4 @@
-% $Id: faq-mac-prog.tex,v 1.23 2011/07/10 22:51:12 rf10 Exp rf10 $
+% $Id: faq-mac-prog.tex,v 1.25 2011/09/09 19:35:14 rf10 Exp rf10 $
\section{Macro programming}
@@ -2481,6 +2481,113 @@ argument, so:
\end{quote}
is needed to produce a replica of the \csx{ghi} we defined earlier.
+\Question[Q-printvar]{How to print contents of variables?}
+\keywords{typeout, print variables, showthe}
+
+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 \csx{textheight} variable are:
+\begin{enumerate}
+\item \csx{showthe}\csx{textheight}
+\item \cmdinvoke{message}{The text height is \csx{the}\csx{textheight}}
+\item \cmdinvoke{typeout}{The text height is \csx{the}\csx{textheight}}
+\end{enumerate}
+These techniques use the \TeX{} primitives \csx{the} (which provides
+the value of a variable), \csx{showthe} (print a variable to the
+terminal and the log, on a line of its own), and \csx{message}, which
+interpolates something into the log. The command \csx{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 \csx{textheight}, just
+\csx{the}\csx{textheight} is enough, but a more flexible alternative is
+to use the \Package{printlen} package. \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 \Package{printlen}, we could say:
+\begin{quote}
+\begin{verbatim}
+\newlength{\foo}
+\setlength{\foo}{12pt}
+\verb|\foo| is \printlength{\foo}
+\end{verbatim}
+\end{quote}
+and get:
+\begin{quote}
+\verb|\foo| is 12pt
+\end{quote}
+while, if we say:
+\begin{quote}
+\begin{verbatim}
+\newlength{\foo}
+\setlength{\foo}{12pt}
+\uselengthunit{mm}
+\verb|\foo| is \printlength{\foo}
+\end{verbatim}
+\end{quote}
+we get:
+\begin{quote}
+\verb|\foo| is 4.21747mm
+\end{quote}
+\begin{ctanrefs}
+\item[printlen.sty]\CTANref{printlen}
+\end{ctanrefs}
+\LastEdit*{2011-09-08}
+
+\Question[Q-labelcount]{Using labels as counter values}
+
+Labels are tempting sources of `numbers'~--- their most common use,
+after all, is simply to typeset a number. However, their seeming
+simplicity is deceptive; the packages \Package{babel} and
+\Package{hyperref}, at least, fiddle with the definition of
+\csx{ref} and \csx{pageref} in ways that make
+\begin{quote}
+\begin{verbatim}
+\setcounter{foo}{\ref{bar}}
+\end{verbatim}
+\end{quote}
+(etc.\@) not work; thus the technique may not be relied upon.
+
+The solution is to use the \Package{refcount} package (incidentally,
+by the author of \Package{hyperref}). The package provides four
+commands, all similar to:
+\begin{quote}
+\begin{verbatim}
+\usepackage{refcount}
+...
+\label{bar}
+...
+\setcounterref{foo}{bar}
+\end{verbatim}
+\end{quote}
+(the other three are \csx{addtocounterref}, \csx{setcounterpageref}
+and \csx{addtocounterpageref}).
+
+The package also provides a command
+\cmdinvoke*{getrefnumber}{label-name} that may be used where a
+`number' value is needed. For example:
+\begin{quote}
+\begin{verbatim}
+... \footnote{foo bar ...\label{foofoot}}
+...
+\footnotemark[\getrefnumber{foofoot}]
+\end{verbatim}
+\end{quote}
+which gives you a second footnote mark reference the the footnote.
+(There is also a command \csx{getpagerefnumber}, of course).
+
+The commands could be used by one determined not to use
+\Package{changepage} to determine whether % ! line break
+\Qref*{the current page is odd}{Q-oddpage}, but it's probably no more
+trouble to use the fully-developed tool in this case.
+\begin{ctanrefs}
+\item[refount.sty]Distributed as part of \CTANref{oberdiek}
+\end{ctanrefs}
+\LastEdit*{2011-09-08}
+
\subsection{\LaTeX{} macro programming}
\Question[Q-fixnam]{How to change \LaTeX{}'s ``fixed names''}