Unicode support for other fonts in Plots

We can use unicode symbols in plots, like:

julia> plot(rand(10),label="π → 10⁻¹ ×")

image

However, if we change the fonts, most commonly that not this errors:

julia> plot(rand(10),label="π → 10⁻¹ ×",fontfamily="Computer Modern")
GKS: glyph missing from current font: 8315
GKS: glyph missing from current font: 185
GKS: glyph missing from current font: 8315
GKS: glyph missing from current font: 185
GKS: glyph missing from current font: 8315
GKS: glyph missing from current font: 185


image

How/where is this supposed to be parsed and supported for different fonts? I am particularly interested in Computer Modern, as it would make plotting consistent plots using Latex even more practical.

That’s what happens if you use a Unicode character that is not defined in the font you specify… To get these particular characters in a Computer Modern-like font you can use the CMU Serif from the Computer Modern Unicode fonts. Another option is the Latin Modern font.

Note that these fonts still miss a lot of Unicode characters… Have a look at https://mono-math.netlify.app/ which I just updated to include CMU Typewriter Text and Latin Modern Mono (I think they have the same coverage as the proportional serif variants which you probably want).

1 Like

I am having a hard time figuring out if it is possible to use other fonts in Plots (GR) apart from those in this list: Fonts — GR Framework 0.57.3 documentation

Is it?

I just tried with the second mono-math example (∀x ∈ ℝ⁺, ∃n ∈ ℕ : n ≤ x < n+1) which very few fonts can render properly.

Running

plot(1:3, label="∀x ∈ ℝ⁺, ∃n ∈ ℕ : n ≤ x < n+1", fontfamily="JuliaMono")

gives the expected output so yes, it’s possible to use other fonts. However it seems GR gets into a corrupted state if I make another plot call with a different fontfamily: I get a mix of two fonts, and later using again fontfamily=JuliaMono doesn’t work: I still get a mix of fonts.

Are you sure it rendered with JuliaMono ? Here I get the correct characters:
image

but I think that is just the default font.

Here I copied the same thing into inkscape and used JuliaMono on the upper text:

image

You’re right! It’s not JuliaMono. It’s very clear when using the greek letters α β γ δ ϵ ε ζ η θ which have a distinctive design in JuliaMono. I don’t know then which fallback font is used, and why the fallback is not used for Computer Modern (maybe Computer Modern actually defines these glyphs using the “undefined” symbol? That would be a bug I think).

I think it falls back to the default font, Helvetica or something of the sort.