Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: al.basili@gmail.com (alb) Newsgroups: comp.lang.python Subject: Re: rst and pypandoc Date: 3 Mar 2015 20:35:43 GMT Lines: 28 Message-ID: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f4f307$0$12979$c3e8da3$5496439d@news.astraweb.com> X-Trace: individual.net QubmqFB493FxG0j1QTjisAY58GvpcmykJS/Ux77s5etyQOVLYP X-Orig-Path: not-for-mail Cancel-Lock: sha1:X2k6jWWdXUDD/D2tpe9F7OAjub8= User-Agent: tin/2.1.1-20120623 ("Mulindry") (UNIX) (Linux/3.2.0-4-686-pae (i686)) Xref: csiph.com comp.lang.python:86862 Hi Steven, Steven D'Aprano wrote: [] >> In [43]: print pypandoc.convert(s, 'latex', format='rst') >> this is \textbackslash{}some restructured text. >> >> since a literal backslash gets converted to a literal latex backslash. > > Why is this a problem? Isn't the ultimate aim to pass it through latex, > which will then covert the \textbackslash{} back into a backslash? If not, > I have misunderstood something. \textbackslash{} is a latex command to typeset a backslash into the text. This is not what I need. I need to have a string of the form "\some" (actually we are talking about \ref or \hyperref commands). > If not, you could do something like this: > > s = 'this is %(b)ssome restructured text.' > t = pypandoc.convert(s, 'latex', format='rst') > assert t == 'this is %(b)ssome restructured text.' > print t % {'b': '\\'} This is somehow what I'm doing now, but is very dirty and difficult to expand to other corner cases. Al