[Tex/LaTex] AUCTeX: global pdf mode stop working after typesetting error occurs

auctexdvi-mode

Update:

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


Update:

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
    
    \begin{document}
      \MACRO{
    \end{document}
    

    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

   \documentclass[OPTIONS]{CLASS}

   \begin{document}

   \end{document}

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:

    \documentclass{amsart}
    \newcommand{\set}[1]{\left\{#1\right\}}

    \begin{document}
    $\set{$
    \end{document}

Best Answer

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

Related Question