Command line input (LaTeX2e unofficial reference manual (November 2018))

Next: Recovering from errors, Previous: Command line options, Up: Command line [Contents][Index]

### 28.2 Command line input

As part of the command line invocation `pdflatex options argument` you can specify arbitrary LaTeX input by starting argument with a backslash. 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 for paper and one for a PDF.

    \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. (Note the use of double quotes to prevent interpretation of the symbols by the command line shell; your system may do this differently.)

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.

A final example. This loads the package `graphicx` with the option `draft`

    pdflatex -jobname=aa "\RequirePackage[draft]{graphicx}\input{aa.tex}"

so the graphic files are read for their size information but not incorporated into the PDF. (The `jobname` option is there because otherwise the output file would be `graphicx.pdf`, as `\RequirePackage` does an `\input` of its own.)

Unofficial LaTeX2e reference manual