21

In the accepted answer in for the question it is suggested how to add latexmk support to emacs. If I get it right, compiling the .tex file should be assigned to C-c C-c. However this doesn't work for me and I have to go to the menu and click the latexmk option.

My question is basically, how do I make the latexmk the default engine for the emacs+auctex?

EDIT 1: When hitting C-c C-c, and then typing latexmk I get the desired result, i.e. it compiles using latexmk. Thus, maybe a more specific question is how to set latexmk to be the default script/compiler.

Dror
  • 22,613

2 Answers2

10

First, look at TeX-command-list to ensure that it has an entry for latexmk. If not, you need to add a line to this variable to allow the executable to be invoked by Auctex; unfortunately this variable is not well-documented (see the manual); I explain a little later.

Second, the default program is specified by the variable TeX-command-default. Change this to the identifier used by TeX-command-list, that is, the string just before the specification of the latexmk command.

E.g., if one of the elements in TeX-command-list is shown (which you can see using C-h v):

 ("Latex Make" "latexmk %(-pdf) %t" TeX-run-TeX)

then TeX-command-default needs to be "Latex Make".

The Auctex variable TeX-command-default

This variable isn't, as I said, well-documented. It should be a list of lists, each of which takes the form:

 '("Handle" "external-command %(switches) %(arguments)" Auctex-handler)

where Handle introduces a handle for facility to be run from the C-c C-c dialog, so the list of handles in TeX-command-default is the list of possible completions at this prompt. The second option is a form specifying the executable to be run, and Auctex-handler is an Elisp function that handles the process and invokes the external command. TeX-run-TeX and TeX-run-command are the most common handlers, but there are special handlers for Bibtex, the spell checkers, etc.

Charles Stewart
  • 21,014
  • 5
  • 65
  • 121
  • 1
    This gave me a hint. In AUCTeX Group->TeX Command->TeX Command List I added (at the beginning of the list) an entry named LaTeXmk with command latexmk -pdf %t and value TeX-run-command. Then, after C-c C-c I could type LaTeXmk and it ran the right script and produced the right result. How can I make it the default? Assign a some key shortcut? – Dror Feb 09 '11 at 08:43
  • How do I set this variable? I couldn't find it in AUCTeX Group->TeX Command... – Dror Feb 09 '11 at 12:11
  • 2
    It's a buffer-local variable, so you can't customise it. You can see its contents using H-v in the buffer you are interested in. You are best off setting it in your file using an Emacs local variable, but the following will set the value in all TeX buffers if you add it to your preamble: (add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "LaTeX Make"))), changing "LaTeX Make" to whatever identifier is used in TeX-command-list. – Charles Stewart Feb 09 '11 at 12:26
  • Seems that is produced what I wanted. Thanks! – Dror Feb 10 '11 at 09:22
  • @CharlesStewart: What is H-v? C-h v? – SabreWolfy Dec 15 '12 at 23:51
  • @SabreWolfy - Yes, the variable-show dialogue. I'll fix my answer. – Charles Stewart Dec 16 '12 at 20:44
  • What's the difference between TeX-run-command and TeX-run-TeX? %(-pdf) (doesn't work for me) and just -pdf by itself (which works)? How do I get latexmk to jump to an error in my document like the other commands do? – Andrew Mao Jan 10 '13 at 19:35
  • @Andrew (sorry for delay- I've been away from Stack Exchange recently): TeX-run-TeX is a wrapper around TeX-run-command that tries to use its knowledge of the Tex format to to parse logs - you will only get jumping to errors with TeX-run-TeX. I don't know why "latexmk %(-pdf)" isn't working - try "latexmk -pdf %s", but you won't be able to get DVI output if you do that. – Charles Stewart Jan 22 '13 at 08:50
1

I guess you simply want to get all of the necessary file compiled, not necessarily by latexmk. The simplest way to achieve this is to run C-c C-a, which executes TeX-command-run-all.

xuhdev
  • 1,083