Inserting SVG images using Scrivener 3?

I’d like to use SVG images in Scrivener 3 on Mac.

I can drag an SVG image into a folder I created. Then I try to insert the image into a document using Insert>Image to Linked File… However, the SVG document doesn’t appear. My other PNGs do, however, appear. I can insert them without a problem, but not the SVG images.

I also tried using $img notation like this:


Where “circle” is the name of my SVG file:

<svg viewBox="0 0 100 100" xmlns=""> <circle cx="50" cy="50" r="50"/> </svg>

However, after compilation to either PDF or EPUB3, I see no SVG image in the output.

I can use either the Insert menu or the $img notation to insert a PNG image.

The thread I linked to above, links to this announcement that SVG images are supported in Scrivener using Multimarkdown:

Is there any way to insert SVGs into documents in the same way that PNGs get inserted?

I think only multimarkdown/pandoc supports the use of SVG files. I think it would be great if Scrivener had better support of SVG, although I think it will not be supported in the editor as the RTF engine Scrivener uses from Apple doesn’t seem to support SVG. But as you say you could use a link and then an output format like PDF should support it so perhaps this could be a wishlist post?

When you say “multimarkdown/pandoc supports the use of SVG files,” what do you mean? I was trying to incorporate SVG files into my ebook, but as the original poster noted, the $img tag does not work for SVG files (it fails silently; it would be great if at least there was an error shown…)

When you compile to MMD/Pandoc using MMD/Pandoc image link figure placement (§21.4.1 of the user manual), SVG files are exported, and Pandoc at least can embed SVGs for several of its output formats (EPub3 / HTML / possibly LaTeX and even DOCX now!)

Markdown figures are specified like this in the editor (alphachannel is a link to the SVG in the binder):

A paragraph of text.

![Here is mytest of the SVG export here.](alphachannel)

Another paragraph.


Showing the compiled SVG embedded in an EPub3:

The underlying RTF editor Scrivener uses sadly cannot view SVG files so you cannot embed or image-binder-link them. But I suppose Keith should be able to easily change the <$img:xxx> placeholder to work like the Markdown does when exporting to MMD/Pandoc, but the question is why bother if works…

Yes, unfortunately images inserted using <$img:…> must be of a type that Scrivener can insert into the editor, because of the way compilation works. While Apple’s text system does not support SVG files, <$img:…> cannot support them either.

All the best,

@Nontroppo Thanks, your description was very helpful. My project is still in the early stage so I can convert everything to markdown if necessary.

I did this (compiled as Multimarkdown → Web page) and it worked as described… but is there a way to use Markdown with the ePub3 or KF8 compile options? I noticed that I could get unordered lists and paragraphs without doing anything special, but when I compile to KF8 or ePub3, my markdown syntax images do not appear.

You’re going to run into the same exactly problem of being unable to embed an SVG image, by using those formats. Basically with the exception of the Markdown-based stuff, every single compile format in the list starts out as RTF in the compile phase. Linked images are fully embedded and converted to raster formats it understands, etc. After that the compiler moves on to turning that into HTML or whatever it needs.

I’d try the Pandoc->ePub compile type at the very bottom of the menu. It’s not quite as full-featured as Scrivener’s, but it’s a native approach that doesn’t involve conversion to RTF in the intermediate phases (well, the source material is, but that’s somewhat beside the point when the compiler is for the most party stripping the raw text out of it). To make formatting changes, you’ll need to know a thing or two about CSS. The way I’d approach is by enabling the Save source files in a folder with exported file compile option, use Firefox developer tools or what have you to craft the design, and then copy and paste the result into a “Custom CSS” field within the Pandoc Options compile format pane.

There is no need to convert anything apart from the figure blocks really; you can use Scrivener 3 styles to keep using rich text in the editor and convert it to the correct markdown on compile.

There are several approaches. As AmberV mentions, you need to be using the Markdown (MMD/Pandoc) compile format routes. Once Pandoc is installed, you can use the Pandoc direct compile options. You can also use the generic Multimarkdown compile format (it just outputs MMD or Pandoc compatible output), and Scrivener 3’s post-processing panel in the compiler can automatically run Pandoc for you with the correct settings to generate an EPub3 / KF8 etc.

Thank you AmberV and Nontroppo.

After installing PanDoc and evaluating this further, I think I found a better approach (for myself at least; I am writing this here in case anyone else struggles with a similar issue later).

With SVG, the images have to be inserted using Markdown, but in the Markdown markup, the image is linked by referencing the file. This means that you cannot insert an image via the prefix/suffix options on the styles pane of the Compile menu because there’s no way to put a file link in there. This was my original goal because I’m using these images for speech bubbles, which are managed by a style.

So, here is what I did:

  1. Use Photoshop to batch process my folder of SVG images (since there are about 300) and convert them to PNG. Keep all file names the same (so that abc.svg becomes abc.png).
  2. Use the PNG images in Scrivener; this allows the <$img:abc> tags to be used.
  3. Compile to ePub.
  4. Open the ePub in Sigil, delete all PNG images from the image folder, add all SVG images, and then do a global find & replace for “.png” to “.svg” and save. Since the file names are all the same, it works.

This assumes that you have no PNG images that are not also SVG images, which is true in my case.

That’ll do as well!

For future reference, you can insert an image via Markdown using the technique you are using (it’s all text-based after all). Instead of typing <$img:abc> into the field, you’d type . The only thing you’d need to do special to make that work automatically (without dumping the files into the ePub with Sigil, that is) is ensure abc.svg is in the body text somewhere, so that compile exports the file. Having a thumbnail sheet of all resources used in that fashion that can be deleted in Sigil after compiling would be an approach.

A Markdown image reference is almost more like a symbolic link, in the sense that it functions whether or not anything is on the other side of the link. There is nothing about the image in the tag—just a plain-text reference to the resource. MMD and Pandoc both aren’t even going to care if the image is there, they will convert the syntax to <img href=“abc.svg”…>, and then whether the image is actuallly there or not is a problem for the HTML parser (or the ePub validator in this case).

Cool use of styles by the way.

Thanks AmberV, using markdown allows me to set the alt tag and avoid opening up Photoshop just to convert the SVG when I decide to add some new ones.