我正在尝试使用 etoolbox \ifblank
(及其同类\notblank
),但我想扩展其测试语句中的任何宏。例如:
\documentclass{article}
\usepackage{etoolbox}
\begin{document}
\newtoggle{longformt}
\newcommand{\longform}{\toggletrue{longformt}}
\newcommand{\iflong}[2]{\iftoggle{longformt}{#1}{#2}}
\newcommand{\quoteifnotblank}[1]{%
\notblank{#1}{``#1''}{}%
}
% Try commenting this line.
\longform
This should be completely blank if the form is short:
\quoteifnotblank{\iflong{Some long quoted text}{}}
\end{document}
这里的问题是,\notblank
它将 的参数视为\iflong{Some long quoted text}{}
字符串,而不是要扩展的代码,因此总是会出现引号。如何在将参数传递给 之前对其进行扩展\notblank
?
答案1
\notblank
没有扩展它的参数,所以你必须自己做:
\documentclass{article}
\usepackage{etoolbox}
\newtoggle{longformt}
\newcommand{\longform}{\toggletrue{longformt}}
\newcommand{\iflong}[2]{\iftoggle{longformt}{#1}{#2}}
\makeatletter
\newcommand{\quoteifnotblank}[1]{%
\protected@edef\@tempa{#1}%
\expandafter\notblank\expandafter{\@tempa}{``#1''}{}%
}
\makeatother
\begin{document}
This should be completely blank if the form is short:
\quoteifnotblank{\iflong{Some long quoted text}{}}
\longform
This should be completely blank if the form is short:
\quoteifnotblank{\iflong{Some long quoted text}{}}
\end{document}