1

I would like the default compile command for .tex files to be different than the default for .Rnw (knitr) files.

Here is a minimal example to illustrate my current .emacs file:

(defvar TeX-command-list)
(add-hook 'LaTeX-mode-hook 
      (lambda()
         (add-to-list 'TeX-command-list '("LaTeXmk -- run continuously" "latexmk -pdf -pvc -new-viewer- -e \"$pdf_previewer='start C:/SumatraPDF-TeX/SumatraPDF-TeX.exe';$pdflatex='pdflatex -interaction=nonstopmode -synctex=1 %%O %%S'\" %s" TeX-run-TeX nil t))
         (setq TeX-command-default "LaTeXmk -- run continuously")
         (setq TeX-save-query nil)))

So far so good. When I press C-c C-c, my .tex files default to this command.

Here is what I have for .Rnw files:

(setq TeX-file-extensions
  '("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))

(add-hook 'Rnw-mode-hook 
      (lambda()
         (add-to-list 'TeX-command-list '("Knitr via latexmk" "latexmk -pdf -pvc -new-viewer- -f -r \"%UserProfile%\\.emacs.d\\Knitrlatexmk.rc\" %t" TeX-run-TeX nil t))
         (setq TeX-command-default "Knitr via latexmk")
         (setq TeX-save-query nil)))

But when I try to compile my .Rnw files (with C-c C-c), the default is the "Sweave" command. What am I missing? I've searched high and low, trying everything I can think of, but the above command is never offered to me as the default for .Rnw files.

  • In case it matters, I'm using GNU Emacs 25.2.1 on Windows. – Brian May 28 '17 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.