# LaTeXStrings: mix Tex and value of pre-existing variable in string

**URL:** <https://discourse.julialang.org/t/latexstrings-mix-tex-and-value-of-pre-existing-variable-in-string/21201>\
**Category:** General Usage\
**Tags:** question, package, plotting\
**Created:** [February 26, 2019, 4:33am UTC](https://discourse.julialang.org/t/latexstrings-mix-tex-and-value-of-pre-existing-variable-in-string/21201 "2019-02-26T04:33:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [February 26, 2019, 4:33am UTC](https://discourse.julialang.org/t/latexstrings-mix-tex-and-value-of-pre-existing-variable-in-string/21201/1 "2019-02-26T04:33:05Z")

</div>

I’m trying to use [LaTeXStrings](https://github.com/stevengj/LaTeXStrings.jl) in Julia 1.1 and `PyPlot` to programmatically label various subplots. For example, I have a collection of indexed variables \omega\_i and \tau\_i, but I only want to plot a specific subset of them, e.g., \omega\_1, \omega\_3, \tau\_3, and \tau\_4. I’m trying to generate an array `labels` similar to the below

```julia
labels = [[L"$\omega_{$(i)$}$" for i in omega_indices]; 
          [L"$\tau_{$(i)$}$" for i in tau_indices]]

```

but am unable to bring the value of `i` into the string expression. I’ve also tried

```julia
labels = [[L"$\omega_$"*"$(i)" for i in omega_indices]; 
          [L"$\tau_$"*"$(i)" for i in tau_indices]]

```

without luck. Is there aproper way to do so?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [February 26, 2019, 5:09am UTC](https://discourse.julialang.org/t/latexstrings-mix-tex-and-value-of-pre-existing-variable-in-string/21201/2 "2019-02-26T05:09:32Z")

</div>

```julia
i = 1
latexstring("\$\\omega_{$(i)}\$")
# L"$\omega_{1}$"

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 26, 2019, 9:04am UTC](https://discourse.julialang.org/t/latexstrings-mix-tex-and-value-of-pre-existing-variable-in-string/21201/3 "2019-02-26T09:04:43Z")

</div>

@mohamed82008 already provided a solution using LaTeXStrings, but generally I would go with raw strings in plain Julia, eg

```julia
raw"$\omega_{" * string(i) * raw"}$"

```

or

```julia
raw"$\omega_" * "{$(i)}" * raw"}$"

```

All that escaping can become a headache very easily.
