13

System:

Ubuntu 13.04, Texlive2012, Emacs 24.something, I run Emacs from the terminal and not the GUI, and I have server mode on in Emacs.

When compiling my latex documents, I use AucTeX in emacs to run latexmk but latexmk only runs once and will say you should run latexmk again and then reason whether it be references or something else. Isn't the point of latexmk to run the appropriate amount of times from the get go?

How can I have latexmk do this with out me telling emacs to run it again?

My latex portion of my .emacs is below in case there is something I need to add or remove from it to get the desired results.

;;============AucTex===========                                                 
(require 'tex-site)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTex t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

;;============ Latexmk setup==============                                        
(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk"
                (TeX-command-expand "latexmk -pdflatex='pdflatex -file-line-error  \
                                  -synctex=1' -pdf %s" 'TeX-master-file)
                 master-file))
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
        (demolish-tex-help)
        (minibuffer-message "latexmk: done."))))

(add-hook 'LaTeX-mode-hook (lambda ()
    (push
     '("Latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
       :help "Run Latexmk on file")
     TeX-command-list)))

;; Set okular to open with C-c C-v view option                                      
(defun Okular-make-url () (concat
     "file://"
     (expand-file-name (funcall file (TeX-output-extension) t)
                       (file-name-directory (TeX-master-file))
                       "#src:"
                       (TeX-current-line)
                       (expand-file-name (TeX-master-directory))
                       "./"
                       (TeX-current-file-name-master-relative))))

(add-hook 'LaTeX-mode-hook '(lambda ()
        (add-to-list 'TeX-expand-list
                     '("%u" Okular-make-url))))
(setq TeX-view-program-list
      '(("Okular" "okular --unique %u")))
(setq TeX-view-program-selection '((output-pdf "Okular")))

(custom-set-variables
 ;; custom-set-variables was added by Custom.                                       
 ;; If you edit it by hand, you could mess it up, so be careful.                    
 ;; Your init file should contain only one such instance.                           
 ;; If there is more than one, they won't work right.                               
 '(TeX-PDF-mode t)
 '(TeX-newline-function (quote newline-and-indent))
 '(TeX-source-correlate-method (quote synctex))
 '(TeX-source-correlate-mode t)
 '(TeX-source-correlate-start-server t)
 '(TeX-view-program-list (quote (("Okular" "okular -unique %o#src:%n%b"))) t)
 '(TeX-view-program-selection (quote ((output-pdf "Okular"))) t)
 '(compilation-auto-jump-to-first-error t))

Below is my .latexmkrc file

$pdf_mode = 1;
$pdflatex = 'pdflatex -interaction=nonstopmode -file-line-error -synctex=1';

Edit

Per John Collins' request, here is the message I received when running latexmk

You should run LaTeX again to get references right, {9} pages

Even though it says LaTeX, latexmk was ran here is the output to show this:

Running `Latexmk' on `TidalForce' with ``latexmk -pdf TidalForce''
Latexmk: This is Latexmk, John Collins, 11 Nov. 2012, version: 4.35.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'TidalForce.tex'
------------
Run number 1 of rule 'pdflatex'

As John Collins mentioned, here is the better format for the .emacs and .latexmkrc file.

;; ============ Latexmk setup ==============                                        
(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk"
                 (TeX-command-expand "latexmk -pdf %s" 'TeX-master-file)
                 master-file))
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
        (demolish-tex-help)
        (minibuffer-message "latexmk: done."))))

(add-hook 'LaTeX-mode-hook (lambda ()
    (push
     '("Latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
       :help "Run Latexmk on file")
     TeX-command-list)))

.latexmkrc setup:

$pdflatex = 'pdflatex --shell-escape -interaction=nonstopmode -file-line-error -synctex=1 %O %S';
11
  • 3
    Does latexmk run pdflatex only once? If you run it another time, do you get an error All files are up to date? If yes, the problem is only related to auctex's log parser, not to latexmk.
    – T. Verron
    Commented May 20, 2013 at 16:08
  • @T.Verron yes it runs only once and no when I run it again it will update all the references or whatever it was suggesting the reason to run again.
    – dustin
    Commented May 20, 2013 at 16:09
  • @dustin I thought latexmk was a Perl script which is so clever that knows how many times to run various commands? If the above is indeed the case it almost defeats the purpose of using it. I use home coked Makefiles on one hand. Going back to your original question there must be some way to do it by editing .emacs if I recall correctly but I am a vi user (no flaming) and I forgot how to fix that in Lisp. This is trivial to do in vi so in Emacs should be even easier as it is fully programmable editor. Commented May 20, 2013 at 16:12
  • @PredragPunosevac I don't have a problem with Vim I used to use it until a plugin corrupted everything and removing it didn't fix the problem. Yes it is a perl script and it is supposed to be clever but in my case it has been having learning challenges.
    – dustin
    Commented May 20, 2013 at 16:14
  • 2
    I've just seen a problem in the invocation of latexmk. In your definitions of the command lines for latexmk, change "%s" to "%O %S". (Both the "O" and "S" are upper case.) Try that and see what happens. The "%S" is the correct placeholder for the name of the source file, and the "%O" is for options that latexmk may place on the command line. With the lower case "s" that you have, latexmk will function incorrectly. Also the output from latexmk is severely truncated; there should be a minimum of 3 extra lines. Perhaps auctex is eating them. Commented May 29, 2013 at 18:31

1 Answer 1

8
+50

In your definitions of the command lines for latexmk, change %s to %O %S. (Both the O and S are upper case.) The %S is the correct placeholder for the name of the source file, and the %O is for options that latexmk may place on the command line. With the lower case s that you have, latexmk doesn't do the substitution for the name of the source file, and the command line passed to pdflatex is not the intended one.

Note added

It turned out later that the above answer was misleading/misinpretable. There is a configuration of emacs to call latexmk correctly, and a configuration of latexmk to call pdflatex as is desired by the OP. Although latexmk can be configured through its command line, which was done in the emacs configuration file .emacs in the question, it is normally easier and safer to configure latexmk in one of its own configuration files. See TikZ: compiling a standalone picture for a better configuration.

0

You must log in to answer this question.

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