How to set the value of a toggle (from etoolbox package) with command line ?

I would like to create cmd file to compile latex file with different toggle value (i.e. one cmd fiel will compile wiht the toggle foo set to true, and an other cmd file will compile with the toggle foo set to false).

  • I remember reading the solution somewhere a few days ago but can't find it again.
    – Matheod
    Aug 8, 2019 at 0:23

2 Answers 2


It's possible to do

pdflatex.exe -jobname=prof "\AtBeginDocument{\toggletrue{prof}} \input{main}"


echo \AtBeginDocument{\toggletrue{prof}} > _temp.tex
echo \input{main} >> _temp.tex
pdflatex.exe -jobname=prof _temp.tex
del _temp.tex
  • 1
    It seems easier to use pdflatex.exe -synctex=1 -interaction=nonstopmode \AtBeginDocument{\toggletrue{prof}} \input{main}
    – Werner
    Aug 8, 2019 at 0:45
  • It miss the quote but it work, thanks !
    – Matheod
    Aug 8, 2019 at 0:52

Found the solution I read before : https://en.wikibooks.org/wiki/LaTeX/Macros#Command-line_LaTeX

If you work on a Unix-like OS, you might be using Makefiles or any kind of script to build your LaTeX projects. In that connection it might be interesting to produce different versions of the same document by calling LaTeX with command-line parameters. If you add the following structure to your document:

% default value. \providecommand\blackandwhite{false} %...

\ifthenelse{ \equal{\blackandwhite}{true} }{ % "black and white" mode;
do something.. }{ % "color" mode; do something different.. }

Now you can call LaTeX like this:

latex '\providecommand{\blackandwhite}{true}\input{test.tex}'

First the command \blackandwhite gets defined and then the actual file is read with input. By setting \blackandwhite to false the color version of the document would be produced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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