我正在尝试比较这样的章节编号:
\newcounter{exerciseChapterCounter}
\newcounter{exerciseChapterCounter}
\newcounter{exerciseQuestionCounter}
\setcounter{exerciseChapterCounter}{1}
\setcounter{exerciseQuestionCounter}{0}
\newcommand{\exercise}{
\if \value{chapter} > \exerciseChapterCounter
\stepcounter{exerciseChapterCounter}
\setcounter{exerciseQuestionCounter}{1}
\else
\stepcounter{exerciseQuestionCounter}
\fi
\section*{Exercise \arabic{exerciseChapterCounter}-\arabic{exerciseQuestionCounter}}
}
但是,\if 部分似乎没有被击中。
答案1
我已更新我的代码以使用\ifnum
:
\newcounter{exerciseChapterCounter}
\newcounter{exerciseQuestionCounter}
\setcounter{exerciseChapterCounter}{1}
\setcounter{exerciseQuestionCounter}{0}
\newcommand{\exercise}{
\ifnum \value{chapter}>\value{exerciseChapterCounter}
\stepcounter{exerciseChapterCounter}
\setcounter{exerciseQuestionCounter}{1}
\else
\stepcounter{exerciseQuestionCounter}
\fi
这有效。感谢 Phelype Oleinik 的帮助。