CairoMakie - SVG export options

Hi all,

when saving Makie plots as svg, all text is converted to curves (i am using Arial font in case that matters).

I would like to have the text as actual text instead so that it is easier to edit later on using other programs. Is this possible? I couldn’t find an applicable setting in CairoMakie. The only options I found in the docs were for partial rasterization or overall scaling of the output.

I know that Plots.jl exports text as text as long as the font is not missing [link], and in matplotlib you can also easily change the export format [link]. So I imagine it should not be hard to do in Makie.

Help would be appreciated.

This is a known issue: Is there any way to save text as <text> in svg · Issue #2015 · MakieOrg/Makie.jl · GitHub

1 Like

Ah okay, thanks. I was not aware of this issue. Maybe we still leave this thread open for visibility?

It really seems Cairo-related, since as far as I know, both Plots.jl and matplotlib use different backends to export to svg. Matplotlib can also use Cairo, but I don’t know whether it is possible to export text as text in that case.

It’s a pity because of all the various plotting libraries I like Makie the most. But it’s not really a make or break issue for me.

How come? Maybe there’s another solution for your problem?

When Cairo exports to SVG, it converts all text to outline shapes. As you’ve seen, the drawback is that you can no longer edit the text; one benefit, though, is that the document no longer has to refer to some specific font file installed on your computer, and so can be freely moved/copied/placed into other documents without you having to worry about moving/copying the fonts as well. This is also good for fonts where the license prohibits you from copying/sharing them.

When Cairo exports to PDF and EPS, it doesn’t convert the text - the resulting file includes the shapes of every character you’ve used in the document. So you can freely move and share the document, again without worrying about missing fonts. And the quality might be better, since the outlines are generated as needed, when the document is finally rendered.

You may also be able to open the PDF file in an editor (Affinity Designer/Adobe Illustrator, for example, and possibly also some PDF editors) and you “may” even be allowed to edit the text in the converted document - particularly if the specified font is still available, in case some characters weren’t included in the original. Then you export to, say, SVG, at which point both AD/AI allow you to control whether to include the fonts in the SVG or not (an option which unfortunately Cairo doesn’t offer).

1 Like

There are some issues with exporting svgs with <text> tags.

  • mathtexengine uses glyphs which don’t have unicode symbols, so you can’t access them via unicode strings.
  • Makie’s internal representation given to the backends is already abstracted to a collection of single glyphs, so it’s not clear anymore what the coherent strings or words were (unless you do extra work to reverse those steps in the backend)
  • svg doesn’t give the option to place each glyph in a string separately, which means you can only use the default placement algorithm. So this wouldn’t work with the upcoming superscript / subscript functionality. The workaround would be to give each glyph it’s own <text> tag but I’m not sure if that’s useful for manual post editing either.
1 Like

Thanks everyone, I understand the advantages and disadvantages of using curves over text now (compatibility / file size etc.). I did not know Cairo is not capable to embed fonts, otherwise it would have mostly been a choice of preference whether to risk missing glyphs but being able to edit or to use paths and not have the comfort of text editing afterwards.

@sdanisch Its not a make or break issue for me because the text labels can be fine-tuned until its not necessary to edit the text afterwards. With Makie font options and math we are capable of doing many things as it is, Only one thing that is “difficult” to do with Makie, and which comes to my mind: math fonts. Consider this:

using CairoMakie


    f = Figure()
    ax = Label(f[1, 1], L"Testvariable = $\mathrm{\delta x * \sigma\gamma}$")

The math font can’t be changed to Arial but is fixed (even though no glyphs should be missing in this case). I know there is probably an issue open somewhere and someone is working on it, but in these cases I would manually edit the label font afterwards if I could edit it. Now I just manually rewrite the labels in inkscape in these cases.

Another (mildly) inconvenient thing with not being able to export as text is that sometimes you think of a better word choice for something or want to edit something quickly for whatever other reason. In these cases I rather do it in Inkscape than to start a julia session and recompile the figure.

And lastly, it is mildly inconvenient that if you want to move labels in an svg using inkscape / illustrator designer, each glyph is its own path of course. It would be convenient if the glyphs of one label would be grouped together in the svg export so that the label can be more easily selected and moved. But again, it is easy enough in Makie to correctly place the Label beforehand, so there is not often the need to move stuff around anyways and if so, you can still group the objects yourself.

So yeah, as I said, all is very minor inconvenience.

If someone was really motivated it would also be completely possible to add a manual SVG backend to Makie. That way, much more control could be exerted over what kind of code gets generated. Cairo’s handling is a bit of a black box to us