Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted
xelatex `\PassOptionsToPackage{draft}{hyperref}\input{yourdoc}`

then you'll get no hyperlinks.

share|improve this answer
Excellent, I never knew about the \input{} command. I've run xelatex "\newif\ifelectronicversion \electronicversionfalse \input{$TEXFILENAME}" and now it carries out my conditional perfectly. Your version might be tidier for that particular use but it's nice that I can answer the question more generally. –  Sam Svenbjorgchristiensensen May 3 '11 at 6:27
This trick is the same as an older answer of Neil Olver's. –  Charles Stewart May 3 '11 at 8:36
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
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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