[tex-eplain] \definexref problem

Oleg Katsitadze geolsoft at mail.ru
Sun Oct 9 22:51:38 CEST 2005


On Sun, Oct 09, 2005 at 06:05:53PM +0000, Adam Fenn wrote:
> fails with the error \end occurred when \iftrue.

The reason is that TeX fully expands the text of the
reference when it writes it out into the .aux file.  You
need to prevent expansion of the command sequences:

  \definexref{mynewref}
             {\string\iflongref\space a long reference\string\longreffalse
              \string\else\space a short reference\string\fi}
             {}

The \string command prevents expansion of the following
command sequence (actually, it replaces the command sequence
with characters constituting the name of that command
sequence); \space is converted into a space character, this
is needed to separate the command sequence name from the
following text in the .aux file.

Another solution is to pass the reference in a toks
register:

  \toks0={\string\iflongref\space a long reference\string\longreffalse
          \string\else\space a short reference\string\fi}
  \definexref{mynewref}{\the\toks0}{}

When TeX writes out the text into a file, \the\toks0 is
expanded only once (unlike macros, which are expanded
_fully_ until only unexpandable tokens remain, see The
TeXbook), so the command sequences "inside" the toks
register are not expanded.

-- 
Best regards,
Oleg Katsitadze



More information about the tex-eplain mailing list