* File generation from LaTeX src fails due to temporary PDF in wrong directory
@ 2023-03-28 8:04 Christian Moe
2023-03-28 10:14 ` Ihor Radchenko
0 siblings, 1 reply; 9+ messages in thread
From: Christian Moe @ 2023-03-28 8:04 UTC (permalink / raw)
To: Orgmode
Hi,
I'm trying and failing to export images from TikZ code, apparently
because the temporary PDF is misplaced. Here is a minimal example just
exporting the PDF:
#+LATEX_HEADER: \usepackage{tikz}
#+header: :fit yes
#+begin_src latex :exports results :file ./test-tikz-triangle.png
\begin{tikzpicture} %
\draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
\end{tikzpicture}
#+end_src
Execution fails with an error message like this:
org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
produced. See "*Org PDF LaTeX Output*" for details
It turns out, however, that the missing temporary file, here
latex-IJVI84.pdf, is in fact correctly produced. The problem is that it
is produced in the same directory as the source org file, not in the
temp directory.
I've had a quick look at org-compile-file, but don't understand what is
going wrong.
I'm running Org 9.6.2 on GNU Emacs 27.2 under Linux Mint, all very
vanilla.
Any suggestions?
Yours,
Christian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-28 8:04 File generation from LaTeX src fails due to temporary PDF in wrong directory Christian Moe
@ 2023-03-28 10:14 ` Ihor Radchenko
0 siblings, 0 replies; 9+ messages in thread
From: Ihor Radchenko @ 2023-03-28 10:14 UTC (permalink / raw)
To: Christian Moe; +Cc: Orgmode
Christian Moe <mail@christianmoe.com> writes:
> I'm trying and failing to export images from TikZ code, apparently
> because the temporary PDF is misplaced. Here is a minimal example just
> exporting the PDF:
>
> #+LATEX_HEADER: \usepackage{tikz}
>
> #+header: :fit yes
> #+begin_src latex :exports results :file ./test-tikz-triangle.png
> \begin{tikzpicture} %
> \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
> \end{tikzpicture}
> #+end_src
>
> Execution fails with an error message like this:
>
> org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
> produced. See "*Org PDF LaTeX Output*" for details
I cannot reproduce.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
@ 2023-03-29 8:00 Pedro Andres Aranda Gutierrez
2023-03-29 17:31 ` chris
0 siblings, 1 reply; 9+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2023-03-29 8:00 UTC (permalink / raw)
To: Org Mode List, mail
On Tue, 28 Mar 2023 10:04:24 +0200, Christian Moe <mail@christianmoe.com> wrote
Hi,
> I'm trying and failing to export images from TikZ code, apparently
> because the temporary PDF is misplaced. Here is a minimal example just
> exporting the PDF:
> #+LATEX_HEADER: \usepackage{tikz}
>
> #+header: :fit yes
> #+begin_src latex :exports results :file ./test-tikz-triangle.png
> \begin{tikzpicture} %
> \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
> \end{tikzpicture}
> #+end_src
> Execution fails with an error message like this:
>
> org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
> produced. See "*Org PDF LaTeX Output*" for details
Hi Christian,
trying to reproduce this on a master (emacs30.0.50) on Ubuntu. To make it really
lightweight, I'm starting with
emacs -Q
but unfortunately, I'm not able to reproduce it here :(
My emacs:
GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
cairo version 1.16.0) of 2023-03-26
Would you please try again, calling with emacs -Q and giving a couple
clues more of your process to confirm... It may be that I'm too modern
;-)
Thx, /Pedro A.
--
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should
run a leader-deposed hook here, but we can't yet
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-29 8:00 Pedro Andres Aranda Gutierrez
@ 2023-03-29 17:31 ` chris
2023-03-29 21:15 ` Christian Moe
0 siblings, 1 reply; 9+ messages in thread
From: chris @ 2023-03-29 17:31 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 7403 bytes --]
On Wednesday, 29 March 2023 10:00:35 CEST Pedro Andres Aranda Gutierrez wrote:
> On Tue, 28 Mar 2023 10:04:24 +0200, Christian Moe <mail@christianmoe.com> wrote
> Hi,
>
> > I'm trying and failing to export images from TikZ code, apparently
> > because the temporary PDF is misplaced. Here is a minimal example just
> > exporting the PDF:
>
> > #+LATEX_HEADER: \usepackage{tikz}
> >
> > #+header: :fit yes
> > #+begin_src latex :exports results :file ./test-tikz-triangle.png
> > \begin{tikzpicture} %
> > \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
> > \end{tikzpicture}
> > #+end_src
>
> > Execution fails with an error message like this:
> >
> > org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
> > produced. See "*Org PDF LaTeX Output*" for details
>
> Hi Christian,
> trying to reproduce this on a master (emacs30.0.50) on Ubuntu. To make it really
> lightweight, I'm starting with
> emacs -Q
> but unfortunately, I'm not able to reproduce it here :(
Hi, I've been trying to have a similar example working for hours, specifically I was trying to follow https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html[1]
Could you provide more context because if I run emacs -Q here, with the example provided by OP, and type C-c C-c, I just get "no org-babel execute function for latex!".
So I guess it might have required a little more work than what I've just described.
Here is the setting I've used:
This in my dot-emacs.org file:
#+begin_src emacs-lisp
(with-eval-after-load 'org
(add-to-list 'org-latex-packages-alist '("" "stmaryrd" t))
(add-to-list 'org-latex-packages-alist '("" "tikz-cd" t))
(add-to-list 'org-latex-packages-alist '("" "amscd" t))
(add-to-list 'org-latex-packages-alist '("" "mathtools" t))
(add-to-list 'org-latex-packages-alist '("" "unicode-math" t))
;; (add-to-list 'org-latex-packages-alist '("" "breqn" t))
(add-to-list 'org-latex-packages-alist '("" "thisisastupidtestfile" t))
(setq org-latex-create-formula-image-program 'dvisvgm) ;; probably only this line is relevant with the matter at hand
(setq org-format-latex-options
(plist-put org-format-latex-options :scale 0.80)))
#+end_src
With this, when I put the following in some org file and type C-c C-x C-l I immediately get a org-latex-preview of the tikz snippet:
\begin{tikzpicture} %
\draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0]
(-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
\filldraw (-1.5,0) circle[radius=1mm];
\filldraw (1.5,0) circle[radius=1mm];
\end{tikzpicture}
Now If I use the following and type C-c C-c, I never get anything in multiple ways:
Note that I've also tried with imagemagick...
#+name: test_plot_png
#+header: :exports results :file test.svg
#+header: :dvisvgm yes
#+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}")
#+begin_src latex :file test.svg
\begin{tikzpicture} %
\draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0]
(-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
\filldraw (-1.5,0) circle[radius=1mm];
\filldraw (1.5,0) circle[radius=1mm];
\end{tikzpicture}
#+end_src
Many times a pdf is generated in the /tmp/ directory but that pdf is gibberish. When I go from the latex file to the pdf using pdflatex, only gibberish pdf is generated, no relation with the image that should be generated.
If instead I use lualatex, the pdf is correctly generated.
Anyway, I've been experimenting for hours, and I have no idea how to have the thing working.
I also used that code someone gave me:
#+begin_src emacs-lisp
(set-variable 'org-preview-latex-process-alist
'((dvipng :programs ; Was here originally.
("latex" "dvipng")
:description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvipng -D %D -T tight -o %O %f"))
(dvisvgm :programs ; Was here originally.
("latex" "dvisvgm")
:description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-output-type "svg" :image-size-adjust
(1.7 . 1.5)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvisvgm %f -n -b min -c %S -o %O"))
(imagemagick :programs ; The recommended "new" way.
("latex" "convert")
:description "pdf > png" :message "you need to install the programs: latex and imagemagick." :image-input-type "pdf" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("lualatex -interaction nonstopmode -output-directory %o %f")
:image-converter
("convert -density %D -trim -antialias %f -quality 100 %O"))))
#+end_src
No luck at all there neither.
BTW, when I do C-c C-c on the OP example, after having evaluated
#+begin_src emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'((latex . t)))
#+end_src
No pdf, no output, only an empty latex file generated in /tmp
Bottom line, I'd really like to know how this hole thing is supposed to work.
org-preview latex working perfectly fine though.
Note: The reason I want to have this working is that I want to export to html. Plain latex formula are displayed very very well using mathjax. But TiKz things are not working.
So even though I've got a near wysiwyg in emacs, I can't have that exported to html.
What I'd like to have is plain latex formulas exported to mathjax and tikz diagrams exported using the SVG image.
Initially my setting wasn't even using imagemagick, only dvisvgm.
Also it seems we have three ways to do the exact same thing:
org-latex-preview which works perfectly with minimal effort on my box,
the C-c C-c thing,
and the org-html-export-to-html thing.
Each using independent workflow. Though probably not completely independent though.
My emacs is master from a month ago.
Cheers,
Chris
>
> My emacs:
>
> GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
> cairo version 1.16.0) of 2023-03-26
>
> Would you please try again, calling with emacs -Q and giving a couple
> clues more of your process to confirm... It may be that I'm too modern
> ;-)
>
> Thx, /Pedro A.
>
>
--------
[1] https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
[-- Attachment #2: Type: text/html, Size: 22157 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-29 17:31 ` chris
@ 2023-03-29 21:15 ` Christian Moe
2023-03-30 5:16 ` chris
0 siblings, 1 reply; 9+ messages in thread
From: Christian Moe @ 2023-03-29 21:15 UTC (permalink / raw)
To: emacs-orgmode; +Cc: inkbottle007, Pedro Andres Aranda Gutierrez, Ihor Radchenko
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.
Yours,
Christian
chris writes:
> On Wednesday, 29 March 2023 10:00:35 CEST Pedro Andres Aranda Gutierrez wrote:
>> On Tue, 28 Mar 2023 10:04:24 +0200, Christian Moe <mail@christianmoe.com> wrote
>> Hi,
>>
>> > I'm trying and failing to export images from TikZ code, apparently
>> > because the temporary PDF is misplaced. Here is a minimal example just
>> > exporting the PDF:
>>
>> > #+LATEX_HEADER: \usepackage{tikz}
>> >
>> > #+header: :fit yes
>> > #+begin_src latex :exports results :file ./test-tikz-triangle.png
>> > \begin{tikzpicture} %
>> > \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
>> > \end{tikzpicture}
>> > #+end_src
>>
>> > Execution fails with an error message like this:
>> >
>> > org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
>> > produced. See "*Org PDF LaTeX Output*" for details
>>
>> Hi Christian,
>> trying to reproduce this on a master (emacs30.0.50) on Ubuntu. To make it really
>> lightweight, I'm starting with
>> emacs -Q
>> but unfortunately, I'm not able to reproduce it here :(
>
> Hi, I've been trying to have a similar example working for hours, specifically I was trying to follow https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html[1]
>
> Could you provide more context because if I run emacs -Q here, with the example provided by OP, and type C-c C-c, I just get "no org-babel execute function for latex!".
> So I guess it might have required a little more work than what I've just described.
>
> Here is the setting I've used:
>
> This in my dot-emacs.org file:
> #+begin_src emacs-lisp
> (with-eval-after-load 'org
> (add-to-list 'org-latex-packages-alist '("" "stmaryrd" t))
> (add-to-list 'org-latex-packages-alist '("" "tikz-cd" t))
> (add-to-list 'org-latex-packages-alist '("" "amscd" t))
> (add-to-list 'org-latex-packages-alist '("" "mathtools" t))
> (add-to-list 'org-latex-packages-alist '("" "unicode-math" t))
> ;; (add-to-list 'org-latex-packages-alist '("" "breqn" t))
> (add-to-list 'org-latex-packages-alist '("" "thisisastupidtestfile" t))
> (setq org-latex-create-formula-image-program 'dvisvgm) ;; probably only this line is relevant with the matter at hand
> (setq org-format-latex-options
> (plist-put org-format-latex-options :scale 0.80)))
> #+end_src
>
> With this, when I put the following in some org file and type C-c C-x C-l I immediately get a org-latex-preview of the tikz snippet:
> \begin{tikzpicture} %
> \draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0]
> (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
> \filldraw (-1.5,0) circle[radius=1mm];
> \filldraw (1.5,0) circle[radius=1mm];
> \end{tikzpicture}
>
> Now If I use the following and type C-c C-c, I never get anything in multiple ways:
> Note that I've also tried with imagemagick...
> #+name: test_plot_png
> #+header: :exports results :file test.svg
> #+header: :dvisvgm yes
> #+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}")
> #+begin_src latex :file test.svg
> \begin{tikzpicture} %
> \draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0]
> (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
> \filldraw (-1.5,0) circle[radius=1mm];
> \filldraw (1.5,0) circle[radius=1mm];
> \end{tikzpicture}
> #+end_src
>
> Many times a pdf is generated in the /tmp/ directory but that pdf is gibberish. When I go from the latex file to the pdf using pdflatex, only gibberish pdf is generated, no relation with the image that should be generated.
> If instead I use lualatex, the pdf is correctly generated.
> Anyway, I've been experimenting for hours, and I have no idea how to have the thing working.
>
> I also used that code someone gave me:
> #+begin_src emacs-lisp
> (set-variable 'org-preview-latex-process-alist
> '((dvipng :programs ; Was here originally.
> ("latex" "dvipng")
> :description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust
> (1.0 . 1.0)
> :latex-compiler
> ("latex -interaction nonstopmode -output-directory %o %f")
> :image-converter
> ("dvipng -D %D -T tight -o %O %f"))
> (dvisvgm :programs ; Was here originally.
> ("latex" "dvisvgm")
> :description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-output-type "svg" :image-size-adjust
> (1.7 . 1.5)
> :latex-compiler
> ("latex -interaction nonstopmode -output-directory %o %f")
> :image-converter
> ("dvisvgm %f -n -b min -c %S -o %O"))
> (imagemagick :programs ; The recommended "new" way.
> ("latex" "convert")
> :description "pdf > png" :message "you need to install the programs: latex and imagemagick." :image-input-type "pdf" :image-output-type "png" :image-size-adjust
> (1.0 . 1.0)
> :latex-compiler
> ("lualatex -interaction nonstopmode -output-directory %o %f")
> :image-converter
> ("convert -density %D -trim -antialias %f -quality 100 %O"))))
> #+end_src
>
> No luck at all there neither.
>
> BTW, when I do C-c C-c on the OP example, after having evaluated
> #+begin_src emacs-lisp
> (org-babel-do-load-languages
> 'org-babel-load-languages
> '((latex . t)))
> #+end_src
>
> No pdf, no output, only an empty latex file generated in /tmp
>
>
> Bottom line, I'd really like to know how this hole thing is supposed to work.
> org-preview latex working perfectly fine though.
>
> Note: The reason I want to have this working is that I want to export to html. Plain latex formula are displayed very very well using mathjax. But TiKz things are not working.
> So even though I've got a near wysiwyg in emacs, I can't have that exported to html.
> What I'd like to have is plain latex formulas exported to mathjax and tikz diagrams exported using the SVG image.
> Initially my setting wasn't even using imagemagick, only dvisvgm.
>
> Also it seems we have three ways to do the exact same thing:
> org-latex-preview which works perfectly with minimal effort on my box,
> the C-c C-c thing,
> and the org-html-export-to-html thing.
> Each using independent workflow. Though probably not completely independent though.
>
> My emacs is master from a month ago.
>
> Cheers,
> Chris
>
>
>
>>
>> My emacs:
>>
>> GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
>> cairo version 1.16.0) of 2023-03-26
>>
>> Would you please try again, calling with emacs -Q and giving a couple
>> clues more of your process to confirm... It may be that I'm too modern
>> ;-)
>>
>> Thx, /Pedro A.
>>
>>
>
>
>
> --------
> [1] https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-29 21:15 ` Christian Moe
@ 2023-03-30 5:16 ` chris
2023-03-30 11:15 ` Christian Moe
0 siblings, 1 reply; 9+ messages in thread
From: chris @ 2023-03-30 5:16 UTC (permalink / raw)
To: emacs-orgmode
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.
Anyway
You start from that:
#+begin_src emacs-lisp
(setq org-latex-compiler "lualatex")
#+end_src
#+name: circle
#+header: :results file drawer
#+header: :file circle.svg
#+header: :dvisvgm yes
#+header: :headers '("\\usepackage{tikz}")
#+begin_src latex
\begin{tikzpicture}
\fill[yellow] (0,0) circle (3cm);
\end{tikzpicture}
#+end_src
You do C-c C-c on both blocks.
Looking at *Messages* you see there is a file
```
cat /tmp/babel-DQ59bY/latex-2whyWA.tex
\documentclass[preview]{standalone}
\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{tikz}\begin{document}\begin{tikzpicture}
\fill[yellow] (0,0) circle (3cm);
\end{tikzpicture}\end{document}
```
Among `latex`, `pdflatex`, `lualatex`, `htlatex`, the latex file can only be
successfully processed by `htlatex`, which will produces several outputs:
```
ls *2whyWA*
latex-2whyWA-1.svg latex-2whyWA.4tc latex-2whyWA.css latex-2whyWA.html
latex-2whyWA.lg latex-2whyWA.tmp
latex-2whyWA.4ct latex-2whyWA.aux latex-2whyWA.dvi latex-2whyWA.idv
latex-2whyWA.log latex-2whyWA.xref
```
One of them is `svg` file and is correct.
I've tried replacing `(setq org-latex-compiler "lualatex")` by every possible
latex compiler listed above.
I've also tried replacing `#+header: :dvisvgm yes` by `htlatex` and
`inkscape`.
In every case I get the gibberish output, specifically an image of the listing
of the svg output, or in any case something resembling to `XML`.
Something else I can do "by hand":
```
lualatex -jobname=foo <(sed '/pgfsysdriver/d' /tmp/babel-DQ59bY/
latex-2whyWA.tex); dvisvgm --pdf --output=foo.svg foo.pdf
```
then:
```
$ cat foo.svg
<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 3.0.3 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://
www.w3.org/1999/xlink' width='170.079pt' height='170.079
pt' viewBox='0 -170.079 170.079 170.079'>
<g id='page1'>
<g transform='matrix(1 0 0 -1 0 0)'>
<path d='M170.0781 85.039061C170.0781 132.0078 132.0078 170.0781 85.039061
170.0781C38.0703 170.0781 0 132.0078 0 85.039061C0 38.0
703 38.0703 0 85.039061 0C132.0078 0 170.0781 38.0703 170.0781 85.039061Z'
fill='#ff0'/>
</g>
</g>
</svg>
$ cat latex-2whyWA-1.svg
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<?xml-stylesheet href="latex-2whyWA.css" type="text/css"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/
xlink" width="170.71652pt" height="170.71652pt" viewBo
x="-85.35826 -85.35826 170.71652 170.71652 ">
<g transform="translate(0, 85.35826 ) scale(1,-1) translate(0,85.35826 )">
<g stroke="#000" fill="#000">
<g stroke-width="0.4">
<g stroke="#ff0" fill="#ff0">
<path d=" M 0.0 0.0 M 85.35826 0.0 C 85.35826 47.14267 47.14267 85.35826 0.0
85.35826 C -47.14267 85.35826 -85.35826 47.14267 -85
.35826 0.0 C -85.35826 -47.14267 -47.14267 -85.35826 0.0 -85.35826 C 47.14267
-85.35826 85.35826 -47.14267 85.35826 0.0 Z M 0.0 0.
0 " stroke="none"/>
</g>
</g>
</g>
</g>
</svg>
```
I got that last trick from [[https://en.wikipedia.org/wiki/
Wikipedia:Graphics_Lab/Resources/PDF_conversion_to_SVG]]
We can see both files have the exact same size, `foo.svg` is 548 bytes,
`latex-2whyWA-1.svg` is 855 bytes.
`foo.svg` is superior in that it uses `utf-8` encoding, which is superior.
bitmaps outputs for `tikz` are not nice.
So two ways to do it by hand, and it would be nice to have it doing it
automatically.
Wikipedia says `inkscape` method can yield heavy results, and indeed I had to
install `potrace`.
They say in the stackexchange page that `pdflatex+inkscape` is the default
method, so even it didn't work at all, I followed the instruction it gave me
to first install `inkscape` and then install `potrace`.
What I like best is:
```
lualatex -jobname=foo <(sed '/pgfsysdriver/d' /tmp/babel-DQ59bY/
latex-2whyWA.tex); dvisvgm --pdf --output=foo.svg foo.pdf
```
It would be easier if second line `\def\pgfsysdriver{pgfsys-tex4ht.def}` was
not inserted in the first place.
I think the way plain `org-latex-preview`, which work for me, are generated is
through `latex + dvisvgm` and I think that in this case the above
`\def\pgfsysdriver{pgfsys-tex4ht.def}` isn't used neither.
Using "old" `latex` can be troublesome in some cases though, namely everytime
somebody is trying to use some `utf-8`.
Best,
Chris
> Yours,
> Christian
>
>
> chris writes:
>
> > On Wednesday, 29 March 2023 10:00:35 CEST Pedro Andres Aranda Gutierrez
wrote:
> >> On Tue, 28 Mar 2023 10:04:24 +0200, Christian Moe <mail@christianmoe.com>
wrote
> >> Hi,
> >>
> >> > I'm trying and failing to export images from TikZ code, apparently
> >> > because the temporary PDF is misplaced. Here is a minimal example just
> >> > exporting the PDF:
> >>
> >> > #+LATEX_HEADER: \usepackage{tikz}
> >> >
> >> > #+header: :fit yes
> >> > #+begin_src latex :exports results :file ./test-tikz-triangle.png
> >> > \begin{tikzpicture} %
> >> > \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle;
> >> > \end{tikzpicture}
> >> > #+end_src
> >>
> >> > Execution fails with an error message like this:
> >> >
> >> > org-compile-file: File "/tmp/babel-Tay2kl/latex-IJVI84.pdf" wasn’t
> >> > produced. See "*Org PDF LaTeX Output*" for details
> >>
> >> Hi Christian,
> >> trying to reproduce this on a master (emacs30.0.50) on Ubuntu. To make it
really
> >> lightweight, I'm starting with
> >> emacs -Q
> >> but unfortunately, I'm not able to reproduce it here :(
> >
> > Hi, I've been trying to have a similar example working for hours,
specifically I was trying to follow https://orgmode.org/worg/org-contrib/babel/
languages/ob-doc-LaTeX.html[1]
> >
> > Could you provide more context because if I run emacs -Q here, with the
example provided by OP, and type C-c C-c, I just get "no org-babel execute
function for latex!".
> > So I guess it might have required a little more work than what I've just
described.
> >
> > Here is the setting I've used:
> >
> > This in my dot-emacs.org file:
> > #+begin_src emacs-lisp
> > (with-eval-after-load 'org
> > (add-to-list 'org-latex-packages-alist '("" "stmaryrd" t))
> > (add-to-list 'org-latex-packages-alist '("" "tikz-cd" t))
> > (add-to-list 'org-latex-packages-alist '("" "amscd" t))
> > (add-to-list 'org-latex-packages-alist '("" "mathtools" t))
> > (add-to-list 'org-latex-packages-alist '("" "unicode-math" t))
> > ;; (add-to-list 'org-latex-packages-alist '("" "breqn" t))
> > (add-to-list 'org-latex-packages-alist '("" "thisisastupidtestfile"
t))
> > (setq org-latex-create-formula-image-program 'dvisvgm) ;; probably
only this line is relevant with the matter at hand
> > (setq org-format-latex-options
> > (plist-put org-format-latex-options :scale 0.80)))
> > #+end_src
> >
> > With this, when I put the following in some org file and type C-c C-x C-l I
immediately get a org-latex-preview of the tikz snippet:
> > \begin{tikzpicture} %
> > \draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end
angle=0]
> > (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) --
(3,0);
> > \filldraw (-1.5,0) circle[radius=1mm];
> > \filldraw (1.5,0) circle[radius=1mm];
> > \end{tikzpicture}
> >
> > Now If I use the following and type C-c C-c, I never get anything in
multiple ways:
> > Note that I've also tried with imagemagick...
> > #+name: test_plot_png
> > #+header: :exports results :file test.svg
> > #+header: :dvisvgm yes
> > #+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}")
> > #+begin_src latex :file test.svg
> > \begin{tikzpicture} %
> > \draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end
angle=0]
> > (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) --
(3,0);
> > \filldraw (-1.5,0) circle[radius=1mm];
> > \filldraw (1.5,0) circle[radius=1mm];
> > \end{tikzpicture}
> > #+end_src
> >
> > Many times a pdf is generated in the /tmp/ directory but that pdf is
gibberish. When I go from the latex file to the pdf using pdflatex, only
gibberish pdf is generated, no relation with the image that should be
generated.
> > If instead I use lualatex, the pdf is correctly generated.
> > Anyway, I've been experimenting for hours, and I have no idea how to have
the thing working.
> >
> > I also used that code someone gave me:
> > #+begin_src emacs-lisp
> > (set-variable 'org-preview-latex-process-alist
> > '((dvipng :programs ; Was here originally.
> > ("latex" "dvipng")
> > :description "dvi > png" :message "you need
to install the programs: latex and dvipng." :image-input-type "dvi" :image-
output-type "png" :image-size-adjust
> > (1.0 . 1.0)
> > :latex-compiler
> > ("latex -interaction nonstopmode -output-
directory %o %f")
> > :image-converter
> > ("dvipng -D %D -T tight -o %O %f"))
> > (dvisvgm :programs ; Was here originally.
> > ("latex" "dvisvgm")
> > :description "dvi > svg" :message "you need
to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-
output-type "svg" :image-size-adjust
> > (1.7 . 1.5)
> > :latex-compiler
> > ("latex -interaction nonstopmode -output-
directory %o %f")
> > :image-converter
> > ("dvisvgm %f -n -b min -c %S -o %O"))
> > (imagemagick :programs ; The recommended "new" way.
> > ("latex" "convert")
> > :description "pdf > png" :message "you
need to install the programs: latex and imagemagick." :image-input-type "pdf"
:image-output-type "png" :image-size-adjust
> > (1.0 . 1.0)
> > :latex-compiler
> > ("lualatex -interaction nonstopmode -
output-directory %o %f")
> > :image-converter
> > ("convert -density %D -trim -antialias
%f -quality 100 %O"))))
> > #+end_src
> >
> > No luck at all there neither.
> >
> > BTW, when I do C-c C-c on the OP example, after having evaluated
> > #+begin_src emacs-lisp
> > (org-babel-do-load-languages
> > 'org-babel-load-languages
> > '((latex . t)))
> > #+end_src
> >
> > No pdf, no output, only an empty latex file generated in /tmp
> >
> >
> > Bottom line, I'd really like to know how this hole thing is supposed to
work.
> > org-preview latex working perfectly fine though.
> >
> > Note: The reason I want to have this working is that I want to export to
html. Plain latex formula are displayed very very well using mathjax. But TiKz
things are not working.
> > So even though I've got a near wysiwyg in emacs, I can't have that
exported to html.
> > What I'd like to have is plain latex formulas exported to mathjax and tikz
diagrams exported using the SVG image.
> > Initially my setting wasn't even using imagemagick, only dvisvgm.
> >
> > Also it seems we have three ways to do the exact same thing:
> > org-latex-preview which works perfectly with minimal effort on my box,
> > the C-c C-c thing,
> > and the org-html-export-to-html thing.
> > Each using independent workflow. Though probably not completely independent
though.
> >
> > My emacs is master from a month ago.
> >
> > Cheers,
> > Chris
> >
> >
> >
> >>
> >> My emacs:
> >>
> >> GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
> >> cairo version 1.16.0) of 2023-03-26
> >>
> >> Would you please try again, calling with emacs -Q and giving a couple
> >> clues more of your process to confirm... It may be that I'm too modern
> >> ;-)
> >>
> >> Thx, /Pedro A.
> >>
> >>
> >
> >
> >
> > --------
> > [1] https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-30 5:16 ` chris
@ 2023-03-30 11:15 ` Christian Moe
2023-03-31 5:25 ` chris
0 siblings, 1 reply; 9+ messages in thread
From: Christian Moe @ 2023-03-30 11:15 UTC (permalink / raw)
To: emacs-orgmode
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.
Yours,
Christian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-30 11:15 ` Christian Moe
@ 2023-03-31 5:25 ` chris
2023-03-31 7:36 ` Christian Moe
0 siblings, 1 reply; 9+ messages in thread
From: chris @ 2023-03-31 5:25 UTC (permalink / raw)
To: emacs-orgmode
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
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: File generation from LaTeX src fails due to temporary PDF in wrong directory
2023-03-31 5:25 ` chris
@ 2023-03-31 7:36 ` Christian Moe
0 siblings, 0 replies; 9+ messages in thread
From: Christian Moe @ 2023-03-31 7:36 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-03-31 7:37 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-28 8:04 File generation from LaTeX src fails due to temporary PDF in wrong directory Christian Moe
2023-03-28 10:14 ` Ihor Radchenko
-- strict thread matches above, loose matches on Subject: below --
2023-03-29 8:00 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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.