In Python one can write r"a\nb"
in order to prevent the \n
from being interpreted as an escape sequence for newline.
Is there something similar in Julia? And what about string interpolation like "$variable"
, is there a way to prevent it?
I know one can simply write "a\\nb"
and "\$variable"
in Julia, but I would like to write a lot of LaTeX strings without having to care to proper escape every backslash \
and dollar $
characters...
(In Julia, r"..."
creates a regular expression.)
From Julia 0.6 we have raw"\a$variable"
Ok, I just found out that since one can easily create non-standard string literals in Julia, a pass-through one will do what I was asking for:
macro R_str(s)
s
end
>>> R"$a\n$b"
"\$a\\n\$b"
>>> print(R"$a\n$b")
$a\n$b
I also discovered that PyPlot.jl defines a «LaTeXString type which can be constructed via L"...."
without escaping backslashes or dollar signs», with the additional benefit of rendered equations in IJulia.
A last question remains: is not worth it to have a raw string literal in Julia base?