emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Edouard Debry <edouard.debry@gmail.com>
To: "Juan Manuel Macías" <maciaschain@posteo.net>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: latex block tikz to svg
Date: Mon, 18 Apr 2022 15:23:51 +0200	[thread overview]
Message-ID: <86v8v65xug.fsf@gmail.com> (raw)
In-Reply-To: <871r164aia.fsf@posteo.net> ("Juan Manuel Macías"'s message of "Mon, 17 Jan 2022 16:01:17 +0000")


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 


      parent reply	other threads:[~2022-04-18 13:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 14:14 latex block tikz to svg Edouard Debry
2022-01-17 16:01 ` Juan Manuel Macías
2022-01-25 23:24   ` Edouard Debry
2022-04-18 13:23   ` Edouard Debry [this message]

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=86v8v65xug.fsf@gmail.com \
    --to=edouard.debry@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=maciaschain@posteo.net \
    /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).