# Latex in GLMakie, no spaces

**URL:** <https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192>\
**Category:** General Usage\
**Tags:** latex, makie, glmakie\
**Created:** [March 5, 2024, 12:47pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192 "2024-03-05T12:47:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 5, 2024, 12:47pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/1 "2024-03-05T12:47:54Z")

</div>

When trying to use Latex with GLMakie in this code:

```julia
using GLMakie

f = Figure(backgroundcolor = "#f5f0f5")
ax = Axis(f[1, 1], 
    title = L"A Makie Axis",
    xlabel = L"The x label",
    ylabel = L"The y label \omega"
)
display(f)

```

This is the output:

 ![Screenshot from 2024-03-05 13-45-05](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa271fc2e71e23218385a3f890d9e81cb672157b.png)

There is no space. I added a scientific symbol and it’s useful to note that it doesn’t need $$ to be displayed. This means all the text is considered as an equation.

Is there a way to set the text as default and use $$ to delimit symbols?

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [March 5, 2024, 12:50pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/2 "2024-03-05T12:50:43Z")

</div>

A `L".."` string behaves much like an `$...$` expression in LaTeX, e.g. it displays inline math for which spaces are ignored.  
For ordinary text I would just use a normal string.  
Or do what @p_f suggsted below.

---

<div class="post-metadata">

**Author:** ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)\
**Post date:** [March 5, 2024, 12:51pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/3 "2024-03-05T12:51:16Z")

</div>

Latex is in math mode here, you can use \text{} for latex text

E.g. L"\text{normal text } x^2"

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 5, 2024, 12:56pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/4 "2024-03-05T12:56:57Z")

</div>

What if I need to use ordinary text alongside equation, just as in the first example of documentation: [LaTeX · Makie](https://docs.makie.org/stable/explanations/latex/) which doesn’t work as intended with GLMakie (didn’t try with CairoMakie)

If I use \text{} like:

```julia
ax = Axis(f[1, 1], 
    title = L"\text{A Makie Axis}",
    xlabel = L"\text{The x label}",
    ylabel = L"\text{The y label} \omega"
)

```

It throws a huge error:

```julia
ERROR: LoadError: TeXParseError: unexpected error while parsing
at position 7 (string index 7)
\text{The x label}
      ^
with stack (length 1):
[1] TeXExpr :expr

Stacktrace:
  [1] texparse(data::String; showdebug::Bool)
    @ MathTeXEngine ~/.julia/packages/MathTeXEngine/b206G/src/parser/parser.jl:232
  [2] texparse
    @ ~/.julia/packages/MathTeXEngine/b206G/src/parser/parser.jl:221 [inlined]
  [3] generate_tex_elements(str::String, fontset::MathTeXEngine.FontSet)
    @ MathTeXEngine ~/.julia/packages/MathTeXEngine/b206G/src/engine/layout.jl:256
  [4] generate_tex_elements
    @ ~/.julia/packages/MathTeXEngine/b206G/src/engine/layout.jl:256 [inlined]
  [5] texelems_and_glyph_collection(str::LaTeXStrings.LaTeXString, fontscale_px::Float32, halign::Symbol, valign::Symbol, rotation::Quaternionf0, color::Symbol, strokecolor::Tuple{…}, strokewidth::Int64)
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:191
  [6] (::Makie.var"#983#989")(latexstring::LaTeXStrings.LaTeXString, ts::Float32, al::Tuple{…}, rot::Float32, mo::StaticArraysCore.SMatrix{…}, color::Symbol, scolor::Tuple{…}, swidth::Int64, ::Point{…})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:117
  [7] lift(::Function, ::Observable{LaTeXStrings.LaTeXString}, ::Observable{Any}, ::Vararg{Observable{Any}}; kw::@Kwargs{})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interaction/nodes.jl:13
  [8] lift(::Function, ::Observable{LaTeXStrings.LaTeXString}, ::Observable{Any}, ::Observable{Any}, ::Vararg{Observable{…}})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interaction/nodes.jl:9
  [9] plot!(plot::MakieCore.Text{Tuple{LaTeXStrings.LaTeXString}})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:95
 [10] plot!(scene::Scene, P::Type{…}, attributes::Attributes, input::Tuple{…}, args::Observable{…})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:428
 [11] plot!(scene::Scene, P::Type{MakieCore.Text}, attributes::Attributes, args::Observable{Any}; kw_attributes::@Kwargs{})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:339
 [12] plot!
    @ ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:307 [inlined]
 [13] #plot!#157
    @ ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:291 [inlined]
 [14] text!(::Scene, ::Vararg{…}; attributes::@Kwargs{…})
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:35
 [15] Makie.MakieLayout.LineAxis(parent::Scene; kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/lineaxis.jl:174
 [16] layoutable(::Type{…}, fig_or_scene::Figure; bbox::Nothing, kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables/axis.jl:211
 [17] layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables/axis.jl:8 [inlined]
 [18] #_layoutable#11
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:69 [inlined]
 [19] _layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:68 [inlined]
 [20] _layoutable(::Type{…}, ::GridPosition; kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:64
 [21] _layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:57 [inlined]
 [22] #_#9
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:49 [inlined]
 [23] top-level scope
    @ ~/Desktop/Programmi/MODULO_05/executable_and_libraries/bin/aaa.jl:27
 [24] include(fname::String)
    @ Base.MainInclude ./client.jl:489
 [25] top-level scope
    @ REPL[2]:1
in expression starting at /home/matteobacci/Desktop/Programmi/MODULO_05/executable_and_libraries/bin/aaa.jl:27

caused by: TeXParseError: unsupported command \text
at position 7 (string index 7)
\text{The x label}
      ^
with stack (length 1):
[1] TeXExpr :expr

Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/MathTeXEngine/b206G/src/parser/parser.jl:212 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Automa/Aq8Mq/src/codegen.jl:142 [inlined]
  [3] texparse(data::String; showdebug::Bool)
    @ MathTeXEngine ~/.julia/packages/MathTeXEngine/b206G/src/parser/parser.jl:230
  [4] texparse
    @ ~/.julia/packages/MathTeXEngine/b206G/src/parser/parser.jl:221 [inlined]
  [5] generate_tex_elements(str::String, fontset::MathTeXEngine.FontSet)
    @ MathTeXEngine ~/.julia/packages/MathTeXEngine/b206G/src/engine/layout.jl:256
  [6] generate_tex_elements
    @ ~/.julia/packages/MathTeXEngine/b206G/src/engine/layout.jl:256 [inlined]
  [7] texelems_and_glyph_collection(str::LaTeXStrings.LaTeXString, fontscale_px::Float32, halign::Symbol, valign::Symbol, rotation::Quaternionf0, color::Symbol, strokecolor::Tuple{…}, strokewidth::Int64)
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:191
  [8] (::Makie.var"#983#989")(latexstring::LaTeXStrings.LaTeXString, ts::Float32, al::Tuple{…}, rot::Float32, mo::StaticArraysCore.SMatrix{…}, color::Symbol, scolor::Tuple{…}, swidth::Int64, ::Point{…})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:117
  [9] lift(::Function, ::Observable{LaTeXStrings.LaTeXString}, ::Observable{Any}, ::Vararg{Observable{Any}}; kw::@Kwargs{})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interaction/nodes.jl:13
 [10] lift(::Function, ::Observable{LaTeXStrings.LaTeXString}, ::Observable{Any}, ::Observable{Any}, ::Vararg{Observable{…}})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interaction/nodes.jl:9
 [11] plot!(plot::MakieCore.Text{Tuple{LaTeXStrings.LaTeXString}})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/basic_recipes/text.jl:95
 [12] plot!(scene::Scene, P::Type{…}, attributes::Attributes, input::Tuple{…}, args::Observable{…})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:428
 [13] plot!(scene::Scene, P::Type{MakieCore.Text}, attributes::Attributes, args::Observable{Any}; kw_attributes::@Kwargs{})
    @ Makie ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:339
 [14] plot!
    @ ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:307 [inlined]
 [15] #plot!#157
    @ ~/.julia/packages/Makie/xbI6d/src/interfaces.jl:291 [inlined]
 [16] text!(::Scene, ::Vararg{…}; attributes::@Kwargs{…})
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:35
 [17] Makie.MakieLayout.LineAxis(parent::Scene; kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/lineaxis.jl:174
 [18] layoutable(::Type{…}, fig_or_scene::Figure; bbox::Nothing, kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables/axis.jl:211
 [19] layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables/axis.jl:8 [inlined]
 [20] #_layoutable#11
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:69 [inlined]
 [21] _layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:68 [inlined]
 [22] _layoutable(::Type{…}, ::GridPosition; kwargs::@Kwargs{…})
    @ Makie.MakieLayout ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:64
 [23] _layoutable
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:57 [inlined]
 [24] #_#9
    @ ~/.julia/packages/Makie/xbI6d/src/makielayout/layoutables.jl:49 [inlined]
 [25] top-level scope
    @ ~/Desktop/Programmi/MODULO_05/executable_and_libraries/bin/aaa.jl:27
 [26] include(fname::String)
    @ Base.MainInclude ./client.jl:489
 [27] top-level scope
    @ REPL[2]:1
Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [March 5, 2024, 12:58pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/5 "2024-03-05T12:58:27Z")

</div>

Which version of `GLMakie` are you using?  
It works for me on `v0.9.9`.

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 5, 2024, 1:12pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/6 "2024-03-05T13:12:15Z")

</div>

I assumed that after installing it the version was the latest, but it seemed i was wrong here.

Updating solved the issue

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [March 5, 2024, 5:08pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/7 "2024-03-05T17:08:24Z")

</div>

I think you can also escape the space with a backslash: `L"The\ x\ label"`

---

<div class="post-metadata">

**Author:** ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)\
**Post date:** [March 5, 2024, 6:26pm UTC](https://discourse.julialang.org/t/latex-in-glmakie-no-spaces/111192/8 "2024-03-05T18:26:18Z")

</div>

> Is there a way to set the text as default and use $$ to delimit symbols?

Apologies didn’t actually read this bit before. Just had a look at latexstrings.jl and if you include $$, it will interpret the rest as text, so

```julia
f = Figure()
ax = Axis(f[1,1],xlabel=L"Text $a = b$")

```

works. And if you just want text you can do `L"Text$$"`. Not sure why I’ve been using \text all this time…
