[texhax] A new question not in the TeX FAQ

Jeney Gábor jeneyg at hit.bme.hu
Fri Oct 31 13:24:51 CET 2008


Dear TeXhax,

I am an associate professor at the Budapest University of Technology and
Economics, using (and also teaching) LaTeX, and I have the following
question which I have not been able to find any explanation up to now:

inside the \label statement, it is not possible to use the \usebox
command. It is quite strange, since any other commands can be used
there. I show the code which helped me to discover the problem:

\newsavebox{\tabcaption}
\newsavebox{\tablabel}
\newenvironment*{tabl}[3]% #1: caption, #2: label, #3: columns
{\begin{table}[htb]%
\sbox{\tabcaption}{#1}\sbox{\tablabel}{tab:#2}\center%
\begin{tabular}{#3}}
{\end{tabular}
\caption{\usebox{\tabcaption}}\label{\usebox{\tablabel}}
\end{table}}

This is just a new environment, which would ease the usage of tabular
inside table environments, e.g.

\begin{tabl}{Wise statements}{wise}{c|r@{,}l}
Expression & \multicolumn{2}{c}{Value} \\
\hline
$\pi$ & 3&1415927 \\
$\pi^\pi$ & 36&46216 \\
$\pi^{\pi^\pi}$ & 80662&666
\end{tabl}

The problem is that ``tabl'' does not work: during compilation, it
says: 

! Missing \endcsname inserted.
<to be read again> 
                   \unhbox 
l.15 ... \voidb at x \copy \tabcimke \relax }{{5}{3}}


I have found a workaround though: if I declare a new command which
stores the label and I use this command inside the \label statement, it
works (the .aux file must be deleted, of course):

\newcommand{\tablabel}{} % we will redefine this command later
\newsavebox{\tabcaption}
\newenvironment*{tabl}[3]% #1: caption, #2: label, #3: columns
{\begin{table}[htb]%
\sbox{\tabcaption}{#1}\renewcommand{\tablabel}{tab:#2}\center%
\begin{tabular}{#3}}
{\end{tabular}
\caption{\usebox{\tabcaption}}\label{\tablabel}
\end{table}}

This works (it compiles smoothly).
But why \usebox does not work inside \label?
Many thanks in advance for your feedback.

-- 
Best regards,
                            Gábor JENEY
__________________________________________________________
BME, Dep. of Telecommunications, Mobile Innovation Center |
Office: I.B.116, Tel: +36-1-463-2418, Fax: +36-1-463-3263 |



More information about the texhax mailing list