0

Is there a way to cause AUCTeX to automatically generate the line

%%% TeX-engine: luatex

in a new .tex document as it does with other file-variables, such as TeX-master?

  • 1
    So you prefer a per-document setting rather than making luatex the default engine just for you? (I think this is a good way to go). Note that if you try to compile a document that loads fontspec package, AUCTeX will ask you to select a proper engine – giordano May 31 '17 at 19:14
  • @giordano: What do you mean by 'I think this is a good way to go'? That the per-document setting is a good way to go, or that making luatex the default engine just for me is a good way to go? – Evan Aad May 31 '17 at 19:25
  • 1
    The former, because you don't rely on people's default options :-) – giordano May 31 '17 at 19:27
  • 1
    With a recent version of AUCTeX, do C-c C-m usepackage RET fontspec RET in your .tex file and AUCTeX will ask you for an engine with completion incl. adding your choice to your file. – Arash Esbati May 31 '17 at 20:10
  • 1
    Yes, I got your question (and provided an answer ;-), and yes, I know that fontspec is not mandatory (like it isn't mandatory to set any font with pdftex), but it's often used. – giordano May 31 '17 at 23:41
3

Add the following code to your init file:

(add-hook
 'find-file-hook
 (lambda ()
   (when (eq major-mode 'latex-mode)
     ;; Check if we are looking at a new or shared file.
     (when (or (not (file-exists-p (buffer-file-name)))
           (eq TeX-master 'shared))
       (add-file-local-variable
    'TeX-engine
    (intern (completing-read "Add TeX-engine with value: "
                 (mapcar 'car (TeX-engine-alist)) nil nil nil nil "default"))))
     (TeX-update-style t))))

This is inspired by how AUCTeX asks you for master file when you create a new file.

  • Thank you. And to set LuaTeX as the Emacs-wide default, the following line should be added to .emacs, right? (setq-default TeX-engine 'luatex) – Evan Aad Jun 1 '17 at 5:40
  • Also: could you please modify your answer so that if I simply hit Enter in reply to the question Add TeX-engine with value: without specifying a value, the current default value (pdfTeX?) will be selected, or better yet, the TeX-engine file-variable won't get written at all, which is the current behavior? – Evan Aad Jun 1 '17 at 6:01
  • 1
    I've updated the answer so that `default' is the default engine (also because it's slightly simpler than adding nothing with empty input). BTW, you should also check out an autocompletion package like helm & Co ;-) – giordano Jun 1 '17 at 8:01
  • Thank you very much. By the way, I've just noticed something. The mode file-variable is set automatically to latex regardless of the TeX-engine setting. Is this the correct behavior? To make the question more concrete, if my .tex document is written in the LuaLaTeX dialect and I wish to compile it with the luatex program, is it enough to set the TeX-engine file-variable to luatex or will the fact that the mode file-variable is set to latex cause any trouble? Does the mode file-variable definition need to be deleted, or changed, say, to lualatex? – Evan Aad Jun 1 '17 at 8:17
  • 2
    latex-mode is to distinguish between plain TeX, LaTeX, docTeX, ConTeXt, TeXinfo, see gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks It has nothing to do with the actual engine used ;-) AUCTeX is one of the few editors I know that correctly keeps the language and the engine used separated: e.g., you can compile with luatex engine a plain TeX document. – giordano Jun 1 '17 at 8:33

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.