# LaTeX code for titles, labels,... with Plots.jl

**URL:** https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967
**Category:** General Usage
**Tags:** question, package, plotting
**Created:** [February 7, 2017, 8:57pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967 "2017-02-07T20:57:10Z")
**Posts on this page:** 15
**Page:** 2

<div class="post-metadata">

### Author: ![mcarpe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcarpe/32/2719_2.png) [@mcarpe](https://discourse.julialang.org/u/mcarpe)
#### Post date: [September 25, 2019, 10:25am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/22 "2019-09-25T10:25:45Z")

</div>

Which backend are you using for Plots?  
If you haven’t selected it then you’re using the default one (GR). In my experience, the solution given in the answer above your post should work, then… something like `"\$\\mathrm{Unit is} 10^3\$"`

---

<div class="post-metadata">

### Author: ![amontoison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amontoison/32/218741_2.png) [@amontoison](https://discourse.julialang.org/u/amontoison)
#### Post date: [October 6, 2019, 5:32am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/23 "2019-10-06T05:32:24Z")

</div>

Maybe you could try PGFPlots?

using Plots; pgfplots()  
using LaTeXStrings

An example:  
`plot(..., ..., label=L"...", yaxis=:log, lw=1, color=1, line=:dot, xlabel=L"k", ylabel=L"\|r_k\|", legend=:best)`

---

<div class="post-metadata">

### Author: ![KirillGerke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirillgerke/32/11383_2.png) [@KirillGerke](https://discourse.julialang.org/u/KirillGerke)
#### Post date: [November 22, 2019, 5:33pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/24 "2019-11-22T17:33:21Z")

</div>

Hello Guys,

I am in Juno and under Linux. I could not get aplha on my PyPlot graphs, and the following worked for me after some trial runs, e.g.:

```julia
using Plots, LaTeXStrings
plot!(xdata, ydata, label = "\\alpha")

```

Hope this will help somebody…

---

<div class="post-metadata">

### Author: ![KirillGerke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirillgerke/32/11383_2.png) [@KirillGerke](https://discourse.julialang.org/u/KirillGerke)
#### Post date: [December 2, 2019, 8:22pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/25 "2019-12-02T20:22:41Z")

</div>

Btw, i realized that if you want to combine greek and other characters with a text, it gets a bit trickier…  
I could solve it through this hack (funny part, no using LaTeXStrings is needed), e.g.:

```julia
ylabel!("Permeability in z-direction"*"\\mu"*"m")

```

Works for titles, data and axes labels.

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [November 1, 2020, 4:38am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/26 "2020-11-01T04:38:22Z")

</div>

Can I use \frac? in a title?

```julia
using Plots
using LaTeXStrings

f(x)=1/sqrt(x+x^2)
plot(f,title=L "f(x) = \frac {1}{x+x^{2}}"

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [November 1, 2020, 9:30am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/27 "2020-11-01T09:30:29Z")

</div>

You can, but you need to make sure you construct the Latex string correctly - in the above you have a space between the `L` and the start of the string `"` which won’t work, you need `L"f(x)..."`

---

<div class="post-metadata">

### Author: ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)
#### Post date: [December 10, 2020, 7:38am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/28 "2020-12-10T07:38:52Z")

</div>

```julia
using Plots
using LaTeXStrings
plot(0:2,0:2, xlab = L"x^2", xticks = ([0,1,2],[L"0", L"1", L"2"]))
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file

Julia>versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, ivybridge)

```

---

<div class="post-metadata">

### Author: ![schmuelinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schmuelinsky/32/20419_2.png) [@schmuelinsky](https://discourse.julialang.org/u/schmuelinsky)
#### Post date: [December 28, 2020, 1:10am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/30 "2020-12-28T01:10:26Z")

</div>

Just a quick note of what works for me:

```julia
plot(xlabel="axis label \$\\alpha^3_{AB}\$")

```

I’m using PyPlot in Jupyter Notebook on Windows, and Julia Version 1.4.1.  
I’ve tried a lot of combinations of Latexstrings, double backslashes, dollar signs, etc., and only found this by accident. In the end, the syntax that seems to work is just putting one additional backslash in front of most latex commands (including the math mode dollar signs, but not subscripts and superscripts for example).

---

<div class="post-metadata">

### Author: ![KirillGerke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirillgerke/32/11383_2.png) [@KirillGerke](https://discourse.julialang.org/u/KirillGerke)
#### Post date: [December 28, 2020, 8:46am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/31 "2020-12-28T08:46:52Z")

</div>

You are right, they change at times. I had to find the combination that worked for me, but months later then i run the same script - the results were different…  
This is a bit disappointing indeed, i hope plotting packages will get stable and will produce consistent results in the nearest future.

---

<div class="post-metadata">

### Author: ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)
#### Post date: [April 24, 2021, 11:34am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/32 "2021-04-24T11:34:58Z")

</div>

I am trying to use `L"..."` to add a label to a plot using `Plots`.  
I try to include both normal text and a symbol like:  
`L"coordinate, $x$"`  
However, it does not do the latex formatting. What could be the issue?

I know that as a workaround I can do  
`L"\textrm{coordinate, } x"`  
and it works, but I was wondering what is the problem with the former way.

---

<div class="post-metadata">

### Author: ![Michaela\_Maskova](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michaela_maskova/32/8067_2.png) [@Michaela\_Maskova](https://discourse.julialang.org/u/Michaela_Maskova)
#### Post date: [May 3, 2021, 11:37am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/33 "2021-05-03T11:37:18Z")

</div>

I think what happens here is that the “L” terms calls symbol $ automatically, meaning that `L"coordinate, $x$` is similar to `"$coordinate, $x$$`. Just try calling `L"something"` and you can see it returns `L"$something$`.

---

<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: [May 4, 2021, 1:08pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/34 "2021-05-04T13:08:48Z")

</div>

No, that’s not what it does,

```julia
julia> String(L"coordinate, $x$")
"coordinate, \$x\$"

```

`LaTeXStrings.jl` knows to not add surrounding dollar signs if there are dollar signs in the string.

The problem @roi.holtzman is having is that the backend doesn’t actually automatically show `LaTeXString`s as LaTeX, but rather looks for those dollar signs. And it doesn’t know what to do with mixed strings (`GR` doesn’t actually call a LaTeX engine but a bespoke approximation of one). To `GR` there is no difference between `L"x"` and `"\$x\$"`, and between `L"coordinate, $x$"` and `"coordinate, \$x\$"`. The latter two are not detected as math.

`textrm` is the solution to this.

---

<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: [May 4, 2021, 6:46pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/35 "2021-05-04T18:46:54Z")

</div>

This is an old thread, but which has no solution marked. Probably the solution to the original post is this:

> [@Nice fonts with Plots, GR and LaTeXStrings](https://discourse.julialang.org/t/nice-fonts-with-plots-gr-and-latexstrings/60037):
>
> This not a question, just something that might be helpful to others. With Plots 1.12 and GR0.57.4 (at least), and using these options below, one can get a plot with homogeneous fonts (“Computer Modern”) in every element. using Plots using LaTeXStrings plot\_font = "Computer Modern" default(fontfamily=plot\_font, linewidth=2, framestyle=:box, label=nothing, grid=false) scalefontsizes(1.3) plot(sort(rand(10)),sort(rand(10)),label="Legend") plot!(xlabel=L"\textrm{Standard text}(r…

---

<div class="post-metadata">

### Author: ![ignace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ignace/32/24275_2.png) [@ignace](https://discourse.julialang.org/u/ignace)
#### Post date: [June 6, 2021, 8:34pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/36 "2021-06-06T20:34:08Z")

</div>

Just to keep the forum here somewhat up to date… 🙂  
I think now the package is called `LaTeXStrings` (**[see Github](https://github.com/stevengj/LaTeXStrings.jl)**).

---

<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 8, 2021, 6:49am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/37 "2021-06-08T06:49:09Z")

</div>

@ignace, if only it hadn’t been mentioned [above](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/10), and posted a dozen times.

[Previous page](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967.md?page=1)
