TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I decide a Boolean operation in LaTeX via Linux terminal? That is, I have:


if parameter=true
is true
is false


And I wanted to type in something like terminal

pdflatex -p myfile.tex #is true


pdflatex myfile.tex #is false
share|improve this question
Not sure I understand you question, but wondering if Norman's comment on setting class options after document class helps. I have been using that solution. – Peter Grill May 26 '11 at 4:38
Perhaps this answer Passing parameters to a document is what you are looking for? – Alan Munn May 26 '11 at 4:40
up vote 10 down vote accepted

The best way is outlined in Passing parameters to a document, which should be better known. If the document starts as

  <what to do when \flag=0>\or
  <what to do when \flag=1>\or
  <what to do when \flag=2>\or
  <what to do when \flag=n>\else
  <what to do otherwise>\fi

we are free to choose among many cases by calling the compilation through

pdflatex '\def\flag{<value>}\input{myfile}'

One can also choose a "default mode" by enclosing the above code in

   <code above>
   <default setting>

and the call pdflatex myfile will compile with the <default setting>.

Of course the code may also be after the \documentclass declaration, for choosing packages at run time, for example, or different definitions of some command. I'm thinking to a "printable" version (with black colored links) as opposed to a "web" version where links are colored. But with \ifcase we can define as many versions as we want.

For two versions only one can use a simplified version:


and the call

pdflatex '\let\coloredoutput=T\input{myfile}'

will color the links, while

pdflatex myfile

will use no color.

share|improve this answer
Thanks egreg. And thanks all participants. – Regis da Silva May 26 '11 at 22:05
pdflatex '\scrollmode\newif\ifflag\flagtrue\input{myfile.tex}'
pdflatex '\scrollmode\newif\ifflag\flagfalse\input{myfile.tex}'

The \scrollmode makes TeX not to stop in case of errors. It's convenient when used in a Makefile but you could omit it if you are calling pdflatex from the command line.

Inside myfile.tex you can use \ifflag .. \else .. \fi to process your document depending on the value of the flag.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.