答案1
改用。 确实\def\x{Enu}
如此,但tikz 仅如此。如果一个宏由 定义,而另一个宏由定义,则 的两个宏的比较结果为false 。\newcommad
\newcommand
\long\def
\foreach
\def
\ifx
\def
\long\def
答案2
expl3
有一个名为 的函数\str_case:nn(TF)
,它在某种程度上与你想要的相反,但我想对你有用。它将一个字符串与一个字符串列表进行比较。还有\str_if_eq:nnTF
比较两个字符串的功能。我们可以使用 循环遍历逗号分隔的列表\clist_map_inline:nn
。
\documentclass[]{beamer}
% we borrow three functions from expl3
\ExplSyntaxOn
\cs_new_eq:NN \forclist \clist_map_inline:nn
\cs_new_eq:NN \strcaseTF \str_case:nnTF
\cs_new_eq:NN \strifeqTF \str_if_eq:nnTF
\ExplSyntaxOff
\begin{document}
\forclist{x,Enu,y}
{%
\begin{frame}
\frametitle{test}
\strcaseTF{#1}
{
{x} {this is `x'}
{Enu} {this is $E_{\nu}$}
}
{. One was matched.}
{No matches found.}
\end{frame}%
}
\forclist{x,Enu}
{%
\begin{frame}
\frametitle{test2}
\strifeqTF{#1}{Enu}{this is $E_{\nu}$}{this is not $E_{\nu}$}%
\end{frame}%
}
\end{document}
如果您想要坚持(因为它可以用其方便的语法\foreach
做更多的事情),您可以改用和,这将扩展并比较其内容:\clist_map_inline:nn
...
\str_case:onTF
\str_if_eq:onTF
\x
\documentclass[]{beamer}
\usepackage[]{tikz}
% we borrow two functions from expl3
\ExplSyntaxOn
\cs_new_eq:NN \strcaseOTF \str_case:onTF
\cs_new_eq:NN \strifeqOTF \str_if_eq:onTF
\ExplSyntaxOff
\begin{document}
\foreach\x in {x,Enu,y}
{%
\begin{frame}
\frametitle{test}
\strcaseOTF\x
{
{x} {this is `x'}
{Enu} {this is $E_{\nu}$}
}
{. One was matched.}
{No matches found.}
\end{frame}%
}
\foreach\x in {x,Enu}
{%
\begin{frame}
\frametitle{test2}
\strifeqOTF\x{Enu}{this is $E_{\nu}$}{this is not $E_{\nu}$}%
\end{frame}%
}
\end{document}