Open doyougnu opened 6 months ago
Thank you for opening this issue.
Imho this is a question of correct usage of Python. In Python, a literal string "\newcommand"
starts with a newline. A literal string r"\newcommand"
starts with a backslash.
This leaves the choice of how to provide literal strings to tikz_latex_preamble
up to the user.
Adding escaping magic to tikz_latex_preamble
would be an interface change and would break code that uses escapes on purpose. See example 1 below.
"\n"
:\tikz_latex_preamble = "\\newcommand\\Foo{First line\n\nSecond line}"
\tikz_latex_preamble = r"""
\newcommand\Foo{
First line
Second line
}
"""
Yes I agree. I didn't realize python had raw multiline strings until I did some searching. Perhaps just a documentation update is needed then?
behavior
consider this setting in
conf.py
where I'm just trying to define a macroThen using one of the examples:
note that I am not even using the macro, this yields:
because the
\n
in\newcommand
is interpreted as a newline, not as latex code.Expected behavior
tikz_latex_preamble
is interpreted as latex code or automatically escapes backslashes.Workaround
manually escape the newline like:
or use a raw string:
A more complicated example
Consider this preamble:
note the
\r
in\relax
and\t
in\tp
and the\f
in\foreach
and\fi
. Each of these will need to be escaped as well