0

Briefly

If I org-latex-export-to-pdf an org file with SVG diagrams, I get a single self-contained file that can be conveniently sent as draft.

If I instead org-html-export-to-html (avoiding all the hassles of page breaks; making it easy to read the document on a non-exotic tablet; etc...), the SVG files remain outside the HTML file, making it necessary to tar-gzip a bundle of files. Yet SVG is eminently suitable for embedding in HTML.

Details

This is a sequel to a question asked earlier. In the present question we start directly from SVG files, not from Gnuplot.

If I start Emacs with a .emacs consisting of just this code, and export the org-mode file

#+HTML_EMBED_SVG: t
Here is a square.
[[./square.svg]]

to HTML, I am expecting to see the SVG file embedded in the HTML file, but I am instead seeing

<img src="./square.svg" alt="square.svg" class="org-svg" />

in the HTML file.

How can I embed SVG images when exporting to HTML from Org?

Versions

  • Org mode version 9.6.1
  • GNU Emacs 30.0.50

This bleeding-edge pre-release of Emacs is compelling because it natively supports viewing SVG figures inline in the Emacs buffer.

MWE completeness

To make this a self-contained MWE, here is square.svg.

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100"
     viewBox="0 0 100 100"
     version="1.1">
<g>
    <path d="M 10 10 L 90 10 L 90 90 L 10 90 z"
          fill="grey" stroke="black" stroke-width="3" />
</g>
</svg>
Sam
  • 317
  • 1
  • 11
  • What is the version of Org mode that you are using? I think the trouble is that 9.5 and later do not have the `org-html--svg-image` function that the the code in the link advises, so it's not going to work with such versions. The function was deleted in April 2021 with [this commit](https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d96e8975791bd3b1a5f8fdb75609d73f134dc831). – NickD May 19 '23 at 13:20
  • @NickD You're right! (as usual.) I am running Emacs 30 (bleeding edge for an unrelated matter), but I keep around v27 and v28 as a safety net. Indeed on Emacs 27.2 it works perfectly. The SVG is embedded inside the HTML file. I would delete the question, but Emacs 27.2 cannot handle my actual .org files (`htmlize-get-color-rgb-hash: Wrong number of arguments: (1 . 1), 2`). Emacs 28.2 is the worst of the three. It won't embed SVG, and it also fails on my real files (`byte-code: Symbol’s function definition is void: defvar-1`). Ideas welcome. – Sam May 19 '23 at 14:01
  • @NickD By the way, I may have misused the term "inline". Others use it either to describe seeing the SVG figure within the flow of the text in the Emacs buffer—I (thankfully) get that—or to indicate that the SVG does not require clicking on an href link in the HTML output (which is the default for me). Perhaps "embedding SVG inside an exported HTML" is a clearer term? – Sam May 19 '23 at 14:02
  • Yes, it is - you should probably change it in the question, although it was clear what you meant after reading the question (where you specifically mention "embed"). – NickD May 19 '23 at 14:11
  • 1
    For the specific failures in 27.2 and 28.2, you should probably ask different questions for each one: they seem unrelated to this one and each other. And you should specify "Emacs 30 (current upstream from git repo)" for this question. – NickD May 19 '23 at 14:14

0 Answers0