I keep being stymied by the apparent incompatibility of HTML and LaTeX export. Here's what I have in my .org file header:

#+LATEX_CLASS: article
#+LATEX_HEADER: \usepackage{tikz}
#+LATEX_HEADER: \usepackage{commath}
#+LATEX_HEADER: \usepackage{stackengine}
#+LaTeX_HEADER: \usepackage{pgfplots}
#+LaTeX_HEADER: \usepackage{sansmath}
#+LATEX_HEADER: \usepackage{mathtools}
#+LaTeX_HEADER: \usepackage{amsmath}

In reality, I don't know if this gets seen by orgmode export to HTML, perhaps by export to LaTeX? So to start, here is working piece of markup that displays great in both HTML and LaTeX:

#+begin_src latex :packages '(("" "tikz")) :exports results :results output raw :file other12.png :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 500


    \draw[step=1cm,thin,gray!60] (-6,-6) grid (6,6);
    \draw[<->] (-6,0)--(6,0) node[right]{$x$};
    \draw[<->] (0,-6)--(0,6) node[above]{$y$};
    \draw[line width=2pt,blue,-stealth](0,0)--(4,-3) node[anchor=south west]{$\boldsymbol{(4,-3)}$};
    \draw[line width=2pt,gray,-stealth](2,3)--(6,0) node[anchor=south west];
    \draw[line width=2pt,gray,-stealth](-5,4)--(-1,1) node[anchor=south west];
    \draw[line width=2pt,gray,-stealth](-3,-1)--(1,-4) node[anchor=south west];
\draw [decorate,color=red,decoration={brace,amplitude=10pt},xshift=-0pt,yshift=0pt] (-5.0,1.0) -- (-5.0,4.0) node [red,midway,xshift=-0.65cm] 
{\footnotesize $-3$};
    \draw [decorate,color=red,decoration={brace,amplitude=10pt,mirror,raise=1pt},xshift=-0pt,yshift=0pt] (-5,1) -- (-1,1) node [red,midway,yshift=-0.6cm] {\footnotesize $4$};


This also displays in both HTML and LaTeX correctly:

\|x\|&=\sqrt{4^2+(-3)^2} \\
&= \sqrt{25} \\
&= 5

as well as this:

    x = \begin{pmatrix}
        \phantom{-} 4 \\
           -3 \\

but this on the HTML side


doesn't know what \setstackEOL{\\} is, nor \parenVectorstack[r] and displays mangled. The LaTeX export looks fine, though. And if I put it in a LaTeX babel code block, it disappears from the HTML entirely, while, again, the LaTeX export displays just fine. Confusing is how the Tikz code block is displayed in both HTML and LaTeX, but any other attempt at a LaTeX code block is ignored and left completely out of the HTML export.

My educated guess is that the org-mode HTML export processes is handled by MathJax, which is a subset of LaTeX. But then I'd like to know definitively what can be done and what cannot be done LaTeX-wise for the HTML export.


As I've researched this issue, it seems like a very big, complicated, outwardly-billowing, crawling-across-broken-glass trial-and-error slugfest that will take a serious sorting out. The "documentation" at orgmode.org here is hardly better than a reference dump, i.e., it will require painstaking, meticulous trial-and-error to sort out what exactly can and cannot be done, culminating in a user/beginner-friendly tutorial write-up. Hence, I absolve the community of answering this. Till then, I lay this on ice.. . . . .

  • I wish org-export was replaced by an interface to Pandoc, which is a very well designed software to convert between text file formats. Feb 8 '20 at 23:38
  • 1
    @scaramouche ox-pandoc is available via melpa.
    – Tobias
    Feb 9 '20 at 1:52

You already discovered yourself that MathJax does not offer all the finesses of LaTeX.

That is the main reason why you can use another LaTeX-backend for HTML export with the help of the tex option of the html exporter. Example:

#+OPTIONS: tex:dvipng

Choosing dvipng as LaTeX backend, your document is exported fine to HTML.

  • Thanks for your response. But if I'm not mistaken, using dvipng converts any LaTeX math markup to little png images, which may or may not fit the surrounding text size and font-wise. I especially like the MathJax feature of being able to right-click on a formula and get the underlying LaTeX markup.
    – 147pm
    Feb 10 '20 at 15:19
  • @147pm In my experience, dvipng or dvisvgm is the only way to ensure some degree of consistency between latex and html when you have a complex latex setup, e.g. lots of latex packages. Some packages are available for mathjax, e.g. physics.js etc. but not all. User-defined LaTeX macros (\newcommand etc) also need to be redefined for html if you use mathjax, but not if you use dvipng or dvisvgm. However, as you say, these latex drivers create lots of small images and their placement (vertical alignment in particular) is dodgy. References to equation numbers using org's #+name also seems to fail. Feb 19 at 6:28

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.