emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: chris <inkbottle007@gmail.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 07:25:08 +0200	[thread overview]
Message-ID: <23027539.6Emhk5qWAg@pluto> (raw)
In-Reply-To: <87y1neqyll.fsf@christianmoe.com>

On Thursday, 30 March 2023 13:15:34 CEST Christian Moe wrote:
> 
> chris writes:
> 
> > On Wednesday, 29 March 2023 23:15:03 CEST Christian Moe wrote:
> >>
> >> Hi,
> >>
> >> Pardon the noise: It turned out to be a pretty obvious problem with my
> >> setup that has now been resolved.
> >>
> >> I had modified org-latex-pdf-process to use xelatex, and for some reason
> >> my setup lacked the =-output-directory %o= switch. I should probably
> >> have thought of that first, but the omission has had no ill effects on
> >> ordinary PDF export, so I didn't run into any problem before trying to
> >> use Babel with LaTeX.
> >>
> >> Ihor and Pedro, thanks for checking.
> >>
> >> Chris, I don't know why your attempts fail, but I'll be trying similar
> >> things over the next days, so maybe I'll come back to you.
> >>
> >
> > For one thing I don't understand 90% of the options, that can explain a lot.
> > Another point, the gibberish output I was speaking about are "similar" those
> > of
> > [[https://emacs.stackexchange.com/questions/68823/minimal-working-example-of-tikz-to-svg-in-orgmode]]
> > Actually the svg image they get is an image containing the `tikz` instructions
> > transformed as image. What I get is the svg instructions that should generate
> > the image: an image showing a `svg` listing.
> 
> I am seeing the same problem, and think I have a solution below, but
> it's confusing and I'm wondering if other people have this working out
> of the box somehow.
> 
> The difference between what you are seeing, and what they are seeing in
> the stackexchange thread, comes down to whether =:headers
> '("\\usepackage{tikz}")= is specified. Without it, all they get is an
> SVG of the glyphs in the arguments to the tikz commands. With it, we get
> an SVG of the glyphs in the SVG for the image. So when the extension is
> .svg, the intermediate PDF that is converted into SVG does not contain
> the image, but a listing of the SVG, which has *already* been generated!
> 
> The reason, I think, is that org-babel-latex-preamble includes this
> definition:
> 
> : \def\pgfsysdriver{pgfsys-tex4ht.def}
> 
> So what happens, I think, is that tex4ht already generates SVG from the
> TikZ code. When Org then uses org-babel-latex-pdf-svg-process to call an
> external utility, by default inkscape, to convert the PDF to SVG, we are
> converting not an image but a code listing already in SVG.
> 
> It is not at all clear to me why tex4ht is invoked in the default
> preamble. I wonder if it still serves a purpose. If it makes better SVG
> from LaTeX than the other utilities, it would be nice to use it directly
> somehow. But perhaps it is just a leftover from a stage in development
> when htlatex was used to produce the SVG, before the two-part-process
> ->PDF->SVG with org-babel-latex-pdf-svg-process was defined. If so it
> should probably be changed. Here's the relevant thread, I think, for
> people wanting to look into that:
> 
>   https://list.orgmode.org/873608ajfn.fsf@bzg.fr/t/
> 
> 
> 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.

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 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`.

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?

Thanks,
Chris

> 
> Yours,
> Christian
> 
> 






  reply	other threads:[~2023-03-31  5:26 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 [this message]
2023-03-31  7:36           ` Christian Moe
  -- 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=23027539.6Emhk5qWAg@pluto \
    --to=inkbottle007@gmail.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).