# [OS X TeX] Math mode in TikZ question

Morten Høgholm morten.hoegholm at gmail.com
Sat Jan 19 16:47:19 EST 2008

On Fri, 18 Jan 2008 22:03:00 +0100, Dietrich, Daniel L wrote:

> I can work around it using the other two, but I
> don't know why '\:' gives an error.  I'm not that proficient in LaTeX
> and tikz, so I'm probably missing something simple.

The solution is to grab a more recent version.

But I will shed some light on it (if you want, else just stop reading :-).
Modelled on the LaTeX kernel definition of \@ifnextchar, the version you
have includes the following piece of code:

\long\def\pgf at ifnextchar#1#2#3{%
\let\reserved at d=#1%
\def\reserved at a{#2}%
\def\reserved at b{#3}%
\futurelet\pgf at let@token\pgf at ifnch}
\def\pgf at ifnch{%
\ifx\pgf at let@token\pgf at sptoken
\let\reserved at c\pgf at xifnch
\else
\ifx\pgf at let@token\reserved at d
\let\reserved at c\reserved at a
\else
\let\reserved at c\reserved at b
\fi
\fi
\reserved at c}
\def\:{\global\let\pgf at sptoken= } \:
\def\:{\pgf at xifnch} \expandafter\def\: {\futurelet\pgf at let@token\pgf at ifnch}

The purpose of the last two lines is to make the control sequence
\pgf at xifnch also remove a space token so that the \futurelet doesn't see
the same space token over and over again.
\def\pgf at xifnch {\futurelet\pgf at let@token\pgf at ifnch}
doesn't work, therefore \: is used because a space after it is not
ignored. This works in the LaTeX kernel because \: is given a new
definition afterwards but is is rather bad coding style: If you want to
use temporary variables also used elsewhere ensure a) it all happens in a
group, b) they are erased immediately or c) the user can't use the
temporary variable.

A better method IMNSHO is something such as
\@firstofone{\global\let\pgf at sptoken= } % space, not EOL
\@firstofone{\def\pgf at xifnch} {\futurelet\pgf at let@token\pgf at ifnch}

A more generic method allowing to gobble any kind of token is found in the
l3token module in the expl3 code from the LaTeX Project web site.

Cheers,
--
Morten