Function: org-latex-compile

org-latex-compile is a byte-compiled function defined in ox-latex.el.gz.

Signature

(org-latex-compile TEXFILE &optional SNIPPET)

Documentation

Compile a TeX file.

TEXFILE is the name of the file being compiled. Processing is done through the command specified in org-latex-pdf-process, which see. Output is redirected to "*Org PDF LaTeX Output*" buffer.

When optional argument SNIPPET is non-nil, TEXFILE is a temporary file used to preview a LaTeX snippet. In this case, do not create a log buffer and do not remove log files.

Return PDF file name or raise an error if it couldn't be produced.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-latex.el.gz
(defun org-latex-compile (texfile &optional snippet)
  "Compile a TeX file.

TEXFILE is the name of the file being compiled.  Processing is
done through the command specified in `org-latex-pdf-process',
which see.  Output is redirected to \"*Org PDF LaTeX Output*\"
buffer.

When optional argument SNIPPET is non-nil, TEXFILE is a temporary
file used to preview a LaTeX snippet.  In this case, do not
create a log buffer and do not remove log files.

Return PDF file name or raise an error if it couldn't be
produced."
  (unless snippet (message "Processing LaTeX file %s..." texfile))
  (let* ((compiler
	  (or (with-temp-buffer
		(save-excursion (insert-file-contents texfile))
		(and (search-forward-regexp (regexp-opt org-latex-compilers)
					    (line-end-position 2)
					    t)
		     (progn (forward-line 0) (eq (char-after) ?%))
		     (match-string 0)))
              ;; Cannot find the compiler inserted by
              ;; `org-latex-template' -> `org-latex--insert-compiler'.
              ;; Use a fallback.
              org-latex-compiler))
	 (process (if (functionp org-latex-pdf-process) org-latex-pdf-process
		    ;; Replace "%latex" with "%L" and "%bib" and
		    ;; "%bibtex" with "%B" to adhere to `format-spec'
		    ;; specifications.
		    (mapcar (lambda (command)
			      (replace-regexp-in-string
                               "%\\(?:\\(?:bib\\|la\\)tex\\|bib\\)\\>"
			       (lambda (m) (upcase (substring m 0 2)))
			       command))
			    org-latex-pdf-process)))
         (spec `((?B . ,(shell-quote-argument org-latex-bib-compiler))
                 (?L . ,(shell-quote-argument compiler))))
	 (log-buf-name "*Org PDF LaTeX Output*")
         (log-buf (and (not snippet) (get-buffer-create log-buf-name)))
         outfile)
    ;; Erase compile buffer at the start.
    (with-current-buffer log-buf
      (erase-buffer))
    (setq outfile
          (org-compile-file
           texfile process "pdf"
	   (format "See %S for details" log-buf-name)
	   log-buf spec))
    (org-latex-compile--postprocess outfile log-buf snippet)
    ;; Return output file name.
    outfile))