4

This is my first post here, although I follow the posts here for years. I tried to follow all rules and guidelines of stackexchange. If I didn't succees, please give me a hint. Now to the question.

I suspect there is a bug in the "additions" functionality of the smartdiagram package. The following document compiles successfully:

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\begin{document}
\smartdiagramadd[circular diagram]
  {$ABC \mathcal{ABC}$}{right of module1/DEF ${DEF}$}
\end{document}

but the same document with a simple LaTeX command like \mathcal added to the text of the additional node fails to compile:

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\begin{document}
\smartdiagramadd[circular diagram]
  {$FOO \mathcal{FOO}$}{right of module1/BAR $\mathcal{BAR}$}
\end{document}

The error message is

! Undefined control sequence.
\GenericError  ...                                
     #4  \errhelp \@err@     ...
l.8 {right of module1/BAR $\mathcal{BAR}$}

Similar errors occurr if other basic LaTeX commands like \textbf or \small are used in the "additional" node. To avoid the problem, I already tried without success to

  • enclose the offending code in (up to three) parenthesis
  • enclose it in an \mbox and a \parbox
  • \protect it

My question is, obviously, if I doing something wrong here or if I found a flaw in smartdiagram. Many thanks for any advices!

1

Hmm somewhere the package isn't taking enough care over expansion. I didn't trace where exactly it fails as you can give it a bit of help:

enter image description here

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\protected\def\hidefromsomething{$\mathcal{BAR}$}
\begin{document}
\smartdiagramadd[circular diagram]
  {$FOO \mathcal{FOO}$}{right of module1/BAR \hidefromsomething}
\end{document}
  • A lean and efficient workaround, thanks. Yet the answer of egreg makes it superflous. Gives me some hope that one can actually avoid such problems without without unstanding every of its details. – Chris Nov 26 '16 at 13:56
3

The usage of \StrCut is not careful with respect to expansion; it should use \noexpandarg.

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}

\makeatletter
\RenewDocumentCommand{\smartdiagramadd}{r[] m m}{
  \tikzstyle{every picture}+=[remember picture]
  \smartdiagram[#1]{#2}
  \begin{tikzpicture}[
    remember picture,
    overlay,
    every node/.style={align=center,let hypenation},
  ]
  \foreach \smitem [count=\xi] in {#2}  {\global\let\numitems\xi}
  \foreach \smitem[count=\xi] in {#3}{%
    \noexpandarg % <---- added
    \expandafter\StrCut\expandafter{\smitem}{/}\pos\textitem % <---- fixed
    \expandafter\StrCut\expandafter{\pos}{ of }\point\modulenum % <---- fixed
    \node[
      additional item,
      \point=\sm@additions@additionalitemoffset of \modulenum
    ] (additional-module\xi)  {\textitem};
    \ifconnectionsdisabled
    \else
      \begin{pgfonlayer}{smart diagram arrow back}
        \draw[additional item arrow type] (additional-module\xi) -- (\modulenum);
      \end{pgfonlayer}
    \fi
  }%
  \end{tikzpicture}
}
\makeatother


\begin{document}
\smartdiagramadd[circular diagram]
  {$FOO \mathcal{FOO}$}{right of module1/BAR $\mathcal{BAR}$}
\end{document}

enter image description here

A different implementation that avoids \StrCut and its quirks.

\documentclass[draft]{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}

\makeatletter
\RenewDocumentCommand{\smartdiagramadd}{r[] m m}{
  \tikzstyle{every picture}+=[remember picture]
  \smartdiagram[#1]{#2}
  \begin{tikzpicture}[
    remember picture,
    overlay,
    every node/.style={align=center,let hypenation},
  ]
  \foreach \smitem [count=\xi] in {#2}  {\global\let\numitems\xi}
  \foreach \smitem[count=\xi] in {#3}{%
    \expandafter\Cut@At@Slash\expandafter{\smitem}{\xi}%
  }%
  \end{tikzpicture}
}
\NewDocumentCommand{\Cut@At@Slash}{>{\SplitArgument{1}{/}}mm}{\Cut@At@Of#1{#2}}
\NewDocumentCommand{\Cut@At@Of}{>{\SplitArgument{1}{ of }}mmm}{\Make@Node#1{#2}{#3}}
\NewDocumentCommand{\Make@Node}{mmmm}{%
  \node[additional item, #1=\sm@additions@additionalitemoffset of #2]
    (additional-module#4) {\IfValueT{#3}{#3}};
  \ifconnectionsdisabled
  \else
    \begin{pgfonlayer}{smart diagram arrow back}
      \draw[additional item arrow type] (additional-module#4) -- (#2);
    \end{pgfonlayer}
  \fi
}
\makeatother


\begin{document}
\smartdiagramadd[circular diagram]
  {$FOO \mathcal{F}$}{right of module1/BAR $\mathcal{B}$}
\end{document}
  • I tested this answer in great extense, works flawlessly. Thanks a lot. – Chris Nov 26 '16 at 13:54

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.