Hi Andreas,
Thank you for your reply. I've read the whole thread, and found your
example (the second link) very useful. Although for some reason, SVG
image is not working well on my machine (not being displayed in
chrome, nor on IE. I don't have firefox installed), but since the SVG
image generated by imagemagick is indeed a raster image, I don't see
any benefit using SVG over PNG, and exporting to PNG works perfectly.
I think I've come cross to the "by-backend" approach while searching
over the Internet, I found nothing about how by-backend is defined so
gave up. Even this tutorial [1] mention the use of by-backend, but
giving no information on what it is. Maybe it would be nice if
somebody write a tutorial on it and post on the website?
But in the other hand, I still think my proposal is still valid, since
my proposing extension would make it much easier and intuitive to
include advancedly typesetted contents to HTML with great freedom,
which remain the same semantics for the exporting to latex forms. I'd
like know what others think about it.
Also, to help other org-mode newbies to achieving including a diagram
or other figures typesetted with latex codes in HTML exports, I'd like
to sum up what's needed here:
1) make sure you have a latex environment and imagemagick installed on
your system
2) define the by-backend macro in ~/.emacs as
(defmacro by-backend (&rest body)
`(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
3) in the org file you want to include a latex rendered figure, add
latex preambles you need in the following format:
#+LATEX_HEADER: \usepackage{tikz}
4) include the latex code for the figure in a SRC block like the
following one:
#+HEADER: :packages '(("" "tikz"))
#+HEADER: :file (by-backend (latex "example_diagram.tikz") (html "example_diagram.png")
#+HEADER: :imagemagick yes :iminoptions -density 300
#+HEADER: :results file raw
#+HEADER: :fit yes
#+BEGIN_SRC latex
\begin{tikzpicture}
\node[red!50!black] (a) {A};
\node (b) [right of=a] {B};
\draw[->] (a) -- (b);
\end{tikzpicture}
#+END_SRC
Notes: the first line is important for the case of tikz, but may or
may not needed for your use case. the size of the image file could
be adjusted with the -density option passed to imagemagick
Bonus) you can use C-c C-x C-l to preview the latex block output,
and if you like, add the following to your ~/.emacs to scale the preview:
(plist-put org-format-latex-options :scale 1.5)
Regards,
Haochen