# \_str string interpolation?

**URL:** <https://discourse.julialang.org/t/str-string-interpolation/125766>\
**Category:** General Usage\
**Tags:** macros, string-interpolation\
**Created:** [February 10, 2025, 7:41pm UTC](https://discourse.julialang.org/t/str-string-interpolation/125766 "2025-02-10T19:41:03Z")\
**Posts on this page:** 1\
**Showing post:** 11

<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:** [February 10, 2025, 9:01pm UTC](https://discourse.julialang.org/t/str-string-interpolation/125766/11 "2025-02-10T21:01:19Z")

</div>

> [@lmiq](#):
>
> Tamas there sais that “you could do it manually”, but I’m unsure what that means and why would it be bad.

The best way to do it manually would be to transform `test"a $i"` into `string("a ", i)` (which is what regular interpolation does). (The key thing to remember is that macros only know how things are “spelled”, not what their _values_ are. By transforming the expression into `string("a ", i)` or similar, you defer the evaluation of `i` until the code actually executes and the value is known.)

An example of how to do this can be found in the [implementation of the `L"..."`](https://github.com/JuliaStrings/LaTeXStrings.jl/blob/d344f9536391ee76fd14b7b62483b6a4bccf1b4d/src/LaTeXStrings.jl#L68-L92) macro from the LaTeXStrings.jl package. In that macro, `$` is treated as the beginning of a LaTeX equation, so it is left as is, but the string `%$` is used for interpolation instead.

The steps are to (1) parse your string to find (unescaped) `$`, (2) call `Meta.parseatom` (or `Meta.parse` with `greedy=false`) to parse the next complete Julia expression after the `$`, and (3) emit the desired expression from the macro, e.g. a call to `string` (or the `latexstring` constructor in the case above).

---

_[View the full topic](https://discourse.julialang.org/t/str-string-interpolation/125766)._
