# W3cubDocs

/LaTeX

### 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.

In this example, one passes 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.

© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/Command-line-input.html