4

I'm try to use org-babel to generate images from tikz code.

The first code (take from this example) works perfectly, but when y want to export the tikz figure in a png (or a jpg) I have an error like :

org-compile-file: File "/tmp/babel-RNLDyr/latex-o3rO8d.pdf" wasn’t produced.  See "*Org PDF LaTeX Output*" for details

I can't find the cause of this error and the "Org PDF LaTeX Output" buffer does not exists.

Code use to make a svg (It's work) :

#+HEADER: :file ./images/contour.svg :imagemagick yes
#+HEADER: :results output silent :headers '("\\usepackage{tikz}")
#+HEADER: :fit yes :imoutoptions -geometry 400 :iminoptions -density 600
#+BEGIN_src latex
\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

Code use to make a png (It does not work) :

#+HEADER: :file ./images/contour.png :imagemagick yes
#+HEADER: :results output silent :headers '("\\usepackage{tikz}")
#+HEADER: :fit yes :imoutoptions -geometry 400 :iminoptions -density 600
#+BEGIN_src latex
\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

2 Answers 2

2

I was able to generate a PNG image of TikZ with the following minimal reproducible example.

In the GIF shown below, you can see that I execute emacs by using the -Q flag and by loading Lisp code present in the main.el file. The image is generated from the file main.org without any problem.

The following code block shows the content of the main.org file

#+LATEX_HEADER: \usepackage{tikz}

#+begin_src latex :file main.png :results file graphics
\begin{tikzpicture}
  \draw node[circle, draw] (a) {$a$}
        node[circle, draw, right of = a] (b) {$b$}
        node[circle, draw, below of = a] (c) {$c$}
        node[circle, draw, below of = b] (d) {$d$};
\end{tikzpicture}
#+end_src

The following code block shows the content of the main.el file

; The following configuration sets the font (demostration purposes)

(set-frame-font "Iosevka SS04 Light 30")

; The following configuration make Org Mode use imagemagick for processing images.
;
; This was retrieved from this question (https://emacs.stackexchange.com/questions/60696) I posted.

(setq org-preview-latex-default-process 'imagemagick)

; The following configuration disables the confirmation prompt whenever code blocks are evaluated.

(setq org-confirm-babel-evaluate nil)

; The following hook make images to be shown after code blocks are executed.

(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)

; The following configuration allows code blocks whose language is latex to be evaluated

(org-babel-do-load-languages 'org-babel-load-languages
                 '((latex . t)))

enter image description here

1
  • It's work, tanks. I don't know why, but the content of the :headers parameter does not seem to be used when the output file is a PNG. It's works using the #+LATEX_HEADER variable.
    – Atm
    Jan 11, 2021 at 15:33
1

It works for me, using

#+HEADER: :results file graphics

instead of

#+HEADER: :results output silent

The complete code is:

#+HEADER: :file contour.png :imagemagick yes
#+HEADER: :results file graphics :headers '("\\usepackage{tikz}") 
#+HEADER: :fit yes :imoutoptions -geometry 400 :iminoptions -density 600
#+BEGIN_src latex
\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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.