rst and pypandoc

Dave Angel davea at davea.name
Mon Mar 2 07:03:52 EST 2015


On 03/02/2015 02:59 AM, alb wrote:
> Hi everyone,
>
> I'm writing a document in restructured text and I'd like to convert it
> to latex for printing. To accomplish this I've used semi-successfully
> pandoc and the wrapper pypandoc.

I don't see other responses yet, so I'll respond even though i don't 
know pyandoc.

>
> My biggest issue is with figures and references to them. We've our macro
> to allocate figures so I'm forced to bypass the rst directive /..
> figure/, moreover I haven't happened to find how you can reference to a
> figure in the rst docs.
>
> For all the above reasons I'm writing snippets of pure latex in my rst
> doc, but I'm having issues with the escape characters:
>
> i = '\ref{fig:abc}'
> print pypandoc.convert(i, 'latex', format='rst')
> ef\{fig:abc\}
>
> because of the \r that is interpreted by python as special character.

I don't know whether your problem is understanding what Python does with 
literals, or what pyandoc wants.  I can only help with the former.

You could try printing the i to see what it looks like, if you don't 
understand Python literal escaping.  Perhaps something like:

print "++" + i + "++"

Those pluses tend to help figure out what happens when you have control 
codes mixed in the line.  For example as it stands, the 0x0d character 
will have the effect of overwriting those first two "++"

A second method is to look at the string in hex:

     print i.encode("hex")

>
> If I try to escape with '\' I don't seem to find a way out...



You should be a lot more explicit with all three parts of that 
statement.  Try:


I'm trying to get a string of
      <here you show the string you expected from that convert statement>
When I try to escape with '\'
       i = '\\ref{fig:abc}'
I get the following exception:
       <here you include the traceback>






-- 
DaveA



More information about the Python-list mailing list