2

When I hit C-c C-c to compile a document, my system is set up such that LaTeXmk is default typesetting option, and I just hit Enter to run it.

The next time I do C-c C-c (without any changes in the document), however, BibTeX is the default, not LaTeXmk. If I choose LaTeXmk, it runs, and says "LaTeXmk: nothing to do", which is fine. I'd just like to avoid writing LaTeXmk in the second run, if possible.

Any ideas how I can do this?

4
  • How do you define the 'second run'?
    – Marijn
    Mar 5, 2018 at 15:33
  • Well, actually I just mean pressing C-c C-c again. I guess what I'd like is to be able to define what happens the second time the command is issued. Mar 6, 2018 at 19:39
  • But what would you like to happen when you change something between the two compilations that needs a rerun of latexmk?
    – Marijn
    Mar 6, 2018 at 20:16
  • Let's say I compile my document, then i go away for a cup of coffee, and when I return, I forgot if I am looking at the most recent version. So I compile again. I guess I'd like to just make C-c C-C invoke latexmk every time. I'm unsure how to do it. Is it possible to remove the other entries in TeX-command-list somehow? Mar 8, 2018 at 7:42

2 Answers 2

8

Short answer: AUCTeX doesn't play very well with latexmk, by default.


Long answer: AUCTeX has its own system to decide what command to run next, when building a document. This is based on reading the output of compilation program, but it expects only one command has been actually run. Instead, latexmk runs multiple commands in a row, making AUCTeX confused. That's why the short answer.

One solution could be to write a parser specific to latexmk, but this isn't super-easy.

However, note that AUCTeX is capable of automatically running all commands needed to build a document. Just issue C-c C-a and you're done (the output document will also be shown automatically). See also the manual. In order for this to work, "LaTeX" should be the default command to be run, not the custom entry you added for latexmk. The existence of this feature of AUCTeX is the reason why no one ever had the need to write the parser to make latexmk play nicer with AUCTeX

3
  • 1
    Thanks for the clear explanation. Then, I wonder what the proper AUCTeX way is to switch default commands depending on the directory or project? With latexmk, you can place a configuration file in the current directory to change the behavior of latexmk .
    – Ryo
    Aug 29, 2019 at 3:17
  • What you mean by command? The engine (like tex, xetex, luatex)? If so, you can set TeX-engine, see gnu.org/software/auctex/manual/auctex.html#Processor-Options
    – giordano
    Aug 29, 2019 at 7:08
  • 1
    A parser for latexmk is available: github.com/tom-tan/auctex-latexmk. Not perfect, but good enough. For me the advantage of latexmk over TeX-command-run-all is that it is easy to add extra rules, and that my emacs workflow matches my terminal workflow. Also, C-c C-a has confusing bindings, relying on prefix arguments unlike C-c C-c, C-c C-b, C-c C-z, C-c C-r... Ergonomically, I believe that a better choice would be to include a "Latex (all)" option in the command list... and it's exactly what Latexmk does.
    – T. Verron
    Feb 19, 2020 at 10:29
0

I rubber might suite your needs here. If you are on debian apt-get install rubber would suffice.

then in your .emacs

(eval-after-load "tex"
  '(progn
 (add-to-list 'TeX-expand-list
          '("%(RubberPDF)"
        (lambda ()
          (if
              (not TeX-PDF-mode)
              ""
 (add-to-list 'TeX-command-list
        '("Rubber" "rubber %(RubberPDF) %t --shell-escape --synctex" TeX-run-shell nil t) t)))
         "--pdf --shell-escape --synctex"))))


(defun rubber ()
  (interactive)
  (save-buffer)
  (let ((this-buffer (buffer-name)))   
(TeX-run-shell nil (concat "rubber " " --pdf --synctex --shell-escape "  this-buffer) t)))
(define-key LaTeX-mode-map (kbd "<f8>") 'rubber)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .