我正在尝试用Ruby生成一个很长的Latex文档。如果我使用普通的heredoc类型声明,Ruby会检测到反斜杠(Latex中有许多反转),因为Unicode转义:
doc = <<DOC
\underline{FOO}
DOC #=> invalid Unicode escape \underline{FOO}
如果我在DOC
周围加上单引号,它会将整个事物视为字符串文字:
doc = <<'DOC'
\underline{FOO}
DOC
puts doc #=> \underline{FOO}
没关系,但现在我不能使用字符串插值:
foo = "foo"
doc = <<'DOC'
string interpolation says "#{foo}".
DOC
puts doc #=> string interpolations says "#{foo}".
我想要两全其美,即字符串插值,而不必逃避每个反斜杠。这可能吗?