Next: , Previous: , Up: Command line interface   [Contents][Index]


28.2 Command line input

As part of the command line invocation

latex-engine options argument

you can specify arbitrary LaTeX input by starting argument with a backslash. (All the engines support this.) This allows you to do some special effects.

For example, this file (which uses the hyperref package for hyperlinks) can produce two kinds of output, one to be read on physical paper and one to be read online.

\ifdefined\paperversion        % in preamble
\newcommand{\urlcolor}{black}
\else
\newcommand{\urlcolor}{blue}
\fi
\usepackage[colorlinks=true,urlcolor=\urlcolor]{hyperref}
  ...
\href{https://www.ctan.org}{CTAN}  % in body
  ...

Compiling this document book.tex with the command line pdflatex book will give the ‘CTAN’ link in blue. But compiling it with

pdflatex "\def\paperversion{}\input book.tex"

has the link in black. We use double quotes to prevent interpretation of the symbols by the command line shell. (This usually works on both Unix and Windows systems, but there are many peculiarities to shell quoting, so read your system documentation if need be.)

In a similar way, from the single file main.tex you can compile two different versions.

pdflatex -jobname=students "\def\student{}\input{main}"
pdflatex -jobname=teachers "\def\teachers{}\input{main}"

The jobname option is there because otherwise both files would be called main.pdf and the second would overwrite the first. (See the next section.)

In this example, we pass the draft option to the graphicx package:

pdflatex "\PassOptionsToPackage{draft}{graphicx}\input{aa.tex}"

so the graphic files are read for their bounding box size information but replaced in the PDF by a box with same size and that contains only the file name, which speeds up compilation time and saves printer ink.


Unofficial LaTeX2e reference manual