\documentclass{article}
\usepackage{ifthen}
\newcounter{theyear}
\setcounter{theyear}{\number\year}
\newcommand{\shorttoday}
{
\ifthenelse{\number\month<5}{May, }{\ifthenelse{\number\month <8}{August, }
{\addtocounter{theyear}{1} January, }}\value{theyear}}
\begin{document}
%\number\month
\shorttoday
\end{document}
为什么是这个结果?
Missing number, treated as zero
<to be read again>
\par
l.14
答案1
没有问题\ifthenelse
。但是你放错了位置\value{theyear}
,应该是\thetheyear
,用于打印值。
为什么会出现“缺少数字”错误?您必须知道,它只\value{theyear}
生成计数器的符号名称,而不是其值;当 TeX 找到计数器名称并且它没有查找数字时,它会开始分配,但找不到要分配给计数器的数字。
\documentclass{article}
\usepackage{ifthen}
\newcounter{theyear}
\setcounter{theyear}{\year}
\newcommand{\shorttoday}{%
\ifthenelse{\month<5}%
{May, }%
{\ifthenelse{\month <8}%
{August, }%
{\addtocounter{theyear}{1}January, }%
}%
\thetheyear
}
\begin{document}
\shorttoday
\end{document}
我重新格式化了代码,删除了所有虚假空格以及冗余\number
标记。