1

I want to create both PDF and HTML figures using Tikz for both purposes. I am doing as it is explained in here, answer of nberth. To do this, I installed imagemagick for windows because this solution uses imagemagick's convert tool. But I think Windows version of imagemagick does not include convert tool and even if it did, convert is a Windows file system utility. So I can't get SVG outputs working in Windows. Has anyone achieved this on Windows? What would you suggest.

  • According to this page imagemagick version 7 uses the magick command in place of convert under windows. – Tobias Jan 4 '17 at 6:32
  • Pityingly, convert is hard-coded in many places in my version of orgmode (8.3.4). Examples are org-create-formula-image-with-imagemagick and org-create-formula-image. – Tobias Jan 4 '17 at 6:42
  • Yes, that was my problem. I found the program to be magick but I don't know how can I modify org-mode to use it. – meguli Jan 4 '17 at 9:30
2

Here is what I did to resolve the issue, I went for doing things with PNG rather than SVG:

First we are going to use Imagemagick to convert from PDF to SVG or PNG. For this purposes, Imagemagick uses gswin32c on Windows which comes when you install Ghostscript. So firts install these two programs and add their executable directories to your PATH.

On Windows, the program Imagemagick uses for conversion is called magick, not convert. Org-mode assumes it is convert by default. We need to change this. Open ob-latex.elwhich you can find under your Emacs installation or your .emacsd folder. There you will find a function definition like:

(defun convert-pdf (pdffile out-file im-in-options im-out-options)
    "Generate a file from a pdf file using imagemagick."
     (let ((cmd (concat "convert " im-in-options " " pdffile " "
            im-out-options " " out-file)))
     (message (concat "Converting pdffile file " cmd  "..."))
     (shell-command cmd)))

Change the "convert " part into "magick ". This should now work. For example, I have folowing Tikz picture in my org-file.

#+NAME: fsa
#+HEADER: :iminoptions -density 300 
#+HEADER: :imoutoptions -resize 240x360 
#+HEADER: :file (by-backend (latex "./img/fsa.png") (t "./img/fsa.png"))
#+BEGIN_SRC latex :results raw file
  \usetikzlibrary{trees}
  \begin{tikzpicture}
    \node [circle, draw, fill=red!20] at (-3,0) {1}
     child { node [circle, draw, fill=blue!30] {2}
     child { node [circle, draw, fill=green!30] {3} }
     child { node [circle, draw, fill=yellow!30] {4} }};
  \end{tikzpicture}
#+END_SRC

#+CAPTION: An FSA drawing
#+BEGIN_marginfig
  #+ATTR_LaTeX: :width 0.6 \marginparwidth
  #+RESULTS: fsa
#+END_marginfig

If I call export, this will embed fsa.png into my document. I first call HTML export because that what's creating PNG from the Tikz code. Then if I export to Latex after, that PNG file is included in \includegraphics. marginfig is a special block I defined for margin figures.

The hardcoded nature of convert program may be patched to handle OS nuances by org developers. For now, this is the fastest solution I have found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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