
我需要创建参数化变量\mycolor
,例如这个例子。变量\mycolor
根据参数定义颜色。我需要#1
与值 1、2 等进行比较,但如何在 latex 中使用 if else 语句?Google 给出了有关各种算法包的结果。
答案1
然而你的问题还不够清楚
\newcommand\mycolor[1]{%
\ifcase#1%
red%
\or
yellow%
\else
green%
\fi}
\color{\mycolor{2}} xxx
使文本变为绿色。(0=红色 1=黄色 其余均为绿色)