加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

\newif\ifXXX

(2018-02-27 22:09:36)
分类: soft-latex-xelatex
\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的状态决定输出的文本即可。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有