From 2a663ee71c6dc91baab41c438135f4207cb6eaf1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 11 Jan 2014 09:50:27 +0100 Subject: [PATCH] Closes #901: Emit a warning when using docutils' new "math" markup without a Sphinx math extension active. --- CHANGES | 3 +++ sphinx/builders/text.py | 1 + sphinx/writers/html.py | 7 +++++++ sphinx/writers/latex.py | 9 +++++++++ sphinx/writers/manpage.py | 8 ++++++++ sphinx/writers/texinfo.py | 8 ++++++++ sphinx/writers/text.py | 10 ++++++++++ 7 files changed, 46 insertions(+) diff --git a/CHANGES b/CHANGES index a28c6ea33..c14656394 100644 --- a/CHANGES +++ b/CHANGES @@ -43,6 +43,9 @@ Bugs fixed pngmath-generated images. This rebuilds them correctly when ``pngmath_latex_preamble`` changes. +* #901: Emit a warning when using docutils' new "math" markup without a Sphinx + math extension active. + Documentation ------------- diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py index 4b73167b1..f09ad6541 100644 --- a/sphinx/builders/text.py +++ b/sphinx/builders/text.py @@ -54,6 +54,7 @@ class TextBuilder(Builder): self.writer = TextWriter(self) def write_doc(self, docname, doctree): + self.current_docname = docname destination = StringOutput(encoding='utf-8') self.writer.write(doctree, destination) outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix) diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 1abe7b3a6..c54f3369a 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -551,6 +551,13 @@ class HTMLTranslator(BaseTranslator): node['classes'].append('field-odd') self.body.append(self.starttag(node, 'tr', '', CLASS='field')) + def visit_math(self, node, math_env=''): + self.builder.warn('using "math" markup without a Sphinx math extension ' + 'active, please use one of the math extensions ' + 'described at http://sphinx-doc.org/ext/math.html', + (self.builder.current_docname, node.line)) + raise nodes.SkipNode + def unknown_visit(self, node): raise NotImplementedError('Unknown node: ' + node.__class__.__name__) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 80080752e..58c7f5f82 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1532,5 +1532,14 @@ class LaTeXTranslator(nodes.NodeVisitor): def depart_system_message(self, node): self.body.append('\n') + def visit_math(self, node): + self.builder.warn('using "math" markup without a Sphinx math extension ' + 'active, please use one of the math extensions ' + 'described at http://sphinx-doc.org/ext/math.html', + (self.curfilestack[-1], node.line)) + raise nodes.SkipNode + + visit_math_block = visit_math + def unknown_visit(self, node): raise NotImplementedError('Unknown node: ' + node.__class__.__name__) diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index f652e9188..bc4da17ab 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -342,5 +342,13 @@ class ManualPageTranslator(BaseTranslator): def depart_inline(self, node): pass + def visit_math(self, node): + self.builder.warn('using "math" markup without a Sphinx math extension ' + 'active, please use one of the math extensions ' + 'described at http://sphinx-doc.org/ext/math.html') + raise nodes.SkipNode + + visit_math_block = visit_math + def unknown_visit(self, node): raise NotImplementedError('Unknown node: ' + node.__class__.__name__) diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 66a0e0392..7b70485aa 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -1393,3 +1393,11 @@ class TexinfoTranslator(nodes.NodeVisitor): pass def depart_pending_xref(self, node): pass + + def visit_math(self, node): + self.builder.warn('using "math" markup without a Sphinx math extension ' + 'active, please use one of the math extensions ' + 'described at http://sphinx-doc.org/ext/math.html') + raise nodes.SkipNode + + visit_math_block = visit_math diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 3bf7588ab..57a40b296 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -152,6 +152,7 @@ class TextTranslator(nodes.NodeVisitor): def __init__(self, document, builder): nodes.NodeVisitor.__init__(self, document) + self.builder = builder newlines = builder.config.text_newlines if newlines == 'windows': @@ -838,5 +839,14 @@ class TextTranslator(nodes.NodeVisitor): self.body.append(node.astext()) raise nodes.SkipNode + def visit_math(self, node): + self.builder.warn('using "math" markup without a Sphinx math extension ' + 'active, please use one of the math extensions ' + 'described at http://sphinx-doc.org/ext/math.html', + (self.builder.current_docname, node.line)) + raise nodes.SkipNode + + visit_math_block = visit_math + def unknown_visit(self, node): raise NotImplementedError('Unknown node: ' + node.__class__.__name__)