# Unexpected spacing in LaTeX plot label

**URL:** <https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740>\
**Category:** General Usage\
**Tags:** plotting, latex, gr\
**Created:** [June 29, 2021, 9:52am UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740 "2021-06-29T09:52:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![psanan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/psanan/32/30106_2.png) [@psanan](https://discourse.julialang.org/u/psanan)\
**Post date:** [June 29, 2021, 9:52am UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/1 "2021-06-29T09:52:35Z")

</div>

I’d like to label a line on a plot using LaTeX to write a norm, e.g.

```
using Plots
using LaTeXStrings
plot([1,2,3], label=L"||x-y||^2")

```

I see  
 ![Bildschirmfoto 2021-06-29 um 11.37.30 Kopie](https://global.discourse-cdn.com/julialang/original/3X/0/5/05244b45e7532edb2c0dd0e12d99dcaa505e800d.png)

but the text inside the norm appears shifted to the right and the spacing between the double bars is greater than expected. I was hoping the label text would look more like  
 ![x-y^2](https://global.discourse-cdn.com/julialang/original/3X/a/2/a2c1bb701832998cbf7450f8906617c9a2d8285f.png)

Is there a way to get my desired appearance?

(Julia official release 1.6.1 (2021-04-23) on OS X)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 29, 2021, 10:09am UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/2 "2021-06-29T10:09:14Z")

</div>

I think this is a bug in GR’s fonts rendering

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 29, 2021, 11:03am UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/3 "2021-06-29T11:03:33Z")

</div>

Yeah, there’s a couple of those. It also messes up `\mathrm{x}^2`.

GR doesn’t actually run `LaTeX`, but has its own built-in approximation. Doesn’t always work.

---

<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:** [June 29, 2021, 1:36pm UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/4 "2021-06-29T13:36:45Z")

</div>

Workaround: use unicode:

```julia
plot([3,2,1], label="‖x-y‖²")

```

---

<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:** [June 29, 2021, 2:37pm UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/5 "2021-06-29T14:37:38Z")

</div>

It works fine with Plots.jl’s `pgfplotsx()` backend:

```julia
using LaTeXStrings, Plots; pgfplotsx()

plot([1,2,3], label=L"||x-y||^2")

```

 ![Plots_pgfplotsx_Latex_label](https://global.discourse-cdn.com/julialang/original/3X/2/1/21200f90a7cde674f345f96800f22ff786381b33.png)

---

<div class="post-metadata">

**Author:** ![psanan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/psanan/32/30106_2.png) [@psanan](https://discourse.julialang.org/u/psanan)\
**Post date:** [June 29, 2021, 5:52pm UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/6 "2021-06-29T17:52:20Z")

</div>

That does look nicer - thanks! At the end of the day this will allow me to generate my plots, but it’s a bit inconvenient because my other plots unfortunately don’t work with `pgfplotsx()` (and they’re slow, so I want to use GR for its promised speed). Simply changing the backend for some of the plots doesn’t work in my code as written, because of [this issue](https://discourse.julialang.org/t/defining-plots-in-function-results-in-world-problem/42401) where you can’t change plot backends within a function. In any case, I’ll mark this as the solution since the original problem is a known issue with the GR backend.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 29, 2021, 7:38pm UTC](https://discourse.julialang.org/t/unexpected-spacing-in-latex-plot-label/63740/7 "2021-06-29T19:38:21Z")

</div>

You should be able to hack it with `\,` or `\;`
