# UniftulRecipes and LaTeXStrings

**URL:** <https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247>\
**Category:** New to Julia\
**Created:** [December 22, 2020, 10:16pm UTC](https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247 "2020-12-22T22:16:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [December 22, 2020, 10:16pm UTC](https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247/1 "2020-12-22T22:16:30Z")

</div>

Hi

Is there a way to use simultaneously UnitfulRecipes and LaTeXStrings? Somewhat like (adapted from [UniftulRecipes’ first example](https://github.com/jw3126/UnitfulRecipes.jl):

```julia
using Unitful, UnitfulRecipes, Plots, LaTeXStrings
const a = 1u"m/s^2"
v(t) = a * t
x(t) = a/2 * t^2
t = (0:0.01:100)*u"s"
plot(x.(t), v.(t), xlabel=L"\textrm{Position} \xi", ylabel=L"\textrm{Speed} \sigma")

```

and it should have the correct LaTeX labels in both axes, appended with their respective units (within parentheses). However, this does not work… I might always ustrip the unitful quantities and set the labels manually together with their units, but I thought this should work seamlessly with Unitful, UnitfulRecipes and LaTeXStrings…

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [December 23, 2020, 7:51am UTC](https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247/2 "2020-12-23T07:51:44Z")

</div>

That’s because the appending was expecting a `String` not an `AbstractString`.

I just made [a PR to UnitfulRecipes](https://github.com/jw3126/UnitfulRecipes.jl/pull/35) to fix this, but I think there is a road block with your specific example. First, I think that using `\textrm` is a problem because one would then also want to use `\textrm` to append the label for consistency, but UnitfulRecipes does not know about LaTeXStrings or any LaTeX commands, so, instead I think it’s better to use `$` signs, e.g.,

```julia
julia> xlabel = L"Position $\xi$"
L"Position $\xi$"

```

which can then be nicely modified by appending `" (m)"`:

```julia
julia> LaTeXString(xlabel * " (m)")
L"Position $\xi$ (m)"

```

However, the GR backend does not work nicely with that syntax for some reason (gentle ping to @jheinen who will certainly know more about that). Anyway, the PR should work as long as you use, e.g., the `pyplot()` backend, as shown in the example commented in the PR and copied here for your convenience:

```julia
using Unitful, UnitfulRecipes, Plots, LaTeXStrings # Note it's UnitfulRecipes PR #35 here
pyplot() # does not work with the GR backend for me (yet?)
const a = 1u"m/s^2"
v(t) = a * t
x(t) = a/2 * t^2
t = (0:0.01:100)*u"s"
plot(x.(t), v.(t), xlabel=L"Position $\xi$", ylabel=L"Speed $\sigma$")

```

which gives

 ![Screen Shot 2020-12-23 at 6.48.29 pm](https://global.discourse-cdn.com/julialang/original/3X/6/c/6cfc6d4ac6478b24b144e391f9f0317049df43d4.jpeg)

Hopefully this helps!

---

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [December 23, 2020, 11:08am UTC](https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247/3 "2020-12-23T11:08:40Z")

</div>

@briochemc: thanks for the prompt reply and the pull request (PR) filing! I use to use the default GR backend, but I would not mind using the good old pyplot one (very powerful and triggers some good memories from my Matplotlib experience). I hope the PR is easy to implement!

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [December 23, 2020, 11:44am UTC](https://discourse.julialang.org/t/uniftulrecipes-and-latexstrings/52247/4 "2020-12-23T11:44:05Z")

</div>

No worries! FWIW, I’m the same, I use the default backend (GR) most of the time, especially for quick exploration/plotting, and I generally don’t bother with LaTeX and try to use Unicode instead, which is why I overlooked this LaTeXStrings application, and also never stumbled upon the GR issue with things like `plot(rand(10), xlabel=L"my equation is $y = a x + b$")`.

BTW I think the PR is mostly done, it’s not much more than changing a `String` into an `AbstractString`, really. So probably a few days to fix whatever comes up during CI and we’ll merge it! 😃
