Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts of text in a mixed-mode L-string differs from a normal text #1560

Closed
ShuhuaGao opened this issue Jan 9, 2022 · 9 comments
Closed

Fonts of text in a mixed-mode L-string differs from a normal text #1560

ShuhuaGao opened this issue Jan 9, 2022 · 9 comments
Labels
Makie Backend independent issues (Makie core) question TODO: move to Discussions text

Comments

@ShuhuaGao
Copy link

using CairoMakie
using LaTeXStrings

fig = Figure(resolution=(600, 400))
ax = Axis(fig[1, 1], xlabel=L"Time $t$", xlabelsize=22, ylabel="Price", ylabelsize=22)
lines!(ax, 1:24, rand(24))
fig

I expect that the font of "Time" is the same as "Price". However, it does not.
pt

What should I do to make Makie render them with the same font (better by default)?

@jonas-schulze
Copy link
Contributor

Regular strings like "Price" and all the tick labels are rendered using the font configured in Makie, while LaTeXStrings like L"Time $t$" are rendered by MathTeXEngine.jl using (New) Computer Modern.

I'm currently working on getting a different font working in MathTeXEngine, but with no success so far. The documentation of MathTeXEngine says

Currently the only font set supported is Computer Modern.

but there clearly is some modularity prepared to support other fonts. Here is what I did so far:

utopia_dir = "/usr/local/texlive/2018/texmf-dist/fonts/type1/adobe/utopia"

utopia = Dict(
	:regular => joinpath(utopia_dir, "putr8a.pfb"),
	:italic => joinpath(utopia_dir, "putri8a.pfb"),
	:bold => joinpath(utopia_dir, "putb8a.pfb"),
	:bolditalic => joinpath(utopia_dir, "putbi8a.pfb"),
	:math => joinpath(utopia_dir, "putri8a.pfb"), # italic
)

utopia_ff = Makie.MathTeXEngine.FontFamily(utopia)

Makie.MathTeXEngine.generate_tex_elements("a+b", utopia_ff)

Currently, the values of the utopia dictionary must be strings to support the current get_font and load_font. A proper solution would require some changes to MathTeXEngine as well, I suppose, e.g. these font values should be allowed to be Union{String,FTFont} as returned by e.g. FreeTypeAbstraction.findfont. I suspect that Makie uses something similar. However, I can't find how/where the fonts are passed to MathTeXEngine.

Is this something you have on the radar? If not, could you give me some pointers, please? Thanks in advance! I won't be able to work on this within the next month, though. 🙂

CC @Kolaru

@jonas-schulze
Copy link
Contributor

@SimonDanisch, did you have time to think about my comment above? If not, no rush. I'm just pinging you because I thought you are online, as you responded so quickly in #1296.

I don't know how LaTeX deals with superscripts exactly, but at least pdflatex doesn't use superscript glyphs (the font I use only has glyphs for 1, 2, 3; cf #1296 (comment)). If MathTeXEngine does something similar, which I suppose as e.g. L"K^{1234567890}_{1234567890}" works fine (except the font being used), fixing this issue would be a work-around for #1296.

@SimonDanisch
Copy link
Member

That's more of a question for @jkrumbiegel and @Kolaru

@Kolaru
Copy link
Contributor

Kolaru commented Mar 10, 2022

The way consistency of fonts is currently supported is only the other way around: you can get the fonts used by MathTeXEngine using get_font or get_fontpath and ask Makie to use them (see Kolaru/MathTeXEngine.jl#27).

The other way is not yet implemented, but now has its very own issue: Kolaru/MathTeXEngine.jl#55

@jonas-schulze You seem to be pretty close. The main problem you may face is that the math font is (for Computer Modern) a special font with special encoding, that requires some additional data (namely how to fetch the special character).

If you get back to it before I can have a closer look (I will try to go through MathTeXEngine issues in the coming few weeks), please open an issue on MathTeXEngine.

@thudjx
Copy link

thudjx commented Mar 28, 2022

@Kolaru I tried get_font(fontstyle), but it only works for fontstyle=:regular, :bold, :italic and :bolditalic. I mean I find there are two more font files in the MathTexEngine directory, but I don't know what the corresponding fontstyles are. The docstring doesn't give any useful information. Do you have any idea?

@greimel
Copy link
Contributor

greimel commented Apr 7, 2022

When installed, you can use fig = Figure(font = "CMU"), then you will have a consistent font (Computer Modern) everywhere.

image

@jonas-schulze
Copy link
Contributor

That is correct. But it doesn't help in situations where a user e.g. prefers the default font of Makie, or wants to have the figure's font (or all its fonts) match the non-CMU font used in the document the figure should be embedded in.

@greimel
Copy link
Contributor

greimel commented Apr 7, 2022

True, but it might be enough for OP.

@Kolaru
Copy link
Contributor

Kolaru commented Jul 24, 2024

I have added a simple support for TeXGyreHeros (Makie default) in MathTeXEngine, and a hack to use it: just put the command \fontfamily{TeXGyreHeros} somewhere in the LaTeXString (see Kolaru/MathTeXEngine.jl#123).

Now this is still a hack, so maybe on the Makie side we would like to have a different interface to pass any FontFamily down to MathTeXEngine.

(there is of course also a lot of work to get any font to get a proper layout, including TeXGyreHeros, but that's a different story)

@ffreyer ffreyer added question TODO: move to Discussions Makie Backend independent issues (Makie core) text labels Aug 22, 2024
@MakieOrg MakieOrg locked and limited conversation to collaborators Aug 22, 2024
@ffreyer ffreyer converted this issue into discussion #4208 Aug 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Makie Backend independent issues (Makie core) question TODO: move to Discussions text
Projects
None yet
Development

No branches or pull requests

7 participants