For programming in C, it is quite common to switch between creating debug- and release-versions by passing a command line argument to the compiler.

I would like to have something similar for pdflatex. Optimally, there would be conditional parts within the source LaTeX file depending on some variable, and then the switching between the versions can be done by somehow setting this variable at the command-line invocation of pdflatex.

Is it possible to achieve something like this? What's the easiest / cleanest way?

  • pdflatex '\def\zz{yes}\input' mainfile – David Carlisle Apr 19 '15 at 11:18
  • @DavidCarlisle: Thank you, that is easier than I thought. I'm declaring my variable internally via \newboolean{variable}, which needs the package ifthen. Is is also possible to assign such a variable a value from the command line? – azimut Apr 19 '15 at 12:22
  • @azimut That's what '\def\zz{yes}\input' does. Alternatively, you could write a small bash script for example who finds the value of the variable in the tex file and compile accordingly. – anderstood Apr 19 '15 at 12:33
  • Use arara, maybe? There is -draftmode but I don't think it is what you want. – cfr Apr 19 '15 at 12:43
  • @cfr: It's not about a draft version. I would like to control from the command line to include certain parts of the document or not. – azimut Apr 19 '15 at 12:45

The following code




yields gagagag when compiled with

pdflatex '\def\val{True}\input' file.tex

and blablabla when compiled with

pdflatex '\def\val{something else}\input' temp.tex

(Credits to David Carlisle, see comments.)

| improve this answer | |

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