Breaking down your problem a bit, the first goal is to get the latex code output verbatim (except for cgi-escapes for <,>, etch.) into the html generated from your light markup of choice: once you have it there, it can easily be LaTex'ed by mathJax (highly recommended) or itex as mentioned by gozzilli.
First I should say that using markdown instead of ReST would probably be easier because ReST uses \ for escaping, so all LaTeX has to be protected. For an example of how nicely things work out with markdown and mathJax, go play around with the setup at mathoverflow.net.
Nevertheless, I will assume that you really want ReST (and mathJax) , in which case there are two ways ahead: use stock ReST (and cumbersome escaping), or add some LaTeX handlers to docutils.
Option 1 - Stock ReST:
For inline math, simply use verbatim plus whatever you tags your postprocessor is looking for: ``$x<\pi$``. For multi-line math, you want a literal block, but you need to set a class attribute for e.g. MathJaX to parse it, as it otherwise skips <pre>
tags:
.. class:: mathjax_process
::
\begin{equation}
x<\pi
\end{equation}
Option 2: Extend you ReST processor
If you are willing to do a bit of hacking to extend your ReST processor, you can get a much nicer notation for the LaTeX literals, by defining a custom interpreted text role for inline latex (e.g. :latex:`x<\pi`
) and a custom directive for multi line math, e.g.
.. latex::
\begin{equation}
x<\pi
\end{equation}
The inline math notation can even be shortened to `x<\pi`
if you use default-role.
There are several ways to implement the role and directive. I have arrived at (roughly) the following which has the nice feature that (unlike most other hacks I have seen) it degrades to literal LaTex code for writers with no integrated post processing.
from docutils import nodes, utils
from docutils.parsers.rst import directives, Directive
class Latex(Directive):
""" Latex directive to display LaTeX as escaped literal wrapped in
<pre class="latex">.
"""
required_arguments = 0
optional_arguments = 0
has_content = True
def run(self):
self.assert_has_content()
prenode=nodes.literal_block(self.block_text,
'\n'.join(self.content),
classes=['latex'])
return [prenode]
directives.register_directive('latex', Latex)
def latex_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
node = nodes.literal(rawtext,
'\(%s\)'%utils.unescape(text, 1),
classes=['latex'])
return [node],[]
register_local_role('latex', latex_role)
The above will use the class "latex" to mark stuff for processing, so you'll need to configure mathJax or equivalent to look for this class. Alternatively, change the code above to set the class to "mathjax_process" which is the default mathJax override class.
\frac{}{}
or type out a one-line expression and hope you don't get lost in parentheses. Mathematicians still prefer the pen-and-paper method because it is the fastest. If you need to digitize your notes, look into something like this: livescribe.com or a document scanner. Math is just one of those things that is not amenable to fast keyboard input. – Gilead