I've tested the problem in detail, and the results are appended at the end of the question. I guess now the problem becomes: How to avoid stupid diagnostic of AUCTeX when curly braces mismatch?

Original question:

I have the following line

(add-hook 'LaTeX-mode-hook 'TeX-global-PDF-mode)

in my ~.emacs that turns on global pdf mode by default. This way, by configuring TeXShop for external editor, I can use it as the previewer every time I C-c C-c LaTeX in emacs.

However, sometimes after a typesetting error occurs and C-c (backtick) is used to view error (details below), the pdf mode seems to be disabled. After fixing the mistake, dvi is generated rather than pdf, and the pdf never gets updated again. I need to exit emacs and restart to restore pdf mode.

Why does this behavior occur? Any fix? I'm using Emacs 24.3.0 with AUCTeX 11.87 (both are the current version).


The detailed workflow that triggers the problem:

  1. Start emacs with a .tex file and (add-hook 'LaTeX-mode-hook 'TeX-global-PDF-mode) in startup file. The initial mode is LaTeX/P Fill, LaTeX-mode major mode, with TeX-PDF-mode and auto-fill-mode minor modes (that autofill mode may be due to my turning on auto fill in my startup file; I didn't test whether AUCTeX start with autofill by default).

  2. Make a non-standard curly braces mismatch error, for instance,

    % header

    where \MACRO is not a default macro, but maybe something defined in % header with newcommand. Still LaTeX/P Fill.

  3. C-c C-c RET (use LaTeX to typeset by default). Error is reported:

    LaTeX errors in `*DIR/FILE output*'. Use C-c ` to display.

    Still LaTeX/P Fill.

  4. C-c (backtick) to trigger function TeX-next-error. A strange buffer appears, named TeX Live 2012. The minibuffer below prompts for options, RET: At this time, the mode becomes LaTeX Fill; pdf mode is toggled away.

  5. C-g to quit the function. The buffer is returned to the original editing buffer (but note that the TeX Live 2012 buffer is still in the background; you will be prompted to save it when you try to quit emacs). Still LaTeX Fill.

  6. Now fix the buggy code and C-c C-c RET again. This time, dvi is generated instead of pdf since now TeX-PDF-mode is nil.

Stray away: if I follow the prompts in step 4 instead of C-g, I will end up with the buffer TeX Live 2012 containing




A new file! Well, not very helpful. I just missed one curly brace... And you ask me to rewrite the file... Nevertheless, the TeX Live 2012 buffer at this time will be LaTeX/P Fill.

At last, a small working example that triggers this behavior:


  • Does it make any difference if, instead, you use (add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
    – Ricardo
    May 14 '13 at 22:37
  • @Ricardo Thanks for helping. No, it doesn't. My fault not testing the problem properly. I've pinned down the actual problem and record the details in the updated question statement.
    – 4ae1e1
    May 15 '13 at 1:46

Here is my setup and I never have had an issue over a compiling error. I just fix whatever the error says and run it again.

(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)

 ;; 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)

You MWE doesn't cause the same issue when I run the code. It might be your Emacs setup.

  • Thanks for helping. Indeed, using custom-set-variables (TeX-PDF-mode t)` instead of (add-hook 'LaTeX-mode-hook 'TeX-global-PDF-mode) solves the problem of PDF mode toggling. In this sense the problem is resolved. However, could you please tell me what error message you get when you use C-c (backtick) on the MWE? I still get that TeX Live 2012 buffer; and only on the second run of LaTeX will it tell me ERROR: File ended while scanning use of \set. This is rather annoying.
    – 4ae1e1
    May 15 '13 at 3:45
  • @KevinSayHi so you want me to try to run latex, then after the error hit C-c and what is backtick?
    – dustin
    May 15 '13 at 3:53
  • You know, C-c ` for the error. (I can't type ` in code mode since it gets escaped.) Otherwise how do you obtain the error message?
    – 4ae1e1
    May 15 '13 at 4:01
  • @KevinSayHi my error messages split the screen and appear at the bottom after compilation.
    – dustin
    May 15 '13 at 4:07
  • Oh really? Unbelievable... That's not the default behavior of AUCTeX. So could you please remind me of what 'tex-site is? Is it another add-on? That line doesn't work for me so I commented it out.
    – 4ae1e1
    May 15 '13 at 4:11

Your Answer

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

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