# Issue with Plots & LaTeX

**URL:** https://discourse.julialang.org/t/issue-with-plots-latex/71045
**Category:** General Usage
**Tags:** plotting, latex
**Created:** [November 6, 2021, 10:32am UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045 "2021-11-06T10:32:24Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [November 6, 2021, 10:32am UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/1 "2021-11-06T10:32:24Z")

</div>

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

```julia
using LaTeXStrings
using Plots
bar(rand(5))
title!(L"Testing LaTEX: $\sigma=1.2$")

```

 ![Screen Shot 2021-11-06 at 12.22.53](https://global.discourse-cdn.com/julialang/original/3X/4/7/47b05e90bcfcd279a3a5adfb42aa0cd839a6e784.jpeg)

Note that removing the $ signs doesn’t help:

```julia
title!(L"\sigma=1.2")

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](https://global.discourse-cdn.com/julialang/original/3X/7/f/7fddeb150f84af4af63bb88b24ada6578766d9a9.png)

I’m on Julia 1.6.3

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

```

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

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 6, 2021, 11:10am UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/2 "2021-11-06T11:10:27Z")

</div>

The following syntax works `using Plots; gr()`:

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

```

 ![Plots_gr_LaTeXString](https://global.discourse-cdn.com/julialang/original/3X/b/2/b234bf32e4a52a42e1ba64bf68506f79b5678524.png)

---

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [November 6, 2021, 11:30am UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/3 "2021-11-06T11:30:52Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> using LaTeXStrings, Plots; gr()
> bar(rand(5))
> title!(L"\textrm{Testing\ LaTeX:} \sigma=1.2")
> 
> ```

Nope…

 ![Screen Shot 2021-11-06 at 13.29.44](https://global.discourse-cdn.com/julialang/original/3X/9/e/9e03860eb6949a767adabfacb7dda1fead80804c.png)

Note I’m running this on MacOS.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 6, 2021, 11:32am UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/4 "2021-11-06T11:32:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [November 6, 2021, 12:17pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/5 "2021-11-06T12:17:46Z")

</div>

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

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

```

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

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

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 6, 2021, 12:52pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/6 "2021-11-06T12:52:49Z")

</div>

> [@dodoplus](#):
>
> `[91a5bcdd] Plots v0.29.9`

Is this version from the last century? 🙂  
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](https://discourse.julialang.org/t/difficulty-installing-polyhedra/60562/2).

---

<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: [November 6, 2021, 1:35pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/7 "2021-11-06T13:35:54Z")

</div>

Don’t Latex must be installed in the system?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 6, 2021, 1:39pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/8 "2021-11-06T13:39:12Z")

</div>

According to @jheinen [in this post](https://github.com/JuliaPlots/Plots.jl/issues/2659#issuecomment-656503819), the answer seems to be no for Plots gr() in the latest versions.

---

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [November 6, 2021, 2:31pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/9 "2021-11-06T14:31:34Z")

</div>

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…

```julia
(@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?

---

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [November 6, 2021, 2:47pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/10 "2021-11-06T14:47:22Z")

</div>

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

Thanks!

---

<div class="post-metadata">

### Author: ![tomas-budi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas-budi/32/30621_2.png) [@tomas-budi](https://discourse.julialang.org/u/tomas-budi)
#### Post date: [November 9, 2021, 3:14pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/11 "2021-11-09T15:14:38Z")

</div>

Hi, I have been using the tips given [here](https://discourse.julialang.org/t/tips-to-create-beautiful-publication-quality-plots/32384) 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  
 ![mwe](https://global.discourse-cdn.com/julialang/original/3X/e/4/e41ee0ff188a370683945103a2aac5e0596cc355.png)

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

---

<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: [November 9, 2021, 4:19pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/12 "2021-11-09T16:19:29Z")

</div>

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:

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

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

```julia
julia> using GR, LaTeXStrings

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

```

![image](https://global.discourse-cdn.com/julialang/original/3X/f/b/fb6910eae1db7af6fbaf67c791b40da9382cff59.png)

Reported it here: [odd spacing with LaTeXStrings with \textrm · Issue #439 · jheinen/GR.jl · GitHub](https://github.com/jheinen/GR.jl/issues/439)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 9, 2021, 4:29pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/13 "2021-11-09T16:29:26Z")

</div>

> [@tomas-budi](#):
>
> xlabel!(L"\textrm{This is } \alpha")

Just use backslashes to keep the spaces:

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

```

---

<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: [November 9, 2021, 4:40pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/14 "2021-11-09T16:40:21Z")

</div>

Still there is a bug on the spacing anyway. That looks like this here: ![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/3890f25aa1319db6af2626f33cd1e85eb79d1355.png)

@jheinen provided an alternative for this specific case here: [odd spacing with LaTeXStrings with \textrm · Issue #439 · jheinen/GR.jl · GitHub](https://github.com/jheinen/GR.jl/issues/439#issuecomment-964313459)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 9, 2021, 4:42pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/15 "2021-11-09T16:42:58Z")

</div>

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

 ![Plots_gr_Latex_spacing](https://global.discourse-cdn.com/julialang/original/3X/7/7/77c2066bfdf7ad5d6192e5a667d443c23bf19a92.png)

---

<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: [November 9, 2021, 5:00pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/16 "2021-11-09T17:00:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 9, 2021, 9:14pm UTC](https://discourse.julialang.org/t/issue-with-plots-latex/71045/17 "2021-11-09T21:14:23Z")

</div>

OK. In the latest versions, the following works:

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

```
