将命令行参数传递给 LaTeX 文档 [英] Passing command-line arguments to LaTeX document

查看:27
本文介绍了将命令行参数传递给 LaTeX 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,我会定义如下的新命令.

Sometimes, I define new commands such as the following.


ewcommand{comment}[1]{	extbf{#1}}
%
ecommand{comment}[1]{emph{#1}} 

上述命令使我能够一次更改部分代码的样式.如果我想生成两种可能的样式,我必须编译我的 LaTeX 文档两次,每次修改源代码以启用所需的样式.

The above commands enable me to change the style of parts of my code all at once. If I want to generate both of the possible styles, I have to compile my LaTeX document two times each time modifying the source code to enable the desired style.

有没有办法避免在这种情况下修改源代码?也就是说,我可以传递 latex 一些命令行参数,以便我可以根据该参数选择要使用的样式吗?

Is there a way to avoid the source code modification in such cases? That is, can I pass latex some command-line arguments so that I can choose which style to use based on that argument?

推荐答案

也就是说,我可以传递 latex 一些命令行参数,以便我可以根据该参数选择要使用的样式吗?

That is, can I pass latex some command-line arguments so that I can choose which style to use based on that argument?

是的.三个选项:

在你的源文件中,写

providecommand{comment}[1]{emph{#1}}% fallback definition

然后将LaTeX文档(myfile.tex")编译为

and then compile the LaTeX document ("myfile.tex") as

pdflatex (whatever options you need) "
ewcommandcomment[1]{	extbf{#1}}input{myfile}"

两个

或者,

pdflatex "letifmyflagiftrueinput{myfile}"

然后在源码中有

ifcsname ifmyflagendcsnameelse
  expandafterletcsname ifmyflagexpandafterendcsname
                  csname iffalseendcsname
fi
...
ifmyflag
  
ewcommandcomment[1]{emph{#1}}
else
  
ewcommandcomment[1]{	extbf{#1}}
fi

三个

甚至

pdflatex "defmyflag{}input{myfile}"

ifdefinedmyflag
  
ewcommandcomment[1]{emph{#1}}
else
  
ewcommandcomment[1]{	extbf{#1}}
fi

这可能是最短的,虽然有点脆弱,因为你永远不知道一个包什么时候会在你背后定义 myflag.

which is probably the shortest, albeit slightly fragile because you never know when a package might define myflag behind your back.

这篇关于将命令行参数传递给 LaTeX 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆