org-e-latex: Fix publishing problems when compiling a TeX file

* contrib/lisp/org-e-latex.el (org-e-latex-compile): Fix compilation
  when default-directory from current buffer doesn't match directory
  from file being compiled. Small refactoring, too.

Thanks to Robert Klein for reporting the problem and suggesting a fix.
This commit is contained in:
Nicolas Goaziou 2012-10-11 23:46:07 +02:00
parent 0a99cf7249
commit 9b11e63e7a
1 changed files with 46 additions and 46 deletions

View File

@ -2667,55 +2667,55 @@ TEXFILE is the name of the file being compiled. Processing is
done through the command specified in `org-e-latex-pdf-process'. done through the command specified in `org-e-latex-pdf-process'.
Return PDF file name or an error if it couldn't be produced." Return PDF file name or an error if it couldn't be produced."
(let* ((wconfig (current-window-configuration)) (let* ((texfile (file-truename texfile))
(texfile (file-truename texfile))
(base (file-name-sans-extension texfile)) (base (file-name-sans-extension texfile))
;; Make sure `default-directory' is set to TEXFILE directory,
;; not to whatever value the current buffer may have.
(default-directory (file-name-directory texfile))
errors) errors)
(message (format "Processing LaTeX file %s ..." texfile)) (message (format "Processing LaTeX file %s ..." texfile))
(unwind-protect (save-window-excursion
(progn (cond
(cond ;; A function is provided: Apply it.
;; A function is provided: Apply it. ((functionp org-e-latex-pdf-process)
((functionp org-e-latex-pdf-process) (funcall org-e-latex-pdf-process (shell-quote-argument texfile)))
(funcall org-e-latex-pdf-process (shell-quote-argument texfile))) ;; A list is provided: Replace %b, %f and %o with appropriate
;; A list is provided: Replace %b, %f and %o with appropriate ;; values in each command before applying it. Output is
;; values in each command before applying it. Output is ;; redirected to "*Org PDF LaTeX Output*" buffer.
;; redirected to "*Org PDF LaTeX Output*" buffer. ((consp org-e-latex-pdf-process)
((consp org-e-latex-pdf-process) (let* ((out-dir (file-name-directory texfile))
(let* ((out-dir (or (file-name-directory texfile) "./")) (outbuf (get-buffer-create "*Org PDF LaTeX Output*")))
(outbuf (get-buffer-create "*Org PDF LaTeX Output*"))) (mapc
(mapc (lambda (command)
(lambda (command) (shell-command
(shell-command (replace-regexp-in-string
(replace-regexp-in-string "%b" (shell-quote-argument base)
"%b" (shell-quote-argument base) (replace-regexp-in-string
(replace-regexp-in-string "%f" (shell-quote-argument texfile)
"%f" (shell-quote-argument texfile) (replace-regexp-in-string
(replace-regexp-in-string "%o" (shell-quote-argument out-dir) command t t) t t) t t)
"%o" (shell-quote-argument out-dir) command t t) t t) t t) outbuf))
outbuf)) org-e-latex-pdf-process)
org-e-latex-pdf-process) ;; Collect standard errors from output buffer.
;; Collect standard errors from output buffer. (setq errors (org-e-latex--collect-errors outbuf))))
(setq errors (org-e-latex--collect-errors outbuf)))) (t (error "No valid command to process to PDF")))
(t (error "No valid command to process to PDF"))) (let ((pdffile (concat base ".pdf")))
(let ((pdffile (concat base ".pdf"))) ;; Check for process failure. Provide collected errors if
;; Check for process failure. Provide collected errors if ;; possible.
;; possible. (if (not (file-exists-p pdffile))
(if (not (file-exists-p pdffile)) (error (concat (format "PDF file %s wasn't produced" pdffile)
(error (concat (format "PDF file %s wasn't produced" pdffile) (when errors (concat ": " errors))))
(when errors (concat ": " errors)))) ;; Else remove log files, when specified, and signal end of
;; Else remove log files, when specified, and signal end of ;; process to user, along with any error encountered.
;; process to user, along with any error encountered. (when org-e-latex-remove-logfiles
(when org-e-latex-remove-logfiles (dolist (ext org-e-latex-logfiles-extensions)
(dolist (ext org-e-latex-logfiles-extensions) (let ((file (concat base "." ext)))
(let ((file (concat base "." ext))) (when (file-exists-p file) (delete-file file)))))
(when (file-exists-p file) (delete-file file))))) (message (concat "Process completed"
(message (concat "Process completed" (if (not errors) "."
(if (not errors) "." (concat " with errors: " errors)))))
(concat " with errors: " errors))))) ;; Return output file name.
;; Return output file name. pdffile))))
pdffile))
(set-window-configuration wconfig))))
(defun org-e-latex--collect-errors (buffer) (defun org-e-latex--collect-errors (buffer)
"Collect some kind of errors from \"pdflatex\" command output. "Collect some kind of errors from \"pdflatex\" command output.