# How to concatenate TypstStrings in Typstry.jl?

**URL:** <https://discourse.julialang.org/t/how-to-concatenate-typststrings-in-typstry-jl/124886>\
**Category:** General Usage\
**Created:** [January 17, 2025, 10:32pm UTC](https://discourse.julialang.org/t/how-to-concatenate-typststrings-in-typstry-jl/124886 "2025-01-17T22:32:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Post date:** [January 17, 2025, 10:32pm UTC](https://discourse.julialang.org/t/how-to-concatenate-typststrings-in-typstry-jl/124886/1 "2025-01-17T22:32:08Z")

</div>

I’m trying to make a custom string macro that effectively adds some initial boilerplate to the start of a Typst string.

The effect would be

```julia
julia> T"important" == typst"""
#set `some pretty rule`
important
"""
true

```

I think the main problem is that I can’t seem “hijack” the `@typst_str` macro, meaning I cant send my string to the macro as a string, it always interperets it as a macro

```julia
macro T_str(s::String)
    s = "#set `some pretty rule` \n" * s
    @typst_str(s)
end
MethodError: no method matching var"@typst_str"(::LineNumberNode, ::Module, ::Expr)

```

My current workaround is to just copy the source code for the `@typst_str` macro and add a line at the top but that seems bad long term in the event of an update to Typstry.jl

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [January 17, 2025, 10:53pm UTC](https://discourse.julialang.org/t/how-to-concatenate-typststrings-in-typstry-jl/124886/2 "2025-01-17T22:53:46Z")

</div>

This should work,

```julia
macro T_str(s::String)
     :(@typst_str($("#set `some pretty rule` \n" * s)))
end

```

i.e., instead of calling the macro directly, generate code that passes it the updated string.

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [January 18, 2025, 12:16am UTC](https://discourse.julialang.org/t/how-to-concatenate-typststrings-in-typstry-jl/124886/3 "2025-01-18T00:16:42Z")

</div>

Alternatively, and required in a non-macro context, use `TypstText` (or some other type implementing `show_typst`) to `print` the value into the string.

```julia-repl
julia> TypstString(TypstText("stuff"))
typst"stuff"

```
