I'm using python to populate a tex template with arbitrary strings - and I would like to escape the strings so they're interpreted and displayed properly inside the tex file (rather than having them mess up my formatting).
Where can I find a python code snippet, which will use the tex rules for escaping an arbitrary string?
To clarify, I want to do this:
[arbitrary string] --->{latex flags}[arbitrary string]{latex flags}
from inside of a python program, such that I can run latex on:
{latex flags}[arbitrary string]{latex flags}
and latex will not complain about strange characters inside [arbitrary strings]
r
modifier to a string. Sor"\foo"
will take care of the escaping. – Matthew Leingang May 14 at 0:38