18

I edit tex file in Emacs, and compile it by C-c C-c, then LaTeX command. Another way to compile it is to use latex file.tex in a terminal.

Now, I would like to compile a file with xelatex, xelatex file.tex works already in a terminal line. So I want to make C-c C-c in Emacs be able to launch either LaTeX or XeLaTeX. Ideally, XeLaTeX should be added to the list of possible commands.

Here is the current .emacs, could anyone help?

SoftTimur
  • 5,630
  • 38
  • 140
  • 292

2 Answers2

13

Say

M-x customize-group

and

tex-command

Then find the "Tex Command List" option. From there you can introduce new AUCTeX commands.

However, AUCTeX is meant to be used a little differently. Instead of creating a separate XeLaTeX command, you can do

  • M-x TeX-engine-set followed by xetex or
  • (TeX-engine-set 'xetex) in lisp code or
  • Command | TeXing Options | Use XeTeX engine in the menu bar

(the three methods are equivalent).

After that the LaTeX command will run xelatex instead of latex.

shakurov
  • 2,358
  • 24
  • 27
  • Thanks for your answer, that works... But how could I set `Use XeTeX engine` as default? I guess I still need to modify `.emacs`. – SoftTimur Apr 10 '13 at 14:08
  • 2
    The default can be changed by `M-x customize-variable` and then `TeX-engine`. You can also call `(setq TeX-engine 'xetex)` in some hook, but be aware that the `TeX-engine` variable automatically becomes buffer-local in that case. – shakurov Apr 10 '13 at 14:13
  • 1
    Many thanks for your answer - saved me a whole bunch of trouble... - for me I could just go to <> then <> – tom Aug 31 '16 at 11:12
  • 1
    Is there a way to do the menu bar Command > TeXing Options > Use XeTeX engine without the menu bar, which I have hidden by default? Thanks! – Lino Ferreira Apr 28 '20 at 17:44
  • `M-x TeX-engine-set` followed by `xetex` (or `(TeX-engine-set 'xetex)` in lisp code). You can also open the menu `F10` (the default binding for `menu-bar-open`) and go from there. – shakurov Apr 30 '20 at 11:24
1

A more local way to specify the TeX-engine is to append the following text to the very end of your .tex file. This will set TeX-engine to xetex for the current file only.

%%% Local Variables:
%%% TeX-engine: xetex
%%% End:

Edit in reply to comment

The same answer was given here: https://tex.stackexchange.com/a/450955/90321, but that answer also shows how to call Tex-engine with command line arguments, by adding another line to the local variables:

%%% TeX-command-extra-options: "-shell-escape" 
leitungswasser
  • 228
  • 3
  • 6
  • How can I use this same lines to pass extra arguments? I need to pass `-shell-espace` – Alexandre Rademaker Feb 10 '21 at 23:56
  • @AlexandreRademaker, I edited the answer regarding your question. – leitungswasser Feb 12 '21 at 12:18
  • @leitungswasser Great answer! Also wondering, how can I set this up so that only certain specific project is compiled with XeLaTeX, while the remaining ones are still handled with pdflatex? I have a lot of files in the intended project so I don't really want to change the bottom text of each single file. – Daniel Oct 27 '21 at 06:37
  • To answer my own question: of course, simply use local variables (```add-dir-local-variable``` and then ```TeX-engine```). – Daniel Oct 27 '21 at 06:56