Tikz snippet preview in orgmode
2019-05-09, updated 2022-07-23 — emacs tech blog   ⇦Emacs Tramp asking for password – Baby white-woodpeckers are dumb⇨
For some reason, in my installation, both dvipng, and imagemgick don't work when using tikz, with errors such as the following when using a latex src block,
org-compile-file: File "/tmp/babel-aqvAMK/latex-Ehm75V.pdf" wasn’t produced. See "Org PDF LaTeX Output" for details
Or the image was simply not showing up.
My solution was to set use dvisvgm
(setq org-preview-latex-default-process 'dvisvgm)
This allows me to simply insert tikz code in my file, and the latex fragment will display it, as long as I have added the necessary header.
TODO dvisvgm has been broken after I updated emacs
\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}
It is also considerably faster than using dvipng, at least on my machine.
If you want to use the image in your html export, instead of your pdf export, you can create a .svg folder, and then run the following:
#+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