8

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.

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

then you'll get no hyperlinks.

  • 1
    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
  • 2
    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
  • 2
    then run xelatex with the option -jobname=... – user2478 May 3 '11 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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