# Plots and LaTeXStrings not recognizing some LaTeX commands

**URL:** <https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922>\
**Category:** General Usage\
**Tags:** package, plotting\
**Created:** [July 11, 2024, 5:49pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922 "2024-07-11T17:49:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brombo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brombo/32/47867_2.png) [@brombo](https://discourse.julialang.org/u/brombo)\
**Post date:** [July 11, 2024, 5:49pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922/1 "2024-07-11T17:49:04Z")

</div>

I am using Julia with Plots and LaTeXStrings to plot data. Here is an example

 ![LX521.4_Mg](https://global.discourse-cdn.com/julialang/original/3X/7/c/7cc66008f7afa7a26af10866cbaaa4689a9a3eb3.jpeg)

The problem is that when I label the y-axis it works if the label string is -

`$| H |$ dB`

which is shown in the plot but if I use the string (variable height “|”)

`$\left | H \right |$ dB`

The “|” does not appear in the label (no error generated). Am I doing something wrong or is this a bug in the plotting package or LaTeXStrings.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 11, 2024, 6:31pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922/2 "2024-07-11T18:31:24Z")

</div>

> [@brombo](#):
>
> Am I doing something wrong or is this a bug in the plotting package or LaTeXStrings.

See [FAQ: Not a LaTeX renderer](https://github.com/JuliaStrings/LaTeXStrings.jl?tab=readme-ov-file#faq-not-a-latex-renderer). LaTeXStrings is not responsible for doing the LaTeX math rendering — that is done by [MathJax](https://www.mathjax.org/), [MathTeXEngine.jl](https://github.com/Kolaru/MathTeXEngine.jl), or [other renderers](https://matplotlib.org/2.0.2/users/mathtext.html) called by the plotting package or other environment. Generally these are not full LaTeX engines and only handle a subset of the math syntax.

`L"$\left | H \right | dB$"` works fine for me with Matplotlib’s LaTeX renderer, via PyPlot.jl or PythonPlot.jl. So if you do `Plots.set_default_backend!(:pythonplot)` then presumably it will work. What Plots.jl backend are you using?

---

<div class="post-metadata">

**Author:** ![brombo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brombo/32/47867_2.png) [@brombo](https://discourse.julialang.org/u/brombo)\
**Post date:** [July 11, 2024, 7:54pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922/3 "2024-07-11T19:54:04Z")

</div>

Whatever the default renderer for Plots.jl is what it is (I don’t specify a renderer). In my code I just do this -

using LaTeXStrings  
using Plots

and

p = plot(xscale=:log10, minorgrid=true)  
xlims!(p,PV.vars[“xmin”], PV.vars[“xmax”])  
ylims!(p,PV.vars[“ymin”], PV.vars[“ymax”])  
title!(p,convert\_text(PV.vars[“title”]))  
xlabel!(p,latexstring(PV.vars[“xlab”]))  
ylabel!(p,latexstring(PV.vars[“ylab”]))

```
for k in keys(PV.crvs)
    plot!(p,get_col(PV,k,"freq"),get_col(PV,k,"amp"),label=convert_text(PV.crvs[k].legend_name),lw=2)
end
file_name_pdf = PV.vars["filename"]*".pdf"
savefig(p,file_name_pdf)
run(`open $file_name_pdf`)
file_name_jpg = PV.vars["filename"]*".jpg"
run(`convert -density 300 -quality 100 $file_name_pdf $file_name_jpg`)

```

I will take your advice and change the backend. I wish that `Plots.jl` could use Asymptote for a backend -

[Asymptote](https://asymptote.sourceforge.io/)

There is supposed to be a Julia frontend for Asymptote but I was unable to install it and it did not expose much of Asymptote. I think the Plots API is well designed.

[Asymptote for Julia](https://github.com/sswatson/AsyPlots.jl)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 11, 2024, 8:04pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922/4 "2024-07-11T20:04:39Z")

</div>

> [@brombo](#):
>
> \left | H \right | dB

If you remove the spaces it works, although the spacing seems odd:

```julia-repl
julia> plot(rand(10); xlabel=L"$\left|H\right| dB$")

```

![image](https://global.discourse-cdn.com/julialang/original/3X/e/9/e986db2b8c6c6ead1c6cdcfb49a7fada684ef967.png)

```julia-repl
julia> plot(rand(10); xlabel=L"$\left|\frac{1}{2}\right| dB$")

```

![image](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e8be60ba129205120cdb53470a56eb824770e40.png)

---

<div class="post-metadata">

**Author:** ![brombo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brombo/32/47867_2.png) [@brombo](https://discourse.julialang.org/u/brombo)\
**Post date:** [July 11, 2024, 8:19pm UTC](https://discourse.julialang.org/t/plots-and-latexstrings-not-recognizing-some-latex-commands/116922/5 "2024-07-11T20:19:24Z")

</div>

Thank you. I will try that along with the effects of using other backends. I tried the following and it fixed the spacing -

`$\left|\!\! H \right| \textrm{\ dB}$`

 ![LX521.4_Mg](https://global.discourse-cdn.com/julialang/original/3X/6/6/66086646998cd4dbb5cd52ba8c43f91dc5cd79c6.jpeg)
