MakieOrg / MakieTeX.jl

TeX integration in Makie
http://makieorg.github.io/MakieTeX.jl/
MIT License
92 stars 13 forks source link

Available LaTeX fonts #65

Open RpfR2000 opened 3 days ago

RpfR2000 commented 3 days ago

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

Thanks

asinghvi17 commented 3 days ago

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 commented 2 days ago

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

RpfR2000 commented 2 days ago

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 commented 8 hours ago

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 commented 7 hours ago

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 commented 6 hours ago

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 commented 6 hours ago

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.