Index: docutils/parsers/rst/directives/body.py
===================================================================
--- docutils/parsers/rst/directives/body.py	(r??vision 4834)
+++ docutils/parsers/rst/directives/body.py	(copie de travail)
@@ -190,3 +190,22 @@
         node['classes'].extend(classes)
         self.state.nested_parse(self.content, self.content_offset, node)
         return [node]
+
+####################################################################
+# Latex-math from Jens
+#################################################################
+from docutils.parsers.rst.latexparser import parse_latex_math, latex_math
+class LatexMath(Directive):
+        has_content = True
+        def run(self): 
+            latex = ''.join(self.content)
+            try:
+                mathml_tree = parse_latex_math(latex, inline=False)
+            except SyntaxError, msg:
+                error = self.state_machine.reporter.error(
+                    msg, nodes.literal_block(self.block_text, self.block_text),
+                    line=self.lineno)
+                return [error]
+            node = latex_math(self.block_text, mathml_tree, latex)
+            return [node]
+
Index: docutils/parsers/rst/directives/__init__.py
===================================================================
--- docutils/parsers/rst/directives/__init__.py	(r??vision 4834)
+++ docutils/parsers/rst/directives/__init__.py	(copie de travail)
@@ -59,6 +59,7 @@
       'default-role': ('misc', 'DefaultRole'),
       'title': ('misc', 'Title'),
       'date': ('misc', 'Date'),
+      'latex-math': ('body', 'LatexMath'),
       'restructuredtext-test-directive': ('misc', 'TestDirective'),}
 """Mapping of directive name to (module name, class name).  The
 directive name is canonical & must be lowercase.  Language-dependent
Index: docutils/parsers/rst/languages/en.py
===================================================================
--- docutils/parsers/rst/languages/en.py	(r??vision 4834)
+++ docutils/parsers/rst/languages/en.py	(copie de travail)
@@ -64,6 +64,7 @@
       #'footnotes': 'footnotes',
       #'citations': 'citations',
       'target-notes': 'target-notes',
+      'latex-math': 'latex-math',
       'restructuredtext-test-directive': 'restructuredtext-test-directive'}
 """English name to registered (in directives/__init__.py) directive name
 mapping."""
@@ -99,6 +100,7 @@
     'uri-reference': 'uri-reference',
     'uri': 'uri-reference',
     'url': 'uri-reference',
-    'raw': 'raw',}
+    'raw': 'raw',
+    'latex-math':'latex-math'}
 """Mapping of English role names to canonical role names for interpreted text.
 """
Index: docutils/parsers/rst/roles.py
===================================================================
--- docutils/parsers/rst/roles.py	(r??vision 4834)
+++ docutils/parsers/rst/roles.py	(copie de travail)
@@ -310,6 +310,25 @@
 
 register_canonical_role('raw', raw_role)
 
+####################################################################
+# Latex-math from Jens
+####################################################################
+from docutils.parsers.rst.latexparser import parse_latex_math, latex_math
+def latex_math_role(role, rawtext, text, lineno, inliner,
+                    options={}, content=[]):
+    i = rawtext.find('`')
+    latex = rawtext[i+1:-1]
+    try:
+        mathml_tree = parse_latex_math(latex, inline=True)
+    except SyntaxError, msg:
+        msg = inliner.reporter.error(msg, line=lineno)
+        prb = inliner.problematic(rawtext, rawtext, msg)
+        return [prb], [msg]
+    node = latex_math(rawtext, mathml_tree, latex)
+    return [node], []
+    
+register_canonical_role('latex-math', latex_math_role)
+####################################################################
 
 ######################################################################
 # Register roles that are currently unimplemented.
Index: docutils/writers/html4css1/__init__.py
===================================================================
--- docutils/writers/html4css1/__init__.py	(r??vision 4834)
+++ docutils/writers/html4css1/__init__.py	(copie de travail)
@@ -1520,6 +1520,32 @@
 
     def depart_version(self, node):
         self.depart_docinfo_item()
+    has_mathml_dtd = False
+    def visit_latex_math(self, node):
+        mathml = ''.join(node.mathml_tree.xml())
+        string = """<math xmlns="http://www.w3.org/1998/Math/MathML">
+        <semantics>
+        %s
+        </semantics>
+        </math>
+        """ % mathml
+        inline = isinstance(node.parent, nodes.TextElement)
+        if not inline:
+            string += '<br/>\n'
+        self.body.append(string)
+        if not self.has_mathml_dtd:
+            doctype = ('<!DOCTYPE html'
+                       ' PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"'
+                       ' "http://www.w3.org/Math/DTD/mathml2/'
+                       'xhtml-math11-f.dtd">\n')
+            if self.settings.xml_declaration:
+                self.head_prefix[1] = doctype
+            else:
+                self.head_prefix[0] = doctype
+            self.has_mathml_dtd = True
+    
+    def depart_latex_math(self, node):
+        pass
 
     def unimplemented_visit(self, node):
         raise NotImplementedError('visiting unimplemented node type: %s'
Index: docutils/writers/latex2e/__init__.py
===================================================================
--- docutils/writers/latex2e/__init__.py	(r??vision 4834)
+++ docutils/writers/latex2e/__init__.py	(copie de travail)
@@ -2091,6 +2091,18 @@
     def depart_warning(self, node):
         self.depart_admonition()
 
+    def visit_latex_math(self, node):
+        inline = isinstance(node.parent, nodes.TextElement)
+        if inline:
+            self.body.append('$%s$' % node.latex)
+        else:
+            self.body.extend(['\\begin{equation*}\\begin{split}',
+                              node.latex,
+                              '\\end{split}\\end{equation*}'])
+                              
+    def depart_latex_math(self, node):
+        pass
+
     def unimplemented_visit(self, node):
         raise NotImplementedError('visiting unimplemented node type: %s'
                                   % node.__class__.__name__)
Index: setup.py
===================================================================
--- setup.py	(r??vision 4834)
+++ setup.py	(copie de travail)
@@ -113,7 +113,9 @@
                  'tools/rst2latex.py',
                  'tools/rst2newlatex.py',
                  'tools/rst2xml.py',
-                 'tools/rst2pseudoxml.py'],}
+                 'tools/rst2pseudoxml.py',
+		 '../sandbox/jensj/latex_math/tools/rst2latexmath.py',
+		 '../sandbox/jensj/latex_math/tools/rst2mathml.py'],}
 """Distutils setup parameters."""
 
 classifiers = [
