Skip to content
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

Available LaTeX fonts #65

Open
RpfR2000 opened this issue Nov 19, 2024 · 9 comments
Open

Available LaTeX fonts #65

RpfR2000 opened this issue Nov 19, 2024 · 9 comments

Comments

@RpfR2000
Copy link

Is there any way to use other fonts offered in LaTeX -- in particular, computer modern sans serif?

Thanks

@asinghvi17
Copy link
Member

asinghvi17 commented Nov 19, 2024

Sure, you can load them the same way you would in LaTeX. But that needs a full TeXDocument.

Ideally this would be automated from the fonts in the theme, but I don't have time to figure that out currently...

@RpfR2000
Copy link
Author

I see. This is a great addition to Makie, thanks!

@RpfR2000 RpfR2000 reopened this Nov 20, 2024
@RpfR2000
Copy link
Author

Sorry -- to be clear, if I loaded in the font via a TeXDocument, would it apply to all fonts in the plot (e.g., for ticks, axis labels, titles, etc.)?

@RpfR2000
Copy link
Author

This attempt does not seem to do anything to the fonts. Clearly I need to pass the tex doc somewhere but I don't know where.

using Makie, MakieTeX
using CairoMakie
fig = Figure()
doc = raw"""
\renewcommand{\familydefault}{\sfdefault}
"""
tex = CachedTEX(MakieTeX.texdoc(doc))
ax1 = Axis(
    fig[1, 1], ytickformat = x -> latexstring.(string.(x)), xtickformat = x -> latexstring.(string.(x)) 
)
heatmap!(ax1, Makie.peaks())
fig

@asinghvi17
Copy link
Member

You aren't using tex anywhere though? The formatting functions would have to return a complete TeXDocument. Here's an example:

function num2tex(num)
    return TeXDocument("""
\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
\renewcommand{\familydefault}{\sfdefault}
$$\int x = dx$$
\end{document}
""")
end
fig = Figure()
ax1 = Axis(
    fig[1, 1], ytickformat = x -> num2tex.(x), xtickformat = x -> num2tex.(x)
)
heatmap!(ax1, Makie.peaks())
fig

It's been a while since I wrote TeX so that document might be wrong. But this is what you would do.

@RpfR2000
Copy link
Author

I see, thanks. This attempt gives an error that I am having difficulty parsing. The TeX document compiles just fine on its own.

using Makie, MakieTeX 
using CairoMakie
function num2tex(num)
    return TeXDocument(raw"""
\documentclass{standalone}
\usepackage{amsmath}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
Test
\end{document}
""")
end
fig = Figure()
ax1 = Axis(
    fig[1, 1], ytickformat = x -> num2tex.(x), xtickformat = x -> num2tex.(x)
)
heatmap!(ax1, Makie.peaks())
fig
ERROR: LoadError: MethodError: no method matching _get_glyphcollection_and_linesegments(::TEXDocument, ::Int64, ::Float32, ::FreeTypeAbstraction.FTFont, ::Att
ributes, ::Tuple{…}, ::Quaternion{…}, ::MakieCore.Automatic, ::Float64, ::ColorTypes.RGBA{…}, ::ColorTypes.RGBA{…}, ::Int64, ::Int64, ::Vec{…})
                                                                              
Closest candidates are:                                                       
  _get_glyphcollection_and_linesegments(::Makie.RichText, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
   @ Makie ~/.julia/packages/Makie/8h0bl/src/basic_recipes/text.jl:313        
  _get_glyphcollection_and_linesegments(::LaTeXString, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
   @ Makie ~/.julia/packages/Makie/8h0bl/src/basic_recipes/text.jl:112        
  _get_glyphcollection_and_linesegments(::AbstractString, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
   @ Makie ~/.julia/packages/Makie/8h0bl/src/basic_recipes/text.jl:107  

@asinghvi17
Copy link
Member

Ooh yeah I missed that you are using it like that. That doesn't work in recent versions of Makie unfortunately, because of changes to the way text is laid out. I want to change that at some point but it's a bit tough.

If you need that specific font and have a file for it (.ttf, .otf, or whatever) then you could use Makie's native font capabilities to point to it (https://docs.makie.org/dev/explanations/fonts) and reserve MakieTeX for labels and other, larger text that you can create independent label blocks for.

@RpfR2000
Copy link
Author

Okay, thanks. Using a .ttf file works fine for the most part. Perhaps it's worth keeping this issue open though?

@asinghvi17
Copy link
Member

Yes, at some point I want to unify these two approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants