# Uninformative error message when using AUCTeX

I often have this error when using AUCTeX:

TeX-error: Error occured after last TeX file closed

However, when running for instance pdflatex on the command line, I have a proper error message. But the line number information is not always useful, especially if multiple files are included. I'd like to be able to see the error in Emacs.

## AUCTeX 11.89

Starting from this version of AUCTeX, the option TeX-file-line-error enables by default the file:line:error messages that solve the problem. Thus, from this version you shouldn't run anymore into this kind of problems. I also suggest to revert any change to LaTeX-command-style, in order to be sure to use the default value.

See below for previous versions.

## AUCTeX 11.88 or earlier

Instead of editing the texmf.cnf file you can just add -file-line-error option to your TeX processor. To do this add the following code to your .emacs:

(setq LaTeX-command-style '(("" "%(PDF)%(latex) -file-line-error %S%(PDFout)")))


8. Why does TeX-next-error (C-c ) fail?

When writing the log file, TeX puts information related to a file, including error messages, between a pair of parentheses. AUCTeX determines the file where the error happened by parsing the log file and counting the parentheses. This can fail when there are other, unbalanced parentheses present.

As a workaround you can activate so-called file:line:error messages for the log file. (Those are are easier to parse, but may lack some details.) Either you do this in the configuration of your TeX system (consult its manual to see where this is) or you add a command line switch to the (la)tex call, e.g. by customizing LaTeX-command-style or TeX-command-list.

• Thanks for the information. I searched for the error message "Error occured after last TeX file closed" and found no answers on TeX.SX, and on Google I had tried the error message + "site:stackexchange.com", which prevented me from finding the answer in Stack Overflow. – anol Jul 16 '13 at 15:39
• If this problem only happens for beamer documents (which is the case for me), one can use (setq LaTeX-command-style '(("beamer" "%(PDF)%(latex) -file-line-error %S%(PDFout)") ("" "%(PDF)%(latex) %S%(PDFout)"))) to get C-c  work for beamer documents while not sacrificing detailed reports on other documents. – Jisang Yoo Feb 20 '14 at 12:04
• @JisangYoo Why do you say that using -file-line-error sacrifices detailed reports? – giordano Feb 20 '14 at 13:03
• With --file-line-error, if you happen to use an undefined control sequence, the error report only says that you used an undefined control but does not tell you which one. AUCTeX will place cursor at the end of the frame containing the undefined control sequence, so not big deal, but it is less detailed. – Jisang Yoo Feb 20 '14 at 16:05
• For those interested, visit sourceforge.net/p/miktex/bugs/2310 to track progress on the bug. – Jisang Yoo Mar 5 '14 at 18:43

This Gentoo Forum gives a solution that worked for me:

I have discovered that if I comment out

\usepackage{hyperref}

all works as it should. Evidently there is some sort of interaction between emacs, auctex, and hyperref that leads to the problem.

This solution is quick to try, but not ideal (you have to uncomment hyperref later).

A better solution is to follow what is mentioned in the Bug-AUCTeX list, referenced on the previous forum post. Resuming the quick fix:

change file_line_error_style from f to t in the texmf.cnf file.

The location and name of this file may vary. Here are some possible values:

/usr/share/texmf/web2c/texmf.cnf
/usr/share/texlive/texmf/web2c/texmf.cnf
/etc/texmf/texmf.d/95NonPath.cnf


You might need to run update-texmf, though in my TeXLive installation I didn't have to do it. I just uncommented the hyperref line previously commented and it worked.

• You can also add --file-line-error to the options of your invokation of pdflatex. – T. Verron Jul 16 '13 at 14:54

giordano's solution is great, but i came into something else.

i never had the problem until i recently rebuilt emacs24.2.1+auctex11.87+miktex2.9 on win7. not only did i get the "TeX-error: Error occured after last TeX file closed" error msg, i cannot even directly compile a newly created tex file by C-c C-c y RET. emacs would not remind me to save the new file as usual and then compile, but i had to use the mouse to click the SAVE icon first.

while searching for a resolution, i came upon the following page comments.gmane.org/gmane.emacs.auctex.general/5070

so i tried to replace the two files tex-buf.el and tex-buf.elc from auctex11.87 with the same files from auctex11.86.

i'm not sure i distroyed some new feature from auctex11.87, but at least the problem is gone.

• I wouldn't suggest to downgrade a file for this problem that can be worked around easily. In AUCTeX 11.87 was added support to Biber, one would lose it downgrading tex-buf.el to 11.86. If you really want to restore the behavior in AUCTeX 11.86 without downgrading the whole file you can change the line (when (> (length TeX-error-file) 0) in tex-buf.el to (when (> (length TeX-error-file) 1) but I definitely don't recommend to do that, that behavior was somewhat broken. – giordano Oct 6 '13 at 21:35
• @giordano,thanks again! i agree that downgrading is not viable from the initial point. btw, changing that line your suggested does not work for me here. i now really believe that this whole emacs stuff is strictly version-controlled and os dependent. i built the whole stuff on another computer and the "TeX-error: Error occured after last TeX file closed" error is gone, but i still cannot directly compile a newly created buffer as usual. emacs keeps reminding me that the file does not exist. – davyjones Oct 8 '13 at 11:15
• i like to compile on save by using the suggestion from link, but this bug i mentioned above is affecting that. so i add another (save-buffer) before (TeX-command-menu "LaTeX") and i'm back to normal so far. – davyjones Oct 8 '13 at 14:05