I have defined a compilation tool for TeXWorks as follows:

Program: latexmk
Arguments: -e
           $xelatex=q/xelatex $synctexoption %0 %S/

It works fine in most cases, but I'm having problems with one file that imports the hyperref package. Here's a minimal example:

hello, paper!

If I use the (predefined) XeLaTeX compilation tool instead, it works. If I comment the line importing hyperref, it works. But if I try to combine them, I get the following error message:

! Package hyperref Error: Wrong driver option `xetex',
(hyperref) because XeTeX is not detected.

If I remove the xetex option and the import of fontspec, both work, but then I can't choose the fonts I want in my real document.

How do I combine these requirements?

  • Not that I'm having 100% success with hypertext, but my setup for XeLaTeX via latexmk says "$pdflatex=q/xelatex $synctexoption %O %S/" (Note the pdflatex rather than xelatex). But this was very much "monkey fingerpoken", I admit. Feb 27 '12 at 23:04
  • @Brent.Longborough: I don't care if it was "monkey fingerpoken" - it solved my problem =D Feb 29 '12 at 13:35
  • LOL. Chee chee chee. Feb 29 '12 at 16:06

There is a xetex option for hyperref, but it's recommended not using it. In some cases it's necessary to pass hyperref an explicit driver option, but not when using

• LaTeX+dvips
• pdfLaTeX
• XeLaTeX
• LuaLaTeX

because in these cases hyperref is able to detect the driver automatically. The indication of the driver is necessary for

• LaTeX+dvipdfmx

or some other less common engines (VTeX, for instance).

Notice that the same holds for other commonly used packages whose behavior changes depending on the engine and driver used:

graphicx, color, xcolor, geometry

don't need to be passed explicitly a driver name. For geometry it may be necessary when used alongside with crop.

However (thanks to Ulrike Fischer for pointing it out), a xetex options should do no harm if the engine used is XeTeX and raise an error otherwise. So in your case this means that latexmk is not using XeLaTeX for processing your document.

As Brent Longborought remarks, the argument to be passed to latexmk should be

$pdflatex=q/xelatex $synctexoption %0 %S/

(notice pdflatex just after the first $ symbol).

  • 1
    There is a xetex option. hyperref.sty does contain the line \DeclareVoidOption{xetex}. \usepackage[xetex]{hyperref} works fine for me. It gives the error mentioned in the question if used when compiling with e.g. pdflatex – which indicates that latexmk is not using xetex. Feb 28 '12 at 8:46
  • Thanks a lot for the extensive answer! It turns out that Brent was indeed the one to spot my problem - once I changed to $pdflatex instead of what I previously had, everything worked as expected. Feb 29 '12 at 13:36

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.