有人可以解释为什么在命令中使用时不尊重\setbool
(from )etoolbox
仅有的用于脚注?
\documentclass[12pt]{article}
\usepackage{etoolbox}
\newcommand{\longshort}[1][]{%
\providebool{ls}%
\ifbool{ls}%
% bool = true = not first time
{This is the #1 time\ldots}%
% bool = false = first time
{This is the first time the command is used!}%
\setbool{ls}{true}%
}
\begin{document}
1:% \longshort%
\footnote{\longshort[2nd]}
2:% \longshort[3rd]
\footnote{%
% \providebool{ls}% uncomment these two lines to get
% \setbool{ls}{true}% expected behaviour
\longshort[4th]}
\end{document}
答案1
正确的定义\longshort
应该是:
\providebool{ls}%
\newcommand{\longshort}[1][]{%
\ifbool{ls}%
% bool = true = not first time
{This is the #1 time\ldots}%
% bool = false = first time
{This is the first time the command is used!}%
\global\booltrue{ls}%
}
其中ls
设置为true
带有\global
前缀。否则,赋值不会在其所调用的组中继续存在。此外,ls
定义为外部 \longshort
。