3

I thought that the construction \wd\bopxcontrolsequence was expandable. But in mucking around in things, it seems not to be. At least in the following, the code demonstrates that \wd\aetmpbox never gets fully expanded in the definition of \aewidth.

\documentclass{article}
\usepackage{pgffor}
\newsavebox\aetmpbox
\begin{document}

\def\aewidth{0pt}%%
\foreach \myitem in {first,a,a bit longer,shorter,very very very very very long}
{\savebox\aetmpbox{\myitem}%%
 \ifdim\wd\aetmpbox>\aewidth\relax
    \xdef\aewidth{\wd\aetmpbox}%%
    \typeout{---> \detokenize\expandafter{\aewidth} :L: \myitem }%%
  \else 
    \typeout{---> \detokenize\expandafter{\aewidth} :s: \myitem }%%
  \fi
}

hello

\end{document}

What I did not want to have to create a new length (for whatever reason). I just wanted to get the value for the width of my box to be saved in the macro \aewidth for later use.

A.Ellett
  • 50,533

1 Answers1

5

\wd is an unexpandable primitive; \aetempbox is a chardef token, so it's unexpandable. Hence

\xdef\aewidth{\wd\aetmpbox}

is exactly the same as \def\aewidth{\wd\aetmpbox}

However, \the is expandable!

\xdef\aewidth{\the\wd\aetmpbox}

See The \the command

egreg
  • 1,121,712