emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: emacs-orgmode@gnu.org
Subject: Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
Date: Fri, 31 Mar 2023 09:36:03 +0200	[thread overview]
Message-ID: <87ilehs78c.fsf@christianmoe.com> (raw)
In-Reply-To: <23027539.6Emhk5qWAg@pluto>


chris writes:

>> [ ... snip ... ]
>> Solution:
>>
>> Redefine org-babel-latex-preamble to remove
>> the offending line.
>>
>>   (setq org-babel-latex-preamble
>>     '(lambda (_)
>>       "\\documentclass[preview]{standalone}"))
>>
>> With this setup, my example
>>
>>   #+header: :fit yes :headers '("\\usepackage{tikz}")
>>   #+begin_src latex :exports results :results raw file :file test-tikz-triangle.svg
>>     \begin{tikzpicture}
>>       \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
>>     \end{tikzpicture}
>>   #+end_src
>>
>> exports correctly to an .svg file.
>
> Hmm, your fix works perfectly! And it's a `defcustom` variable so it's not even a hack.

Yes, I only thought about that afterwards.

> I guess that since you haven't selected specific method like:
> `#+header: :imagemagick yes`, the method used is `inkscape`
> (`ob-latex.el` file):
> ```
> (defcustom org-babel-latex-pdf-svg-process
>   "inkscape \
> --pdf-poppler \
> --export-area-drawing \
> --export-text-to-path \
> --export-plain-svg \
> --export-filename=%O \
> %f"
>   "Command to convert a PDF file to an SVG file."
>   :group 'org-babel
>   :type 'string
>   :package-version '(Org . "9.6"))
> ```
>

I would have been, but I've got inkscape installed via Linux Mint apt
repo and it appears to be just a bit too old to have the --pdf-poppler
option. Right now, for testing, I'm just using the first thing I have at
hand that works, which is pdftocairo:

: (setq org-babel-latex-pdf-svg-process "pdftocairo -svg %f %O")

I'll probably switch to inkscape for options like not exporting text to
paths.

I also considered dvisvgm, which I use for snippet preview, but I
*think* that using xetex, I could not use dvisvgm for Babel blocks
because the Babel latex-to-svg process expects a pdf to be produced,
whereas xelatex only outputs dvi (actually an extended dvi format called
xdv) if you use the -no-pdf option. Could be wrong.

> I don't know if you use `org-latex-preview` for `tikz` snippets? Maybe you don't because that doesn't export to `html`.
>
> I use `(setq org-preview-latex-default-process 'dvipng)`, and I guess it would be nice to add an new option in `(defcustom org-preview-latex-process-alist` to add `inkscape`.

I imagine that's possible.

But on raw tikz snippets (not src blocks), this already works well for
me with dvisvgm. To get it working with xetex I have customized the
dvisvgm option in org-preview-latex-process-alist:

   ...
   (dvisvgm :programs
	    ("xelatex" "dvisvgm")
	    :description "xdv > svg"
	    :message "you need to install the programs: xetex and dvisvgm."
	    :image-input-type "xdv" :image-output-type "svg"
	    :image-size-adjust (1.7 . 1.5)
	    :latex-compiler ("xelatex -no-pdf -interaction nonstopmode -output-directory %o %f")
	    :image-converter ("dvisvgm %f --no-fonts --exact-bbox
            --scale=%S --output=%O")))
   ...


> So with you solution, I guess when we export to `html`, the "normal" `latex` formulas are rendered by `mathjax`, which works very well, and the `tikz` diagrams are automatically exported as a `svg` image, while the code to produce them is not exported.
>
> I suppose you use those `latex` code block for exporting to `html` purpose?

Yes, that's my aim.

Yours,
Christian


  reply	other threads:[~2023-03-31  7:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29  8:00 File generation from LaTeX src fails due to temporary PDF in wrong directory Pedro Andres Aranda Gutierrez
2023-03-29 17:31 ` chris
2023-03-29 21:15   ` Christian Moe
2023-03-30  5:16     ` chris
2023-03-30 11:15       ` Christian Moe
2023-03-31  5:25         ` chris
2023-03-31  7:36           ` Christian Moe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-03-28  8:04 Christian Moe
2023-03-28 10:14 ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilehs78c.fsf@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).