Hi all,
I have a Scheme function that processes a string and writes the result
to a LaTeX file. For this I have to escape a number of characters that
are allowed in a LilyPond string but not in LaTeX input.
Consider this code:
\version "2.19.16"
#(use-modules (ice-9 regex))
str = "This should be \partcombine-d & match everything"
ampString = "\\&"
slashString = "\\textbackslash "
#(set! str
(regexp-substitute/global #f "&" str
'pre ampString 'post))
#(set! str
(regexp-substitute/global #f "\\+" str
'pre slashString 'post))
#(ly:message "")
#(ly:message str)
#(ly:message "")
The resulting output is "This should be \partcombine-d \& match
everything" while I want to have "This should be \textbackslash
partcombine-d \& match everything".
The escaping of the ampersand works as expected (although I have to
define the replacement string in a LilyPond string while entering it
directly as a string in the Scheme function doesn't seem to work), but
the backslash is not matched.
Using "\" as regex obviously doesn't work because that would escape the
quotation mark so the string isn't properly ended.
Using "\\" give the error "Trailing backslash"
Using "\\+" compiles but doesn't match the backslash.
So what's the way to match a backslash in a LilyPond string?
Additionally I'd be glad about comments to:
- Which other characters would I have to escape when writing LaTeX code
(so far I've encountered the backslash and the ampersand. But I'd feel
better if I'd not just wait for errors ...)?
- Is there a more efficient way to escape a number of characters
than piping the string through a series of regex substitutions?
TIA
Urs
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user