如何根据状态为LaTeX的变量定义输出?

如何根据状态为LaTeX的变量定义输出?,latex,tex,if-statement,Latex,Tex,If Statement,我有一些标准文本,但有些部分是不同的。但在这些不同的部分中,只有少数几个部分存在 例如,我想要: \mytext{...}{a} \mytext{...}{b} 这将产生: \section{Item: ...}\label{item...} This is a standard item. Items of type a are very precious. \section{Item: ...}\label{item...} This is a standard item. Items

我有一些标准文本,但有些部分是不同的。但在这些不同的部分中,只有少数几个部分存在

例如,我想要:

\mytext{...}{a}

\mytext{...}{b}
这将产生:

\section{Item: ...}\label{item...}
This is a standard item. Items of type a are very precious.

\section{Item: ...}\label{item...}
This is a standard item. Items of type b are cheap.

一个简单的解决方案是定义命令mytexta和mytextb,但由于我有更多的选项,我希望在编程语言中有更多类似if或switch的东西。有人能解决这个问题吗?

您可以使用\newif\iffoo来声明一个新条件。 然后\footrue或\footfalse将其设置为true或false,您可以通过\iffoo\否则\菲


还有更多条件,请参见TeXbook中的第209ff页。

如果包(包含在标准LaTeX安装中)定义了一个命令
\ifthenels
,其使用方式如下:

\usepackage{ifthen}
\ifthenelse{test}{then-code}{else-code}
所以你可以做一些类似的事情:

\newcommand\mytext[1]{%
    \ifthenelse{\equal{#1}{a}}{very precious}{%
    \ifthenelse{\equal{#1}{b}}{cheap}{unknown}}}

对于LaTeX编程,我建议获得一份。这是一个很好的参考资料。

顺便说一句,它应该说“这是一个标准项目”,而不是:-)谢谢,我更正了它。我不是以英语为母语的人。