Passing command-line arguments to LaTeX document

Viewed 27218

Sometimes, I define new commands such as the following.

\newcommand{\comment}[1]{\textbf{#1}}
%\necommand{\comment}[1]{\emph{#1}} 

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.

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?

4 Answers

This may not be the optimal solution for the situation in question (also a very old post), but I thought I'd present an alternative solution which was useful for me. It is simply to define the two commands in two different files, link a third file to the desired choice, and \input that third file. For example, define:

% in main.tex
\input{options}
% ...

.

% in option1.tex
\newcommand{\comment}[1]{\textbf{#1}}

.

% in option2.tex
\newcommand{\comment}[1]{\emph{#1}} 

Then to compile with option1, simply run:

> ln -s option1.tex options.tex && pdflatex main.tex

I prefer this because I am more comfortable with bash than obscure latex, have no problem with a proliferation of files (these can easily be organized in subdirectories), and have scripts compile my document anyway so this additional step comes at little cost.

Related