TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The user "Mike" kindly helped me on Latex, Emacs: automatically open TeX Help buffer on error and close it after correction of the error? to create the following function which makes error detection to play nicely together with latexmk.

(defun run-latexmk ()
  (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)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
    (minibuffer-message "latexmk: done.")))))

I would like to add another option to the latexmk call like this:

(TeX-command-expand "latexmk -pdflatex='pdflatex -file-line-error' -pdf %s" 'TeX-master-file)

to make pdflatex to report not only the line of an error but also the file name (which is crucial for AUCTeX to open the correct buffer in case of an error). The problem is that after I add this option, a compiled myfile.tex does not have an accompanying myfile.synctex.gz anymore, which causes forward and backward search to fail (see How to set up Okular for forward/backward search with TeX Live 2011? (not trivial anymore)).

Where is the problem?

share|improve this question
Did you try putting -synctex=1 -file-line-error? – egreg Jun 17 '12 at 13:40
Great, thanks, that worked! I guess I should have specified this option even without the pdflatex option, not sure why it was working automatically. Thanks again, egreg. – Marius Hofert Jun 17 '12 at 13:59
up vote 9 down vote accepted


"latexmk -pdflatex='pdflatex -file-line-error' -pdf %s"

instruction should contain all options we want to pass to pdflatex at execution time, so

"latexmk -pdflatex='pdflatex -file-line-error -synctex=1' -pdf %s"

should work. The part within single quotes is the command latexmk will issue for compiling the document.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.