\newif\ifXXX
(2018-02-27 22:09:36)\newif\ifXXX举例
\newif\ifstudent
\def\printstudent{\ifstudent here is a student. \else here is
not a student.\fi}
\studenttrue\printstudent
\studentfalse\printstudent
\studentfalse\printstudent
输出结果为:
here is a student. here is not a student.
\newif 是plain
TeX(LaTeX2ε中依然支持)中创建逻辑变量,变量(variable)、控制序列(control
sequence)、命令(command)、宏(macro)在TeX中基本是同义词的方法,语法很简单:
\newif\ifboolcondition
简单的语法却有不简单的含义!简单的说,这同时创建了三个命令:
\ifboolcondition
创建逻辑变量ifboolcondition(只有true/false两种状态),并根据相应的状态执行相应的代码,需要配合\fi一起使用,即一旦通过\newif创建了逻辑变量ifboolcondition,在实际使用时一般的形式为:
\ifboolcondition
%\ifboolcondition为true时的输出
\else
%\ifboolcondition为false时的输出
\fi
\boolconditiontrue
将 \ifboolcondition 设置为true。注意,这个命令不包含if!
\boolconditionfalse
将 \ifboolcondition 设置为false。注意,这个命令不包含if!
默认的, \newif\ifboolcondition 命令创建一个false状态的逻辑变量
\ifboolcondition ,即 \new\ifboolcondition 等价于: \new\ifboolcondition
\boolconditionfalse 。
有了\newif创建逻辑变量,关于分支的处理就方便多了:在合适的时候使用\xxxtrue或者\xxxfalse设置\xxx逻辑变量的状态,通过监测\xxx的状态决定输出的文本即可。
后一篇:neotheorem计数器更改