# How do I make make different versions of my document with command line compile flags?

I've found a number of answers online, and plainly none of them have seemed to be able to execute any conditional code. This answer looked particularly promising.

One thing I noticed is that in the command line help, xetex (and similarly pdflatex) claim that the COMMANDS part of

xetex [OPTION]... [TEXNAME[.tex]] [COMMANDS]

is latex code that will be processed after the file TEXNAME.tex. Now it occurs to me that this would cause any conditionals which rely on the value of the flags set in COMMANDS to fail, due to the processor not finding the flag value until the end of the file, at which point it is too late. How do I get a command line argument to be interpretted as xetex/latex code which is to be inserted into the document at some point before the \begin{document} element?

The specific problem that I have, is that I want a document that may contain hyperlinks to different parts of the document, but only if I flag it as an electronic copy upon compilation.

-

xelatex \PassOptionsToPackage{draft}{hyperref}\input{yourdoc}

Unfortunately this solution cannot be combined with TikZ external graphics option (because that relies on a \realjobname macro). –  Konrad Rudolph May 3 '11 at 12:27
then run xelatex with the option -jobname=... –  Herbert May 3 '11 at 12:35