14

According to \show, the pre-defined control sequence \\ is supposed expand to its argument without the suffix "pt":

This is TeX, Version 3.1415926 (TeX Live 2012/Debian)
**\show\\
> \\=macro:
#1pt->#1.
<*> \show\

However, using it fails:

*\message{\\5pt}
! Argument of \\ has an extra }.
<inserted text> 
                \par 
<to be read again> 

When defining a macro that has the same definition as \\, everything works as expected:

*\def\mymacro #1pt{#1}

\show\mymacro
> \mymacro=macro:
#1pt->#1.

*\message{\mymacro5pt}
5

How can this be explained?

  • 2
    This behavior of \\ is undocumented and should not be relied upon. It's used for defining \getf@ctor which, in turn, is used in \sh@ft. – egreg Jul 31 '13 at 9:02
21

What \show doesn't show is that the p and the t are expected to have catcode 12 (other), since they were assigned that catcode when \\ was defined. Your definition of \mymacro is therefore not the same, since here the letters are indeed letters (catcode 11). Why did Knuth define a delimited macro with such strange catcodes? Because this way, \\ can be used to strip the pt when reading a dimen register, which tex outputs with all characters (except space) of catcode other. For example: \expandafter\\\the\fontdimen2\font.

Knuth explains this dirty trick in the TeXbook, p. 375, where it also becomes clear that \\ is just an auxiliary command and, as @egreg comments, shouldn't be relied upon.

The LaTeX2e equivalent for \\ has a (slightly) more telling name: \rem@pt; there is also the handy \strip@pt, which is defined as \expandafter\rem@pt\the, so that you can simply say \strip@pt\@tempdima to strip the pt from \@tempdima. And LaTeX3 provides, with a different syntax, the internal function \__dim_strip_pt:n{<dimension expression>}.

  • Is there a comparable "pt" stripping command in LaTeX? Because up to now, I've gotten around that problem by setting a count variable equal to a length, and it stores it in some internal non-dimensional way. – Steven B. Segletes Jul 31 '13 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.