Mixing LaTeX equations and Chinese in Makie plot titles

I have tried:

using GLMakie
f = Figure()
Axis(f[1,1], title=(L"中文 $\sin$"))
Axis(f[1,2], title=(L"\text{中文}\ \sin"))
f

It doesn’t work.

2 Likes

Maybe the font that’s hardcoded in MathTeXEngine doesn’t have Chinese characters? Makie has some fallback functionality for characters, but it might be that MathTeXEngine directly returns glyph indices, and you can’t get a fallback for a raw index. Worth an issue in MathTeXEngine

1 Like

MathTexEngine only knows Computer Modern, which doesn’t have the characters you want. Using Label or Annotate you can build the title from pieces, and you can specify the font you need for each piece. It’s awkward because you have to fiddle with the spacing, but here is one way:

f = Figure();
lines(f[1,1], 1:2π/1000:2π, sin.(1:2π/1000:2π))
Label(f[0,1], "中文"; padding=(1.0, 1.0, 1.0, 200.0), tellheight=false, tellwidth=false)
Label(f[0,1], L"$\sin$"; padding=(55.0, 1.0, 1.0, 200.0), tellheight=false, tellwidth=false)
f

This gets you:

(I should note that I’ve just started to dip my toe into Makie, so there are probably much better ways to do this.)

3 Likes