Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

After hitting C-c RET and compiling my .tex file, I would like the tex-shell buffer to close if the compilation was successful. How can I do that?

share|improve this question

In my .emacs I have the following code:

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

(add-hook 'LaTeX-mode-hook
          (lambda () (local-set-key (kbd "C-0") #'run-latexmk))

This binds C-0 to the defined function run-latexmk which in turn saves all the files of the current document (based on the notion of master file) and then runs latexmk. If the compilation was successful then the compilation window closes. You can easily(?) change this code to your needs.

This answer is based on this one and this one.

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.