2

In my org-mode file I have some LaTeX equations using tikz and tikz-cd packages:

#+TITLE: Mixing tikz and equations

* An example

\begin{equation*}
\begin{tikzcd}
A\arrow[yshift=.7ex,r,"f"]
 \arrow[yshift=-.7ex,r,swap,"g"] & B
\end{tikzcd}
\end{equation*}

I have added tikz and tikz-cd packages to org-latex-packages-alist with value:

(("" "tikz-cd" t) ("" "tikz" t))

and I have customized org-latex-pdf-process as follows:

(setq org-latex-pdf-process
        '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "biber %b"
          "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"))

With this configuration, I can export the document to pdf: enter image description here

However this does not work when exporting html:

enter image description here

If I try to export only the equation fragment (with C-c C-x C-l) I get this error:

org-compile-file: File "/tmp/orgtexayOYxL.dvi" wasn’t produced. Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.

Unfortunately, the org-preview-latex-process-alist variable does not seem easy to configure... and I need help here.

In short: what would be a clean configuration to be able to export my org mode document both in pdf and html?


Update:

I do not know if it helps...

Adapted from https://www.homepages.ucl.ac.uk/~ucahjde/blog/tikz.html

#+HEADER: :file contour.png :imagemagick yes :eval no-export
#+HEADER: :results raw :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

works for figures, but I would like to make it works for equations.

2
  • 1
    The following sentence in the tikzcd package documentation indicates that dvipng is not the right tool for tikzcd: "It is important to note thatdviviewers will not display diagrams correctly. It is necessary to convert thedvifile topdforpsformat—or, even better, use a tool that generatespdffiles directly, such aspdflatex." Maybe, you should rather convert to pdf. – Tobias Feb 22 '20 at 0:38
  • @Tobias thank you for your interest. I missed this from the doc, but in practice, I have not observed problems for the basic tikz figures I use (also see my post update). Also I am still interested by an answer as I really wonder how to cleanly configure Emacs/OrgMode to manage both html & pdf exports of equations with tikz (even if png convertion may not work properly in all cases) – Picaud Vincent Feb 22 '20 at 8:36

Your Answer

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

Browse other questions tagged or ask your own question.