emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: latex block tikz to svg


From: Edouard Debry
Subject: Re: latex block tikz to svg
Date: Mon, 18 Apr 2022 15:23:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (windows-nt)

Hi,

I finally found a way to make the following example work

<===========================================================>
#+HEADER: :file test1.svg
#+HEADER: :exports results
#+HEADER: :results output silent graphics file
#+HEADER: :headers '("\\usepackage{tikz}")
#+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=3mm];
\end{tikzpicture}
#+end_src
<===========================================================>

In file ob-latex.el, I commented out the lines beginning with ((string=
"svg" extension) :
         ;; ((string= "svg" extension)
         ;;  (with-temp-file tex-file
         ;;    (insert (concat (funcall org-babel-latex-preamble params)
         ;;                 (mapconcat #'identity headers "\n")
         ;;                 (funcall org-babel-latex-begin-env params)
         ;;                 body
         ;;                 (funcall org-babel-latex-end-env params))))
         ;;  (let ((tmp-pdf (org-babel-latex-tex-to-pdf tex-file)))
         ;;    (let* ((log-buf (get-buffer-create "*Org Babel LaTeX Output*"))
         ;;           (err-msg "org babel latex failed")
         ;;           (img-out (org-compile-file
         ;;                     tmp-pdf
         ;;                     (list org-babel-latex-pdf-svg-process)
         ;;                     extension err-msg log-buf)))
         ;;      (shell-command (format "mv %s %s" img-out out-file)))))

This part is responsible for the previous example to fail. What actually
breaks the svg production is the latex preamble. "pdflatex" fails itself
to produce a valid pdf file.


After that, I changed
((and (string= "html" extension)
               (executable-find org-babel-latex-htlatex))

into

((and (or (string= "html" extension) (string= "svg" extension))
               (executable-find org-babel-latex-htlatex))

Then, previous example, is compiled no more by "pdflatex" but by
"htlatex", this latter is able to produce svg directly.

I hope I do not introduce any side effects in doing so. There are several ways
to produce svg :
- pdflatex + inkscape (default with current org implementation)
- latex + dvisvgm
- pdflatex + pdf2svg
- htlatex (my choice above)

Ideally, all ways could be implemented and orgmode's user should choose
which way to use through a header parameter. As far as I could
understand, "htlatex" is the faster (direct) and cleaner way to produce
svg, but it may lack some advanced features, which is probably why, at the 
moment, the default way is through pdf generation.

Regards
  
Juan Manuel MacĂ­as <maciaschain@posteo.net> writes:

> Hi Edouard,
>
> Edouard Debry writes:
>
>> I would like to find a way to generate svg images from latex src blocks
>> (using tikz) which works and is compatible with default orgmode settings
>> for latex export (at least does not break it)
>>
>> Did you experience such issues ? do you have some workings settings and
>> examples ? I googled several times "org latex block tikz svg", but it is
>> difficult to guess how relevant are the elements found, some of them
>> seems quiet outdated. Hence my question on this mailing list
>
> I've done some quick tests with your example block. I don't know if I'm
> wrong, but I think the problem is on line 27 of `org-babel-execute:latex':
>
> ((string= "svg" extension)
>
> I don't know if this should be considered an Org bug, but it's clear
> that if the svg extension is detected in :file, the ':imagemagick yes'
> option is ignored, and a type of preamble is generated that fails in
> pgfsysdriver when compiling the temp tex document:
>
> \documentclass[preview]{standalone}
> \def\pgfsysdriver{pgfsys-tex4ht.def}
>
> If I replace the above line with this conditional:
>
> ((and (string= "svg" extension) (not imagemagick))
>
> then the imagemagick option is taken into account: it creates correctly
> the pdf and then converts it to svg with 'convert' imagemagick program.
> I did have to remove this line though:
>
> #+HEADER: :imoutoptions -geometry 400 :iminoptions -density 600
>
> otherwise, the conversion produced a dark image.
>
> Best regards,
>
> Juan Manuel 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]