问题
I am trying to embed a LaTeX variable into some reStructuredText. I know about the ".. raw::" directive, but I want this to be embedded in a paragraph of text. Specifically, I am looking to replicate the \numquestions\ and \numpoints\ variables from the template exam document. I have tried using :raw:\numquestions\, but this does not seem to be valid. Is there any way of doing this?
回答1:
You first have to define your own latex role, which allows you then to embed LaTex directly into paragraphs:
.. role:: latex(raw)
:format: latex
Now, you can write things like :latex:`\\textsc{NoTex}` directly embedded in paragraphs. You can find an example of this in the browser based text editor NoTex with support for reStructuredText and PDF, LaTex & HTML export options.
回答2:
Use the raw role (the inline equivalent of the raw directive). See these references:
- http://docutils.sourceforge.net/FAQ.html#how-can-i-include-mathematical-equations-in-documents
- http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw
来源:https://stackoverflow.com/questions/7533406/can-i-use-inline-raw-latex-in-restructuredtext