> Asilata Bapat <[email protected]> writes:
>
>> But it seems to me that there is still the following problem in ox-html.el. 
>> The documentation of org-html-format-latex does not make it clear that its 
>> last argument, the info plist, *has to* contain the property :output-file in 
>> order to avoid a runtime error!
>>
>> The further heart of the matter is the weird behaviour of 
>> file-name-directory: in particular, running (file-name-directory "") gives 
>> nil, while running (file-name-directory nil) throws an error. I don't 
>> understand why those two calls should behave differently.
>>
>> Anyway, because of this issue, an unsuspecting external call to 
>> org-html-format-latex is doomed to fail. Because it probably won't 
>> explicitly include :output-file in its info plist. This does not seem good!
>
> Right.
> However, do note that we will likely deprecate org-html-format-latex in
> one of the future releases, when we merge the latex preview branch.
> CCing Karthik.
> Karthik, could you please take a look and consider whether this
> situation will be problematic on the branch?

First, about the version of org-html-format-latex on main.

The line in question used to be

(setq cache-relpath
      (concat (file-name-as-directory org-preview-latex-image-directory)
              (file-name-sans-extension
               (file-name-nondirectory bfn)))
      cache-dir (file-name-directory bfn))

but was changed at some point to

(setq cache-relpath
      (concat (file-name-as-directory org-preview-latex-image-directory)
              (file-name-sans-extension
               (file-name-nondirectory bfn)))
      cache-dir (file-name-directory (plist-get info :output-file)))

where bfn is 

(or (buffer-file-name)
    (make-temp-name
     (expand-file-name "latex" temporary-file-directory)))

It seems to me that :output-file should only be the preferred location,
and it should still fall back to bfn:

(setq cache-relpath
      (concat (file-name-as-directory org-preview-latex-image-directory)
              (file-name-sans-extension
               (file-name-nondirectory bfn)))
      cache-dir (file-name-directory
                  (or (plist-get info :output-file) bfn)))

This should fix the issue.

-----

On the org-latex-preview branch, there is no org-html-format-latex, of
course, and the preview image location on disk is determined entirely by
org-html-latex-image-options.

org-mime calls (org-mime-export-buffer-or-subtree), which calls

 (org-export-to-buffer
     'html "*Org Mime Export*" nil subtreep nil t
     '(:with-latex imagemagick :section-numbers nil :with-author nil :with-toc 
nil))

The location of the image files in the HTML export depends on the value
of :image-dir in the new option org-html-latex-image-options, which
defaults to the relative directory "ltximg/".  This default was chosen
as it is the default behavior of ox-html on main as well.

So the fragment image is placed in ./ltximg/some-long-hash.png, with the
directory created if required.

:image-dir in org-html-latex-image-options can take all the values that
org-latex-preview-cache can, so it can be a relative or absolute
directory, or the symbols 'persist and 'temp to store the generated
image in the Org persist cache or (temporary-file-directory),
respectively.

I tested org-mime-org-buffer-htmlize and verified that it works like
this on the branch.

Karthik

Reply via email to