So I am using AUCTeX with xetex in emacs and each time after I compile the file I get a split window showing the compilation process. I don't want to completely hide this since I find it useful for debugging, but I want it to appear in a different buffer and not bother me when there are no errors. Is this possible? Another option, although less great, would be to automatically hide it except when there are compilation errors.

I have the option:

(setq TeX-show-compilation t)

I think the best solution it to hook onto TeX-LaTeX-sentinel. In this way, you can check for the presence of errors after the compiler has finished its job. Add the following code to your initialization file:

(defadvice TeX-LaTeX-sentinel
  (around mg-TeX-LaTeX-sentinel-open-output activate)
  "Open output when there are errors."
  ;; Run `TeX-LaTeX-sentinel' as usual.
  ;; Check for the presence of errors.
      (with-current-buffer TeX-command-buffer
    (plist-get TeX-error-report-switches (intern (TeX-master-file))))
    ;; If there are errors, open the output buffer.
    (TeX-recenter-output-buffer nil)))

The problem with the compilation step is that the next buffer is extremely large. I typically do this:

(defun shrink-window-to-height(height)
  "Shrink window height to certain height."
  (interactive "nNew window height: ")
  (if (> (window-height) height)
    (shrink-window (- (window-height) height))
    (enlarge-window (- height (window-height)))

(add-to-list 'TeX-command-list '("pdfLaTeX" "pdflatex -shell-escape %t" TeX-run-interactive nil t))
(defun do-pdflatex ()
    "pdflatex with shell escape."
    (interactive nil)
    (let ((process (TeX-active-process)))
      (if process
    (TeX-command "pdfLaTeX" 'TeX-master-file)
    (other-window 1)
    (shrink-window-to-height 7)
    (other-window -1)
    (TeX-recenter-output-buffer nil)
(global-set-key [f3] 'do-pdflatex)

It does this:

  1. Kills any active compilation steps
  2. Starts a new compilation step
  3. Switch buffer to the compiling window (not exactly, but if 2 buffers are open this will happen)
  4. Shrink the window to height 7
  5. Switch back to original buffer

As it takes up so little space it usually doesn't bother me when it compiles fine. I have never looked into this, but it probably means hacking into the process to check it its done, which I suspect is not that easy.

  • Two issues: "pdfLaTeX" is not a built-in AUCTeX command (why not using "LaTeX"?); shrink-window-to-height function doesn't exist. – giordano Jun 20 '14 at 9:46
  • Sorry, I have updated the answer, it has been a long time since I created these scripts! ;) If anything else is missing, please ask! – zeroth Jun 20 '14 at 9:49
  • I'm getting "Symbol's value as variable is void: TeX-command-list". – Matías Guzmán Naranjo Jun 20 '14 at 15:59
  • @MatíasGuzmánNaranjo I suspect you have a legacy AucTeX installation. – zeroth Jun 23 '14 at 7:17

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.