[texhax] \protect in LaTeX2e

Morten Høgholm moho01ab at student.cbs.dk
Wed Oct 6 13:30:47 CEST 2004

On Tue, 05 Oct 2004 17:55:01 -0400, Alexandru Scorpan  
<ascorpan at math.ufl.edu> wrote:

>> One has to think carefully which commands should be robust and which  
>> not.
> Why do certain commands need to be fragile?  For example, why is  
> \raisebox fragile? (Or ref, for that matter.)

Let me answer \ref first. \ref isn't fragile, rather it is completely  
expandable (in the non-babel case) which is quite important.

   \expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
\section{Test of reference: \ref{test}}\label{test}

Try running this document and observe that the reference doesn't work in  
the header. The reason is \MakeUppercase acts on the text in the header  
but as \ref is robust and thus still appears as \ref{test} it is converted  
to upper case and then executed later on.

The reason for not robustifying commands from the get go had to do with  
speed and memory. Quoting David Carlisle (comp.text.tex on 2000/01/24):

   In the beginning, when latex had to fit on a 1/2 Meg PC and it took
   about 15 minutes per page to run a typical document, it was worth the
   saving of a bit of space and a bit of time to leave commands fragile.

   Now, it's not so clear:-)

Now we have \protected from eTeX which makes it easier on the memory  
because it doesn't take up two strings for each user command. One day  
maybe even \raisebox will be robust, but to be fair, it's not exactly one  
of those commands you use directly in section headings and captions, is it?
Morten Høgholm

More information about the texhax mailing list