[OS X TeX] LaTeX (2005/12/01) Release Beta Test

Morten Høgholm morten.hoegholm at gmail.com
Sat Feb 11 21:43:33 CET 2006


On Sat, 11 Feb 2006 21:12:48 +0100, Wolfgang Schmidle  
<Wolfgang.Schmidle at sunderland.ac.uk> wrote:

Hi Wolfgang,

Thanks for testing.

> xspace no longer works in the following example:
>
> \documentclass{report}
> \usepackage{xspace}
> \newcommand{\becomes}{$>$\xspace}
> \begin{document}
> A \becomes B
> \begin{tabular}{l@{ \becomes }l}
> A & B \\
> \end{tabular}
> \end{document}
>
> To make it work, I have to replace the second \becomes by its definition
> (without xspace, of course). Why is this so? I'm reluctant to report
> this as a problem because I'm not sure if xspace was ever meant to work
> in such a situation.

The new xspace uses a much more sofisticated procedure for checking what's  
next and in order to keep the code readable, I decided use dedicated  
functions to check what the token really is. The problem with this is  
TeX's concept of \outer control sequences, which aren't allowed in the  
argument of other commands. Here you have found a very, very special  
control sequence indeed, namely \endtemplate (and no, you can't access it  
directly). So TeX barfs. I must admit I never expected anyone to use  
xspace this way but here we are :-)

To emphasize my point about readable code, here is the new definition,  
with dedicated functions (the names should give their meaning away). Note  
that this code has no problems in the cases where \@let at token is equal to  
\ifXXX.

\def\@xspace{%
   \@xspace at lettoken@if at letter@TF \space{%
     \let\@xspace at maybespace\space
     \@xspace at eTeX@setup
     \expandafter\@xspace at check@token
       \@xspace at exceptions@tlp\@xspace at q@nil
     \@xspace at token@if at equal@NNT \space \@xspace at maybespace
     {%
       \@xspace at lettoken@if at expandable@TF
       {\expandafter\xspace}%
       {\@xspace at maybespace\@xspace at hook}%
     }%
   }%
}
\def\@xspace at check@token #1{%
   \@xspace at if@q at nil@NF#1{%
     \@xspace at token@if at equal@NNT#1\@let at token{%
       \let\@xspace at maybespace\relax
       \@xspace at break@loop
     }%
     \@xspace at check@token
   }%
}%


For fun(?) I at one point tried to implement the same algorithm in a way  
that avoids problems with \outer control sequences and also handles \if  
primitives. Pretty nice bit of code, isn't it? To me, this looks  
completely incomprehensible:

\def\@xspace{%
    \ifcat\noexpand\@let at token @%
      \space
    \else
      \let\@xspace at maybespace\space
      \@xspace at eTeX@setup
      \expandafter\@xspace at check@token\@xspace at exceptions@tlp\@xspace at q@nil
      \ifx \space \@xspace at maybespace
        \expandafter\expandafter\expandafter\ifx
        \expandafter\noexpand\csname @let at token\expandafter\endcsname
          \csname @let at token\endcsname
          \@xspace at maybespace\expandafter\expandafter\expandafter
          \expandafter\expandafter\expandafter\expandafter\@xspace at hook
        \else
          \expandafter\expandafter\expandafter\expandafter
          \expandafter\expandafter\expandafter\expandafter
          \expandafter\expandafter\expandafter\expandafter
          \expandafter\expandafter\expandafter\xspace
        \fi
      \fi
    \fi
}
\def\@xspace at check@token #1{%
    \ifx\@xspace at q@nil#1%
    \else
      \expandafter\ifx\csname @let at token\endcsname#1%
        \let\@xspace at maybespace\relax
        \@xspace at break@loop
      \fi
      \expandafter\@xspace at check@token
    \fi
}


Looks like I'll have to use it anyway... sigh. Well, maybe I can introduce
   \def\@xspace at after@elsefififi#1\else#2\fi\fi\fi{\fi\fi\fi#1}
   \def\@xspace at after@fififi #1\fi\fi\fi{\fi\fi\fi#1}
and use them instead of the gazillion \expandafters.

Once again thanks for testing, much appreciated.
-- 
Morten
------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
          & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/




More information about the macostex-archives mailing list