Fix file compilation in a different directory than current one

* lisp/org.el (org-compile-file): Do not set default directory.
(org-preview-latex-process-alist): Update since base-name may no be
located in current directory.
* lisp/ox-latex.el (org-latex-compile): Remove auxiliary files in
  default directory instead of ".tex" file directory.

Reported-by: Alex Fenton <alex.fenton@pressure.to>
<http://permalink.gmane.org/gmane.emacs.orgmode/110078>
This commit is contained in:
Nicolas Goaziou 2016-11-08 11:44:28 +01:00
parent 13dbea95af
commit 120f8c09f4
2 changed files with 26 additions and 22 deletions

View File

@ -4085,7 +4085,7 @@ All available processes and theirs documents can be found in
:image-output-type "png" :image-output-type "png"
:image-size-adjust (1.0 . 1.0) :image-size-adjust (1.0 . 1.0)
:latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
:image-converter ("dvipng -fg %F -bg %B -D %D -T tight -o %b.png %f")) :image-converter ("dvipng -fg %F -bg %B -D %D -T tight -o %o%b.png %f"))
(dvisvgm (dvisvgm
:programs ("latex" "dvisvgm" "gs") :programs ("latex" "dvisvgm" "gs")
:description "dvi > svg" :description "dvi > svg"
@ -4095,7 +4095,7 @@ All available processes and theirs documents can be found in
:image-output-type "svg" :image-output-type "svg"
:image-size-adjust (1.7 . 1.5) :image-size-adjust (1.7 . 1.5)
:latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
:image-converter ("dvisvgm %f -n -b min -c %S -o %b.svg")) :image-converter ("dvisvgm %f -n -b min -c %S -o %o%b.svg"))
(imagemagick (imagemagick
:programs ("latex" "convert" "gs") :programs ("latex" "convert" "gs")
:description "pdf > png" :description "pdf > png"
@ -4107,7 +4107,7 @@ All available processes and theirs documents can be found in
:image-size-adjust (1.0 . 1.0) :image-size-adjust (1.0 . 1.0)
:latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f") :latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
:image-converter :image-converter
("convert -density %D -trim -antialias %f -quality 100 %b.png"))) ("convert -density %D -trim -antialias %f -quality 100 %o%b.png")))
"Definitions of external processes for LaTeX previewing. "Definitions of external processes for LaTeX previewing.
Org mode can use some external commands to generate TeX snippet's images for Org mode can use some external commands to generate TeX snippet's images for
previewing or inserting into HTML files, e.g., \"dvipng\". This variable tells previewing or inserting into HTML files, e.g., \"dvipng\". This variable tells
@ -22756,28 +22756,27 @@ it for output.
`default-directory' is set to SOURCE directory during the whole `default-directory' is set to SOURCE directory during the whole
process." process."
(let* ((source-name (file-name-nondirectory source)) (let* ((base-name (file-name-base source))
(base-name (file-name-sans-extension source-name))
(full-name (file-truename source)) (full-name (file-truename source))
(out-dir (file-name-directory source)) (out-dir (file-name-directory source))
(time (current-time)) (time (current-time))
(err-msg (if (stringp err-msg) (concat ". " err-msg) ""))) (err-msg (if (stringp err-msg) (concat ". " err-msg) "")))
(save-window-excursion (save-window-excursion
(let ((default-directory (file-name-directory full-name))) (pcase process
(pcase process ((pred functionp) (funcall process (shell-quote-argument source)))
((pred functionp) (funcall process (shell-quote-argument source))) ((pred consp)
((pred consp) (let ((log-buf (and log-buf (get-buffer-create log-buf)))
(let ((log-buf (and log-buf (get-buffer-create log-buf))) (spec (append spec
(spec (append spec `((?b . ,(shell-quote-argument base-name))
`((?b . ,(shell-quote-argument base-name)) (?f . ,(shell-quote-argument source))
(?f . ,(shell-quote-argument source-name)) (?F . ,(shell-quote-argument full-name))
(?F . ,(shell-quote-argument full-name)) (?o . ,(shell-quote-argument out-dir))))))
(?o . ,(shell-quote-argument out-dir)))))) (dolist (command process)
(dolist (command process) (shell-command (format-spec command spec) log-buf))))
(shell-command (format-spec command spec) log-buf)))) (_ (error "No valid command to process %S%s" source err-msg))))
(_ (error "No valid command to process %S%s" source err-msg))))) ;; Check for process failure. Output file is expected to be
;; Check for process failure. ;; located in the same directory as SOURCE.
(let ((output (concat out-dir base-name "." ext))) (let ((output (expand-file-name (concat base-name "." ext) out-dir)))
(unless (org-file-newer-than-p output time) (unless (org-file-newer-than-p output time)
(error (format "File %S wasn't produced%s" output err-msg))) (error (format "File %S wasn't produced%s" output err-msg)))
output))) output)))

View File

@ -3612,10 +3612,15 @@ produced."
(when org-latex-remove-logfiles (when org-latex-remove-logfiles
(mapc #'delete-file (mapc #'delete-file
(directory-files (directory-files
(file-name-directory texfile) t ;; Assume auxiliary files are created in current
;; directory instead of ".tex" file directory, which
;; may differ.
default-directory
nil
(concat (regexp-quote (file-name-base outfile)) (concat (regexp-quote (file-name-base outfile))
"\\(?:\\.[0-9]+\\)?\\." "\\(?:\\.[0-9]+\\)?\\."
(regexp-opt org-latex-logfiles-extensions))))) (regexp-opt org-latex-logfiles-extensions))
t)))
(let ((warnings (org-latex--collect-warnings log-buf))) (let ((warnings (org-latex--collect-warnings log-buf)))
(message (concat "PDF file produced" (message (concat "PDF file produced"
(cond (cond