TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am struggling setting up AUCTeX preview in a way that I can use it with XeLaTeX documents. When I try to generate the previews I get the following error


generated by the fontspec package. So I guess I have to force the use of XeLaTeX even when generating previews, but I didn't find anything suitable on the net.

Here is a MWE:


\title{Some title}

and here is the full result:

! Fatal fontspec error: "cannot-use-pdftex"
! The fontspec package requires either XeTeX or LuaTeX to function.
! You must change your typesetting engine to, e.g., "xelatex" or "lualatex"
! instead of plain "latex" or "pdflatex".
! See the fontspec documentation for further information.
! For immediate help type H <return>.


Preview-LaTeX exited as expected with code 1 at Sun Apr 01 09:30:59
LaTeX: LaTeX found no preview images

Setting local variables didn't help.

If I remove:


The error is gone.

In consequence, I guess I need a way to force auctex to compile previews with xelatex.

Any ideas or existing setups?

Some additional information: AUCTeX 11.86 and gs 9.0 on debian wheezy as well as AUCTeX 11.86 on windows 7.

preview of circ.tex works fine

share|improve this question
As you are using preview, you need a .dvi file. LuaLaTeX can generate these, XeLaTeX cannot. (No idea on how to force the use of dvilualatex, I'm afraid.) – Joseph Wright Apr 1 '12 at 8:20
you have to run xelatex with xelatex -no-pdf, but this generates an extended dvi which can only be converted into a pdf with xdvipdfmx – Herbert Apr 1 '12 at 8:31
OK, looks like I have ot understand a little bit more about what happens within preview. Does 'xelatex -no-pdf' create the preview images during a normal run? Or does the preview run only use the dvi file? Are the preview images only created during the 'C-c C-p'? Then 'xelatex -no-pdf' shouldn't help really, right? – louis cypher Apr 1 '12 at 15:33
up vote 5 down vote accepted

XeTeX does not generate .dvi files. Instead, it creates an 'extended .dvi (.xdv) file, which is usually converted straight to PDF format by xdvipdfmx. You can interrupt the process at the .xdv stage using xelatex -no-pdf, but that will not help with preview, as the latter requires a .dvi files. As such, the only way to work with preview and fontspec is to use LuaLaTeX in .dvi mode, using dvilualatex. (I'm not sure how to set that as the engine for AUCTeX, but that would be a separate question!)

share|improve this answer

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.