Issue with Plots & LaTeX

In the following code, the $ signs around the LaTeX text are printed. Quite sure that’s not the right behavior:

using LaTeXStrings
using Plots
title!(L"Testing LaTEX: $\sigma=1.2$")

Note that removing the $ signs doesn’t help:


sh: latex: command not found
latex: failed to create a dvi file

Printing LaTeX via Jupyter seems to work fine:
Screen Shot 2021-11-06 at 12.28.34

I’m on Julia 1.6.3

(@v1.6) pkg> st
  [b964fa9f] LaTeXStrings v1.2.1
  [91a5bcdd] Plots v0.29.9

GR doesn’t appear to be installed outside of Plots.

The following syntax works using Plots; gr():

using LaTeXStrings, Plots; gr()
title!(L"\textrm{Testing\ LaTeX:} \sigma=1.2")


Note I’m running this on MacOS.

Ok, here it is Win10. In any case make sure the latest package versions are installed.

Did a Pkg.update(). It updated LaTexStrings:

[b964fa9f] ↑ LaTeXStrings v1.2.1 ⇒ v1.3.0

However, it did solve the problem: still getting error messages such as:

sh: latex: command not found
latex: failed to create a dvi file

Is this version from the last century? :slight_smile:
It seems it was issued on Mar 27, 2020, but Plots is already at v1.23.5.

There are many recommendations in Discourse to create new project environments and work with only the packages you need. Update failing due to version# conflict issues are then minimized. See for instance this post.

1 Like

Don’t Latex must be installed in the system?

According to @jheinen in this post, the answer seems to be no for Plots gr() in the latest versions.

1 Like

Hmm… seems Julia didn’t upgrade Plots due to dependency issues.

This is what I get when trying to upgrade manually. There are pages of dependencies…

(@v1.6) pkg> add Plots@1.23.5
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package AbstractFFTs [621f4979]:
 AbstractFFTs [621f4979] log:
 ├─possible versions are: 0.3.0-1.0.1 or uninstalled
 ├─restricted by compatibility requirements with FFTW [7a1cc6ca] to versions: 0.3.0-1.0.1
 │ └─FFTW [7a1cc6ca] log:
 │   ├─possible versions are: 0.1.0-1.4.5 or uninstalled
 │   ├─restricted by compatibility requirements with KernelDensity [5ab0869b] to versions: 0.1.0-1.4.5
 │   │ └─KernelDensity [5ab0869b] log:
 │   │   ├─possible versions are: 0.5.0-0.6.3 or uninstalled
 │   │   └─restricted to versions * by an explicit requirement, leaving only versions 0.5.0-0.6.3
 │   ├─restricted by compatibility requirements with ImageFiltering [6a3955dd] to versions: 0.3.0-1.4.5
 │   │ └─ImageFiltering [6a3955dd] log:
 │   │   ├─possible versions are: 0.4.0-0.7.1 or uninstalled
 │   │   ├─restricted by compatibility requirements with Images [916415d5] to versions: 0.4.0-0.6.22
 │   │   │ └─Images [916415d5] log:
 │   │   │   ├─possible versions are: 0.17.3-0.24.1 or uninstalled
 │   │   │   ├─restricted to versions * by an explicit requirement, leaving only versions 0.17.3-0.24.1
 │   │   │   ├─restricted by compatibility requirements with FixedPointNumbers [53c48c17] to versions: 0.18.0-0.24.1 or uninstalled, leaving only versions: 0.18.0-0.24.1
 │   │   │   │ └─FixedPointNumbers [53c48c17] log:
 │   │   │   │   ├─possible versions are: 0.5.0-0.8.4 or uninstalled

Note that I’ve never explicitly installed most of those packages.

Is there a way to get the Julia environment into a sane configuration?

Update: started a new environment and managed to get latest Plots installed.
Problem went away.


1 Like

Hi, I have been using the tips given here for my Plots for quite a long time, so first let me thank @lmiq. Recently, though, I have been facing problems with LaTeX strings in my labels. In particular, it seems that LaTeX strings do not understand spaces between each word. MWE:

using Plots, LaTeXStrings
default(fontfamily=“Computer Modern”, linewidth=2, framestyle=:box, label=nothing, grid=false)
x = rand(10)
y = rand(10)
plot(x[1:10], y)
xlabel!(L"\textrm{This is } \alpha")

produces the following

The problem is not coming from \textrm{} as I also face it when I remove it.
The Plot backend is gr() and package versions are Plots v1.23.5, GR v0.62.1 and LaTeXStrings v1.3.0

1 Like

Indeed, I see the same thing now. And usually one could add ~ to force the spaces to appear, but the spacing is odd anyway (particularly the space between the capital T and the rest:


It is an issue with GR, as it occurs even without Plots:

julia> using GR, LaTeXStrings

julia> x = rand(10)
       y = rand(10)
       plot(x[1:10], y, xlabel=L"\textrm{This is } \alpha")


Reported it here: odd spacing with LaTeXStrings with \textrm · Issue #439 · jheinen/GR.jl · GitHub


Just use backslashes to keep the spaces:

xlabel!(L"\textrm{This\ is\ } \alpha")

Still there is a bug on the spacing anyway. That looks like this here: image

@jheinen provided an alternative for this specific case here: odd spacing with LaTeXStrings with \textrm · Issue #439 · jheinen/GR.jl · GitHub

Do not seem to see the same thing here using Plots; gr():

We are using the latest version of GR, so probably yours is one without the regression.

OK. In the latest versions, the following works:

xlabel!(L"This\ is\ \alpha")