# smartdiagram “additions” with LaTeX commands fail to compile

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}
\begin{document}
{$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}
\begin{document}
{$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!

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:

\documentclass{article}
\usepackage{smartdiagram}
\protected\def\hidefromsomething{$\mathcal{BAR}$}
\begin{document}
{$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

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

\documentclass{article}
\usepackage{smartdiagram}

\makeatletter
\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\StrCut\expandafter{\smitem}{/}\pos\textitem % <---- fixed
\expandafter\StrCut\expandafter{\pos}{ of }\point\modulenum % <---- fixed
\node[
\ifconnectionsdisabled
\else
\begin{pgfonlayer}{smart diagram arrow back}
\end{pgfonlayer}
\fi
}%
\end{tikzpicture}
}
\makeatother

\begin{document}
{$FOO \mathcal{FOO}$}{right of module1/BAR $\mathcal{BAR}$}
\end{document}

A different implementation that avoids \StrCut and its quirks.

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

\makeatletter
\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}{%
\ifconnectionsdisabled
\else
\begin{pgfonlayer}{smart diagram arrow back}
{$FOO \mathcal{F}$}{right of module1/BAR $\mathcal{B}$}