这是我在这里的第一篇帖子,尽管我关注这里的帖子很多年了。我试图遵循 stackexchange 的所有规则和指南。如果我没有成功,请给我提示。现在来回答问题。
我怀疑 smartdiagram 包的“添加”功能中存在错误。以下文档编译成功:
\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\begin{document}
\smartdiagramadd[circular diagram]
{$ABC \mathcal{ABC}$}{right of module1/DEF ${DEF}$}
\end{document}
但将简单的 LaTeX 命令(如 \mathcal)添加到附加节点的文本中后,同一文档的编译将失败:
\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\begin{document}
\smartdiagramadd[circular diagram]
{$FOO \mathcal{FOO}$}{right of module1/BAR $\mathcal{BAR}$}
\end{document}
错误信息是
! Undefined control sequence.
\GenericError ...
#4 \errhelp \@err@ ...
l.8 {right of module1/BAR $\mathcal{BAR}$}
如果在“附加”节点中使用其他基本 LaTeX 命令(如 \textbf 或 \small),也会出现类似错误。为了避免此问题,我已尝试过
- 将有问题的代码括在括号中(最多三个)
- 将其括在 \mbox 和 \parbox 中
- \保护它
我的问题是,显然,我是否在这里做错了什么,或者我是否在 smartdiagram 中发现了缺陷。非常感谢您的任何建议!
答案1
嗯,这个包在某个地方没有足够注意扩展。我没有追踪到它到底在哪里失败了,因为你可以给它一点帮助:
\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}
答案2
的使用\StrCut
在扩展方面不够谨慎;应该使用\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}
避免和其怪癖的不同实现\StrCut
。
\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}