Plots and LaTeXStrings not recognizing some LaTeX commands

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

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.

See FAQ: Not a LaTeX renderer. LaTeXStrings is not responsible for doing the LaTeX math rendering — that is done by MathJax, MathTeXEngine.jl, or other renderers 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?

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

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

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

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

image

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

image

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}$