> Next step - ox-latex.
>
>> (defvar org-latex-precompile t
>> "Precompile the preamble during export.
>> This requires the LaTeX package \"mylatexformat\" to be installed.")
>
> Should it be defcustom?
I turned it into a defcustom and changed the default value to nil, for
backward compatibility and to avoid surprises.
>> (defconst org-latex--precompile-log "*Org LaTeX Precompilation*")
Added docstring.
>> (defvar org-latex-precompile-compiler-map
>> '(("pdflatex" . "latex")
>> ("xelatex" . "xelatex -no-pdf")
>> ("lualatex" . "dvilualatex")))
>
> Missing docstring.
I've removed this variable entirely, it's not used anywhere or
required.
> In org-latex--precompile, there is
> (preamble-hash
> (thread-first
> preamble
> (concat
> (plist-get info :latex-compiler)
> (alist-get ?l (plist-get info :precompile-format-spec))
> (if tempfile-p "-temp" default-directory))
> (sha1)))
>
> but org-latex--remove-cached-preamble has
>
> (preamble-hash
> (thread-first
> preamble
> (concat
> latex-compiler
> (if tempfile-p "-temp"
> default-directory))
> (sha1)))
>
> Note how ?l field from :precompile-format-spec is missing.
Fixed as part of redesign of the precompilation code path (currently
commit fa18cc2bd336a9966e1074db04c66c01870d5896, but I might
amend/rebase so it'll be one of the top commits).
More on this below.
>> (defun org-latex--precompile-preamble (info preamble basepath)
>
> checkdoc warnings.
Fixed.
>> (unless (= 0 (call-process "kpsewhich" nil nil nil "preview.sty"))
>> (display-warning
>> '(org latex-preview preamble-precompilation)
>> "The LaTeX package \"preview\" is required for precompilation, but
>> could not be found")
>> :warning)
>
> This seems out of scope of ox-latex.el
Not sure how to propagate this error back to org-latex-preview. Please
advise.
>> (defun org-latex-export-to-pdf-and-open (&optional async subtreep
>> visible-only body-only ext-plist)
>
> This is a new function that should be announced, maybe added to the
> manual (as other similar functions). Also, docstring is missing.
This function is gone, I reverted org-latex-compile to being
synchronous.
>> (defun org-latex-compile (texfile &optional snippet open-pdf)
>
> open-pdf argument is missing in the docstring.
Reverted to old synchronous behavior, so no changes required.
>> (let ((failure-msg (format "File %S wasn't produced (exit code %%d). See
>> %%s for details."
>> outfile))
>> async-call-spec)
>> (dolist (cmd (reverse (org-compile-file-commands
>> texfile process "pdf" spec)))
>> (setq async-call-spec
>> (list cmd
>> :buffer log-buf
>> :success
>> (or async-call-spec
>> (list (and open-pdf (lambda (_ _ _) (org-open-file
>> outfile)))
>> (lambda (_ buf _)
>> (org-latex-compile--postprocess outfile
>> buf snippet))))
>> :failure
>> failure-msg)))
>> (message "Compiling %s..." texfile)
>> (apply #'org-async-call async-call-spec))
>
> This looks problematic:
> 1. The awkward dance with the loop reveals problems with design of
> org-async-call
> 2. The call is async, which means that `org-latex-compile' is no longer
> guaranteed to return an existing file.
> 3. I am wondering why the whole new if branch cannot be embedded into
> org-compile-file itself. It already tries to copy org-compile-file
> behavior by using the same failure message.
While this problem is now gone as I reverted org-latex-compile to the
old synchronous code, I will try to apply this loop to org-async-call next.
Karthik