I’m often plotting things where I need the labels to have some styling. Particularly species names that need to be in italics, eg a y-label that’s something like
“Relative abundance of E. coli”
There are easy ways to set the overall font of a label or other text element, but as far as I can tell, no way to have different fonts withing the same text element.
If this feature doesn’t currently exist, I’d be interested in taking a stab at implementing it, though I imagine that the way that stuff interacts with layouts could get pretty complicated, and I haven’t spent much time in the Makie internals. In an ideal world, this would work with @md_str or the stuff from CommonMark.jl, in the same way that @L_str currently works for LaTeX, but even if it requires something a bit more hacky, that would be really useful.
It does exist but this part of the API is pretty rough/hacky. Currently you can pass a vector of font names and each glyph takes its own font. Text shaping / styling / font substitution, etc, is a verrry deep rabbit hole and so far we’ve gotten pretty far without relying on complex tools like Pango / Harfbuzz. However that also means that we don’t have any of their more advanced features like style markup, bidirectional text, etc.
text("Relative abundance of E. coli",
font = [fill("TeX Gyre Heros Makie", 22); fill("TeX Gyre Heros Makie Italic", 7)],
textsize = 30,
align = (:center, :center))
I’m happy to use the hacky solution for now in my own stuff - would there be interest in a PR that attempts to support a small number of markdown styles (I’m thinking just bold and italic really) using that hack, or does it make more sense to wait for a more complete solution (which I do not feel capable of tackling)?
LaTeXStrings.jl does not do any rendering. It is only for convenience to avoid mess with all the escaping when interpolating strings that contain LaTeX commands, as far as I understand. The rendering in Makie.jl is done via MathTexEngine.jl but it looks like it has not yet implemented different fonts. It could be a good pathway to contribute to MathTexEngine, no?
You can just use Unicode italics (assuming you have a font that covers these characters):
text("Relative abundance of 𝘌. 𝘤𝘰𝘭𝘪")
(In Julia, type by tab-completing \itE, \itc, etcetera. You could easily write a function that converts ASCII letters in a string to their Unicode italic, bold, etcetera equivalents, but the web site linked above is also pretty convenient.)
text("Relative abundance of E. coli",
font = [fill("TeX Gyre Heros Makie", 22); fill("TeX Gyre Heros Makie Italic", 7)])
ERROR: BoundsError: attempt to access 1-element UnitRange{Int64} at index [2]
Stacktrace: