Using straight font with Makie and LaTeXStrings

Hi everyone,

I am currently having issues because I’m being asked to produce a figure in which all greek characters should appear in straight fonts. I have tried many ways (using \upmu instead of \mu, using unicode directly, using \textrm{}) but I none mange to produce a straight font greek letter.
Now, I’m kind of resigned not to use any LaTeXString, but the results do not look slick at all…

Anyone has an idea about how to use produce straight greek characters in a LaTeXString?

cheers !

1 Like

I thought that it might be possible to get there by setting the theme to use Noto Sans, but the renderers within the LaTeX environment aren’t that simple. Here’s a long thread, recently continued explaining the issues. MaTeXEngine

Is there a way to use Typst strings instead of LaTeX strings in the labels of Makie plots?
This could potentially solve the issue (?)

1 Like

I’d compose in typst

#show math.equation: set text(size: 28pt)
#set math.equation(numbering: none)
$
integral_0^oo e^(-x^2) thin d x = frac(sqrt(upright(pi)), 2)
$
$upright(theta), upright(beta) upright(lambda)$

and then

typst compile eq.typ eq.png

and

using CairoMakie
using FileIO

# Create a basic plot
fig = Figure(size = (900,900))
ax = Axis(fig[1, 1])

# Load and place the PNG
png_img = load("eq.png")
image!(ax, 0..2, 8..10, rotr90(png_img))

fig
1 Like

That’s cool! Do you think one could replace the text in axis title and x/ylabels by typst strings? I have tried using Typstry but I did not manage to substitute the LaTeX string by a Typst string so far…

For that, the image approach isn’t practicable. Since Makie font support is provided by FreeType.jl, you should be able to handle non-equation characters that way.

OK thanks thanks a lot for the insights. I have no idea how to manage that and all the “basic workarounds” have failed so far. I think I will opt for regular strings with unicode instead of LaTeX strings.

1 Like

That’s reasonable.

Does the functionality from this recent pr not help? Simplify changing fonts by Kolaru · Pull Request #136 · Kolaru/MathTeXEngine.jl · GitHub

I haven’t looked into it closely, though.

1 Like

this is something I wanted also but my understanding is we need to wait for some re-factoring of Makie for this to work (something realted to SpecApi IIRC @asinghvi17 )

1 Like

Thanks for the hint, I have asked the question there, let’s see!

PS: I also add the MWE here, in case anyone has another idea:

f = Figure()
Axis(f[1, 1], title=L"$\theta$ θ \mathrm{θ} \mathbf{θ} \text{\theta} \textrm{\theta}" )
display(f)

Yeah, it was using specapi within text plots in order to allow the text layouter to return any combination of plots.