8

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}                                                                                              
  • 4
    Could you create a minimal (non-)working example? Just something like \documentclass{article}\usepackage{pgf-umlsd}\begin{document}<add code for a single small diagram with such a message>\end{document}. – Torbjørn T. Mar 10 '14 at 12:00
  • Your minimal example seems to be broken, \usepackage{tikz} \usetikzlibrary{arrows,shadows} needs to be added. – Twig Mar 10 '14 at 14:31
  • @Twig Worked fine here ... pgf-umlsd loads those things. – Torbjørn T. Mar 10 '14 at 14:32
  • Ah ok, i just used which ever one was currently installed, probably from texlive 2013. – Twig Mar 10 '14 at 14:44
5

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} 
6

I suggest two ways for solving your issue.

  1. Redefine \mess to “stringify” the problematic argument in the proper place

  2. Define a \Mess command with an additional optional argument (a string that refers to the text); if the second mandatory argument to \Mess (corresponding to the same place in \mess) is characters only, you don't need to add the label in the optional argument.

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

%%%% First way: redefine \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};

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

%%%% Second way: define a command with a different syntax

\usepackage{xparse}
\NewDocumentCommand{\Mess}{O{0}mmom}{%
  \IfNoValueTF{#4}
    {\xmess{#1}{#2}{#3}{#3}{#5}}
    {\xmess{#1}{#2}{#3}{#4}{#5}}%
}

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

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


\begin{document}

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

\begin{sequencediagram}
\newthread{a}{Alice}{Alice}
\newthread{b}{Bob}{Bob}
\Mess[1]{a}{Message $\alpha$}[malpha]{b}
\Mess[1]{a}{Message $\beta$}[mbeta] {b}
\end{sequencediagram}
\end{document}

enter image description here

1

I'm not sure if this is what you want but here is something similar to your example that works:

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

Image produced by code

I think in general you should avoid raw TeX commands such as \def, and use the LaTeX equivilent of \newcommand or \renewcommand. I didn't have any problems with greek letters, but the way you used pdf-umlsd differed some what from the example code here: http://www.csrdu.org/nauman/2011/11/24/creating-uml-sequence-diagrams-with-tikz-in-latex/ , so that's probably where the error was.

  • Also \alph is already defined, so i changed it to \alphn. \alph{counter} prints the counter as a lowercase letter, a,b,c... – Twig Mar 10 '14 at 14:40
  • I get a Missing \endcsname inserted error with your code. TeX Live 2013, recently updated. – Torbjørn T. Mar 10 '14 at 15:00
  • Sorry, I don't get any errors, so can't fix this one. – Twig Mar 10 '14 at 15:34
  • ah, I seem to be using v0.5 from 2009/09/30 – Twig Mar 10 '14 at 15:36
  • I get the error now with v0.7 – Twig Mar 10 '14 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.