# How to get escaping in a custom string macro to work?

**URL:** https://discourse.julialang.org/t/how-to-get-escaping-in-a-custom-string-macro-to-work/49709
**Category:** New to Julia
**Created:** [November 6, 2020, 10:18pm UTC](https://discourse.julialang.org/t/how-to-get-escaping-in-a-custom-string-macro-to-work/49709 "2020-11-06T22:18:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [November 6, 2020, 10:18pm UTC](https://discourse.julialang.org/t/how-to-get-escaping-in-a-custom-string-macro-to-work/49709/1 "2020-11-06T22:18:46Z")

</div>

I have a little string macro as follows

```julia
macro Q_str(p)
	esc(:(println(Crayon(foreground = :light_cyan ), $p)))
end

```

Basically I can just write

```julia
Q"""
This is a multi-line string. Printed in light cyan
"""

```

It’s nice cause I can get a note-book-like workflow with very low effort and keep the REPL etc.

Problem, string escaping behaves differently in my `Q_str` macro

```julia
julia> x = Q"""
       The value of x is 
       
       $(x)
       """
The value of x is 

$(x)

```

Does anyone know how I can get all the string escaping for normal multi-line strings to behave the same?

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [November 6, 2020, 11:44pm UTC](https://discourse.julialang.org/t/how-to-get-escaping-in-a-custom-string-macro-to-work/49709/2 "2020-11-06T23:44:01Z")

</div>

This is the same issue as handling escaping in expressions as well, no? Basically the macro runs pre-substitution, so it falls on you to replicate the logic AFAICT.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [November 7, 2020, 12:50am UTC](https://discourse.julialang.org/t/how-to-get-escaping-in-a-custom-string-macro-to-work/49709/3 "2020-11-07T00:50:35Z")

</div>

Ah darn, I guess `@Q md"""` as a shorthand is gooe enought.
