# Change Latex font in Makie

**URL:** https://discourse.julialang.org/t/change-latex-font-in-makie/72729
**Category:** Visualization
**Tags:** makie
**Created:** [December 7, 2021, 7:32pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729 "2021-12-07T19:32:35Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)
#### Post date: [December 7, 2021, 7:32pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/1 "2021-12-07T19:32:35Z")

</div>

Hi all,

Is there a way to change the font Makie uses when you want to typeset labels (etc…) in Latex? See here for a MWE:

```julia
using CairoMakie, LaTeXStrings

fontpath = joinpath(pwd(), "fonts", "tex-gyre", "texgyreheros-bold.otf") # path to some font

fig = Figure(font = fontpath, fontsize = 24, resolution = (1024, 768));
ax = Axis(fig[1, 1], xlabel = L"\Delta_rG \frac{kJ}{mol}", ylabel = "Concentration [mM]");
scatter!(ax, rand(10), rand(10))
fig

```

This generates the figure, shown below, with the mismatched fonts. Is it possible to change the default Latex font (on the x-axis) to match the y-axis font?

 ![test](https://global.discourse-cdn.com/julialang/original/3X/2/e/2ecf7338dbfb129fd5ac61de60b20dee741733e5.png)

---

<div class="post-metadata">

### Author: ![woclass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woclass/32/212699_2.png) [@woclass](https://discourse.julialang.org/u/woclass)
#### Post date: [December 8, 2021, 1:29am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/2 "2021-12-08T01:29:02Z")

</div>

> [@Elmo](#):
>
> Is it possible to change the default Latex font (on the x-axis) to match the y-axis font?

Unfortunately, it is not yet possible.

> Makie can render LaTeX strings from the LaTeXStrings.jl package using [MathTeXEngine.jl](https://github.com/Kolaru/MathTeXEngine.jl/).
> 
> —— [LaTeX](https://makie.juliaplots.org/stable/documentation/latex/)

> Currently the _only_ font set supported is Computer Modern.
> 
> —— [Kolaru/MathTeXEngine.jl: A latex math mode engine in pure Julia.](https://github.com/Kolaru/MathTeXEngine.jl#engine)

---

<div class="post-metadata">

### Author: ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)
#### Post date: [December 8, 2021, 12:15pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/3 "2021-12-08T12:15:51Z")

</div>

Cool, thanks for letting me know 🙂

---

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [October 15, 2022, 6:21am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/4 "2022-10-15T06:21:27Z")

</div>

Any progress here? The font mismatch is annoying.

---

<div class="post-metadata">

### Author: ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)
#### Post date: [October 15, 2022, 10:52am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/5 "2022-10-15T10:52:17Z")

</div>

Not that I am aware of… If you find something, let me know!

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [October 15, 2022, 12:50pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/6 "2022-10-15T12:50:21Z")

</div>

As far as I understand, @Kolaru took the care to pick settings for Computer Modern manually, like where to put letters next to the integral sign, etc. Also the glyph indices for the special symbols. All this would need to be redone for any other font to work well, it’s not just a matter of picking one. If any of you is motivated enough to do it, I’m sure @Kolaru would have some tips how it’s done.

---

<div class="post-metadata">

### Author: ![Kolaru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kolaru/32/4574_2.png) [@Kolaru](https://discourse.julialang.org/u/Kolaru)
#### Post date: [October 15, 2022, 7:40pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/7 "2022-10-15T19:40:30Z")

</div>

If the problem is consistency, I have just put out a new patch where you can do the following:

```julia
using CairoMakie
using MathTeXEngine

fig = Figure()
fig[1, 1] = Label(fig, "Here is a label", font=texfont())
fig[2, 1] = Label(fig, L"Here is another label $x$")

```

which result in both having the same font

 ![display](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa9c73d4060e89e6234223e9acbb631661a52222.png)

As for the more general question of supporting other fonts:

There is a bunch of fonts that would be good candidates here (because they are OpenType fonts) [Which OpenType Math fonts are available? - TeX - LaTeX Stack Exchange](https://tex.stackexchange.com/questions/425098/which-opentype-math-fonts-are-available)

The problem is that if we want to support them, someone has to go through all constructs and make sure they render correctly. I did that manually for NewComputerModern, and hardcoded a lot of the placement values.

I suspect the necessary information for all these fonts is available _somewhere_, but I don’t know where and I don’t understand the structure or magic of LaTeX packages. So I don’t plan to go further in this direction myself, for the forseeable future.

---

<div class="post-metadata">

### Author: ![baptiste](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baptiste/32/9813_2.png) [@baptiste](https://discourse.julialang.org/u/baptiste)
#### Post date: [December 7, 2022, 2:25am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/8 "2022-12-07T02:25:22Z")

</div>

Just mentioning in passing that the same problem has been (is being) tackled by Mathjax, so there’s probably useful information to obtain from that side: [MathJax Font Support — MathJax 3.2 documentation](https://docs.mathjax.org/en/latest/output/fonts.html)

In particular, since the glyph positioning is handled completely independently of TeX, they may have more readable information that could be reused here. (I briefly interacted with one of the devs, for a project replacing glyphs with custom SVG paths, and it seems most of the machinery is already in place and will become much easier in v3)

---

<div class="post-metadata">

### Author: ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)
#### Post date: [August 10, 2023, 9:19am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/9 "2023-08-10T09:19:39Z")

</div>

> [@Kolaru](#):
>
> `texfont`

Is there a way to use bold latex fonts?

---

<div class="post-metadata">

### Author: ![Kolaru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kolaru/32/4574_2.png) [@Kolaru](https://discourse.julialang.org/u/Kolaru)
#### Post date: [August 11, 2023, 10:42am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/10 "2023-08-11T10:42:29Z")

</div>

`\mathbf` is supported. For example

```julia
julia> fig = Figure()

julia> Label(fig[1, 1], L"normal\mathbf{bold}") ; fig

```

outputs  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/7/67e3ec9664b7bff97c57216ddeda958e3410240f.png)

---

<div class="post-metadata">

### Author: ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)
#### Post date: [August 14, 2023, 6:03pm UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/11 "2023-08-14T18:03:28Z")

</div>

Thanks but \textbf{bold} does not work!

---

<div class="post-metadata">

### Author: ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)
#### Post date: [August 18, 2023, 7:43am UTC](https://discourse.julialang.org/t/change-latex-font-in-makie/72729/12 "2023-08-18T07:43:32Z")

</div>

Since I had the same problem a few days ago, I thought I’d share the theme snippet I ended up with, to make all non-latex text elements look similar to the latex ones:

```julia
using MathTeXEngine # required for texfont

textheme = Theme(fonts=(; regular=texfont(:text),
                        bold=texfont(:bold),
                        italic=texfont(:italic),
                        bold_italic=texfont(:bolditalic)))

with_theme(textheme) do
    fig = Figure(resolution=(400,300))
    ax = Axis(fig[1,1],
              title="foo",
              xlabel="whatever",
              ylabel=L"$\mathcal{H_\infty}$ Norm",
              xticks=(1:10, vcat(L"\sum i", repr.(2:10))))
    scatter!(ax, rand(10))
    fig
end

```

![grafik](https://global.discourse-cdn.com/julialang/original/3X/6/d/6ddb84c3547665d25e6296841f6f8c929cb66573.png)
