# Hi, quick question on using latex strings for labeling plots in PyPlot.jl: what

**URL:** <https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757>\
**Category:** General Usage\
**Created:** [March 8, 2021, 6:35pm UTC](https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757 "2021-03-08T18:35:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 8, 2021, 6:35pm UTC](https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757/1 "2021-03-08T18:35:21Z")

</div>

Hi, quick question on using latex strings for labeling plots in PyPlot.jl: what would be a correct way to do in-place variable substitution? Here’s a piece of code that does not work ….

`ax.set_title(L"$ $(a) $")`

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615228338110500?thread_ts=1615228338.110500&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 8, 2021, 10:53pm UTC](https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757/2 "2021-03-08T22:53:41Z")

</div>

From the [documentation](https://github.com/stevengj/LaTeXStrings.jl):

> If you want to perform [string interpolation](https://docs.julialang.org/en/v1/manual/strings/#string-interpolation) (inserting the values of other variables into your string), use `%$` instead of the plain `$` that you would use for interpolation in ordinary Julia strings. For example, if `x=3` is a Julia variable, then `L"y = %$x"` will produce `L"y = 3"` .

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [March 11, 2021, 8:36am UTC](https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757/3 "2021-03-11T08:36:19Z")

</div>

> `L"y = %$x"` will produce `L"y = 3"`

This is a _very_ nice feature. (It has simplified my LaTeX strings considerably.) Thanks for adding it.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [March 11, 2021, 8:46am UTC](https://discourse.julialang.org/t/hi-quick-question-on-using-latex-strings-for-labeling-plots-in-pyplot-jl-what/56757/4 "2021-03-11T08:46:56Z")

</div>

Another option is explicit escaping:

```julia
ax.set_title("\$ $(a) \$")

```

But I agree that using `%$` is nicer.
