[Tex/LaTex] How to use greek letters in pgf-umlsd (or generally terms starting with \)

tikz-pgf

I'm drawing a sequence diagram with pgf-umlsd and I want to incorporate a greek letter in a message description.
Something like \mess[1]{a}{Message $\alpha$}{b}.
While pgf-umlsd seems to allow $ for using the math mode, it apparently does not allow any \ (so I can't write e.g. \alpha).

\protect also doesn't work. Furthermore, I've defined a variable with \def\alph{$\alpha$}, and used it with \mess[1]{a}{Message \alph}{b}, but also to no avail.
If the definition is set to \def\alph{$alpha$}, it works fine but of course doesn't produce an alpha. So, \ is apparently not generally prohibited inside pgf-umlsd message descritiptions.

Is there a possibility to somehow use greek letters?

Here is a minimal example of the problem:

\documentclass{article}                                                                                     
\usepackage{pgf-umlsd}                                                                                      
\begin{document}                                                                                            
\begin{figure} [ht!]                                                                                        
\def\alph{$\alpha$}                                                                                         
\def\bet {$beta$}                                                                                           
\begin{sequencediagram}                                                                                     
    \newthread{a}{Alice}{Alice}                                                                             
    \newthread{b}{Bob}{Bob}                                                                                 
    \mess[1]{a}{Message \alph}{b} %This doesn't compile                                                     
    \mess[1]{a}{Message \bet} {b} %This compiles but generates no greek letter                              
\end{sequencediagram}                                                                                       
\end{figure}                                                                                                
\end{document}                                                                                              

Best Answer

The problem is caused by how \mess is defined (from v0.7 of pgf-umlsd.sty):

\newcommand{\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 (#3 from) at (mess from) {};
  \node (#3 to) at (mess to) {};
}

The third argument (denoted by #3) is the message, but it is also used to define two additional nodes, at the start and end of the arrow, as you can see in the two last lines,

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

I don't know exactly what the limitations are, but having $\alpha$ in a node name doesn't work at least.

Now, if those node names aren't used anywhere, you could just eliminate those nodes, by redefining the command with

\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};    
}

but if they are needed, other things won't work, so this may or may not be helpful.

enter image description here

\documentclass{article}                                                                                     
\usepackage{pgf-umlsd}                                                                                      

\begin{document}                                                                                            
\begin{sequencediagram}                                                                                     
    \newthread{a}{Alice}{Alice}                                                                             
    \newthread{b}{Bob}{Bob}                                                                                 
    \mess[1]{a}{Message alfa}{b} 
    \mess[1]{a}{Message beta} {b}

% draw borders around the above mentioned nodes:
\draw [ultra thick,red] (Message beta from.south east) rectangle (Message beta from.north west);
\draw [ultra thick,green] (Message beta to.south east) rectangle (Message beta to.north west);
\end{sequencediagram}                                                                                       

% redefine the \mess
\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};
}

\begin{sequencediagram}                                                                                     
    \newthread{a}{Alice}{Alice}                                                                             
    \newthread{b}{Bob}{Bob}                                                                                 
    \mess[1]{a}{Message $\alpha$}{b} 
    \mess[1]{a}{Message $\beta$} {b} 

\end{sequencediagram}                                                                                       
\end{document}