# Create a LaTeX style title with the content of a variable \[Solved\]

**URL:** <https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [March 11, 2024, 3:33pm UTC](https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470 "2024-03-11T15:33:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Dardenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denis_dardenne/32/207669_2.png) [@Denis\_Dardenne](https://discourse.julialang.org/u/Denis_Dardenne)\
**Post date:** [March 11, 2024, 3:33pm UTC](https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470/1 "2024-03-11T15:33:57Z")

</div>

My aim is to title my plot with a LaTeX style.  
My code is the following

```julia
using Plots
using LaTeXStrings
V= "My Title"
plot([1,2],[1,2], title=L"&(V)")

```

But it does not work. I already used `title=latexstring(V)` , but the space disappeared (This idea come from [LaTeX code for titles, labels,... with Plots.jl](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967) )

PS : Make` title=L"My Title"` is not a solution in my context

Thanks in advance

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 11, 2024, 3:42pm UTC](https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470/2 "2024-03-11T15:42:31Z")

</div>

You can use `%$V` to interpolate `V` into the Latex string, see [GitHub - JuliaStrings/LaTeXStrings.jl: convenient input and display of LaTeX equation strings for the Julia language](https://github.com/JuliaStrings/LaTeXStrings.jl).

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [March 11, 2024, 3:47pm UTC](https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470/3 "2024-03-11T15:47:25Z")

</div>

In the default GR backend its a bit tricky but

```julia
plot([1,2],[1,2], title=latexstring("\\textrm{$(replace(V, " " => "~"))}"))

```

worked for this example.

With `pgfplotsx()`

```julia
plot([1,2],[1,2], title=LaTeXString(V))

```

would suffice.

---

<div class="post-metadata">

**Author:** ![Denis\_Dardenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denis_dardenne/32/207669_2.png) [@Denis\_Dardenne](https://discourse.julialang.org/u/Denis_Dardenne)\
**Post date:** [March 11, 2024, 3:54pm UTC](https://discourse.julialang.org/t/create-a-latex-style-title-with-the-content-of-a-variable-solved/111470/4 "2024-03-11T15:54:24Z")

</div>

Thank you, I selected your first solution which works well.

🙂
