LaTeX friendly vector graphics with Makie

Is there a way to produce vector graphics figures with Makie such that they can be included in a LaTeX document and have LaTeX typeset all text in the figure? My first idea was to use CairoMakie to produce a figure.svg file and then use

inkscape -D --export-latex --export-filename=figure.pdf figure.svg

to create a figure.pdf and figure.pdf_tex file that can be included and where figure.pdf_tex contains all text in the figure. But upon closer inspection of the SVG files it turns out that the text in it is actually not text anymore, but just vector graphics outlines of the letters.

image
As you can see, the fonts in the figure don’t match the document font and would stay unchanged when changin the document font,

Similarly, if I use CairoMakie to produce a PDF figure and

inkscape -D --export-latex --export-filename=figure.pdf figure.svg

to put the text into a separate .pdf_tex file the fonts match now, but the spacing is completely off:

image

And \includegraphicing the PDF produced by CairoMakie directly yields

image

My end goal is to be able to include my Makie figures in LaTeX documents and have the fonts in the figure and the main document automatically match and being able to use fonts other than computer modern for LaTeX elements in the figure (which seems to be the only font support by MathTexEngine).

In a similar vein: Are there any plany to write a PGFMakie backend for Makie? In matplotlib / pyplot I can do fig.savefig("filename.pgf") to produce a file that I can directly \input into my LaTeX document and the lack of such an option is the only thing still preventing me from switching to Makie for my plotting needs.

It won’t work to transform the vector output of CairoMakie as you noticed as by then any notion of coherent pieces of text is gone. It’s all about single glyphs then and if you replace those with different fonts it will never match up.

Layout sizing is slightly different though with fonts of different metrics so your end result will never be quite as good if you change fonts after the fact. The difference could of course be so small that you might not care, depending on the situation.

A pgf backend would have to keep the blocks of text intact and write them out as such, however nobody has attempted to write such a backend, yet. I personally would just save the figures directly with the font you want to use in your paper. And mathtexengine can in principle work with other fonts however I’m not sure if there would be a lot of manual work involved to get specific spacings correct for a new font set. Maybe @Kolaru could say something about that.

As far as I understand a LaTeX font is actually a family of fonts, together with some mapping of math characters to specific glyph in specific font. Even with NewComputerModern – which is unicode and to which I switched – the italic math greek charcaters are at some arbitrary glyph indices in the math font instead of being the greek characters of the italics font, and I had to enter that information manually.

MathTexEngine can already in principle work with multiple fonts, but I did the glyph mapping and positioning manually. By chance, those settings may work for multiple font, but there is no guarantee.

The key problem here is that I don’t understand whatever it is that LaTeX is doing to correctly render its equations, and we would need somebody who does to properly allow multiple fonts. Then it would be possible – maybe – to grab all the needed information from their respective LaTeX font packages, and automatize it. At present, I can’t do it.

2 Likes

Hi, I am facing the same problem. Has a solution been found yet??