[Tex/LaTex] tikz pgf: Missing \endcsname inserted

math-modetikz-pgf

I am getting the following error when trying to use mathematic symbols as part of a message caption:

Missing \endcsname inserted

Here is a working minimal example:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgf-umlsd}
\usepgflibrary{arrows} % for pgf-umlsd
\usepackage{verbatim}

\begin{comment}
\end{comment}

\begin{document}

\begin{figure}[!h]
    \centering
        \tikzset{font=\scriptsize}
    \begin{sequencediagram}
    \footnotesize
        \newinst{p}{Prover}
        \newinst[2.6]{v}{Verifier}

        \mess[0]{p}{{$\epsilon$}}{v}{};    % LOCATION OF ERROR
        \node[below {$\epsilon$} to, font=\centering] {$test$};
    \end{sequencediagram}
\caption{\scriptsize Sequence diagram of the device authentication protocol.}   
\label{fig:protocolsAuth}
\end{figure}

\end{document}

There is no problem if no latex macros are used but numbers, text, etc. inside the math mode instead.

Best Answer

The label in the third argument of \mess is also reused as part of a node name. Therefore the text is very restricted. The following example redefines \mess to make the argument safe for use in node names by using \detokenize:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgf-umlsd}
\usepgflibrary{arrows} % for pgf-umlsd
\usepackage{verbatim}
\usepackage{caption} 
\captionsetup{font=scriptsize}

\renewcommand{\mess}[4][0]{
  \stepcounter{seqlevel}   
  \path
  (#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
  \addtocounter{seqlevel}{#1}
  \path
  (#4)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
  \draw[->,>=angle 60] (mess from) -- (mess to) node[midway, above]
  {#3};

  \node (\detokenize{#3} from) at (mess from) {};
  \node (\detokenize{#3} to) at (mess to) {};
}

\begin{comment}
\end{comment}  

\begin{document}

\begin{figure}[!h]
    \centering
        \tikzset{font=\scriptsize}
    \begin{sequencediagram}
    \footnotesize
        \newinst{p}{Prover}
        \newinst[2.6]{v}{Verifier}

        \mess[0]{p}{$\epsilon$}{v}{};

    \end{sequencediagram}
\caption{Sequence diagram of the device authentication
protocol.}   
\label{fig:protocolsAuth}
\end{figure}

\end{document}

Result

Related Question