rst and pypandoc

alb al.basili at gmail.com
Mon Mar 2 07:36:37 EST 2015


Hi Dave,

Dave Angel <davea at davea.name> wrote:
[]
> You should be a lot more explicit with all three parts of that 
> statement.  Try:
> 
> 
> I'm trying to get a string of

\ref{fig:A.B}

but unfortunately I need to go through a conversion between rst and 
latex. This is because a simple text like this:

<rst-text>
this is a simple list of items:

 - item A.
 - item B.

</rst-text>

gets translated into latex by pypandoc as this:

<latex-text>
\begin{itemize}
  \item item A.
  \item item B.
\end{itemize}
<latex-text>

And it's much simpler to write my document with rst markup rather than latex.

So my question is what should my restructured text look like in order to 
get it through pypandoc and get the following:

\ref{fig:abc}


Apparently rst only allows the following type of references:

- external hyperlink targets
- internal hyperlink targets
- indirect hyperlink targets
- implicit hyperlink targets

and I want to get a later that has a reference to a figure, but none of 
those seem to be able to do so. Therefore I thought about passing an 
inline text in my rst in order to get it through the conversion as is, 
but apparently I'm stuck with the various escaping mechanisms.

My python script reads the text and passes it on to pypandoc:

i = "%\n" % text
o = pypandoc.convert(i, 'latex', format='rst')

So if text is:

<text>
this is some text with a reference to Figure \ref{fig:abc}
</text>

I would like o to be like:

this is some text with a reference to Figaure \ref{fig:abc}

but I get:

ef\{fig:abc\}

Al




More information about the Python-list mailing list