I'm trying to generate a long Latex document with Ruby. If I use a normal heredoc-type declaration, Ruby detects backslashes (of which there are many in Latex) as Unicode escapes:
doc = <<DOC
\underline{FOO}
DOC #=> invalid Unicode escape \underline{FOO}
If I put single quotes around DOC it'll treat the whole thing as a string literal:
doc = <<'DOC'
\underline{FOO}
DOC
puts doc #=> \underline{FOO}
That's fine, but now I can't use string interpolation:
foo = "foo"
doc = <<'DOC'
string interpolation says "#{foo}".
DOC
puts doc #=> string interpolations says "#{foo}".
I'd like the best of both worlds, i.e. string interpolation, and not having to escape every backslash. Is this possible?