1

I am using Emacs+Auctex to write LaTeX code.

When compiling a document that contains an error, Emacs writes

LaTeX errors in ‘*~/doc output*’. Use C-c ` to display.

to the Messages buffer (and displays it below the mode line). I often overlook this and continue to work on an erroneous document.

Is it possible to configure Emacs such that the background color of a LaTeX buffer is changed (e. g., to light red), if a document is compiled that raises an error? And the color changes back when the error is fixed and the document is re-compiled?

Alternatively, are there any other, possibly simpler, ways to highlight LaTeX compile errors more prominently?

1

I had the same problem as you. My solution was to add the status of the last Latex compilation (in bright colors) to the mode line. An error is displayed in red so it is hard to overlook. Here is the code (you can add it to your init file):

(setq last-latex-compilation-status "No Compilation") 
(setq-default mode-line-format (append mode-line-format '((:eval (last-latex-compilation-status-update nil)))))

(defun last-latex-compilation-status-update (arg)
  "Update the string that holds the status of the last latex compilation"
  (setq last-latex-compilation-status
    (save-excursion
      (set-buffer "*Messages*")
      (goto-char (point-max))   
      (if (search-backward-regexp "^LaTeX\\(.*\\)$" nil t nil)
          (let ((compilationstatus (match-string 1)))
        (cond
         ((string-match "successfully" compilationstatus) (propertize "Success" 'font-lock-face '(:background "green")))
         ((string-match "errors" compilationstatus) (propertize "Error" 'font-lock-face '(:foreground "red")))
         ((string-match "unresolved" compilationstatus) (propertize "Unresolved" 'font-lock-face '(:foreground "blue")))
         (t "No Compilation")))))))

  • Awesome. I like the idea of coloring the mode line even more than coloring the buffer. Thx! – user64060 Jan 10 at 22:30

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.