summaryrefslogtreecommitdiff
path: root/docutils/utils/math
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2019-08-27 12:09:19 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2019-08-27 12:09:19 +0000
commit3e160024a560b8e31bf94db73d2cf8f93c0122f2 (patch)
tree2e9fc7d5817fe98743cfa278771f250ba06054ca /docutils/utils/math
parentb5e2e8e29a421b21c99ab51b5d631c4e4c82ea36 (diff)
downloaddocutils-3e160024a560b8e31bf94db73d2cf8f93c0122f2.tar.gz
py3: Replace 'ur' prefix
While the 'u' prefix was backported to Python 3.3 or thereabouts, 'ur' remains invalid in Python 3. Just escape all backslashes and use plain old 'u'. Based on patch by Stephen Finucane <stephen@that.guru> git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@8366 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/utils/math')
-rw-r--r--docutils/utils/math/latex2mathml.py28
-rw-r--r--docutils/utils/math/tex2mathml_extern.py3
2 files changed, 15 insertions, 16 deletions
diff --git a/docutils/utils/math/latex2mathml.py b/docutils/utils/math/latex2mathml.py
index fa6013d4c..f037a8e56 100644
--- a/docutils/utils/math/latex2mathml.py
+++ b/docutils/utils/math/latex2mathml.py
@@ -6,12 +6,12 @@
# Based on rst2mathml.py from the latex_math sandbox project
# © 2005 Jens Jørgen Mortensen
# :License: Released under the terms of the `2-Clause BSD license`_, in short:
-#
+#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
# This file is offered as-is, without any warranty.
-#
+#
# .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause
@@ -412,7 +412,7 @@ def parse_latex_math(string, inline=True):
node = entry
skip = 2
else:
- raise SyntaxError(ur'Syntax error: "%s%s"' % (c, c2))
+ raise SyntaxError(u'Syntax error: "%s%s"' % (c, c2))
elif c.isalpha():
node = node.append(mi(c))
elif c.isdigit():
@@ -453,7 +453,7 @@ def parse_latex_math(string, inline=True):
node.close().append(entry)
node = entry
else:
- raise SyntaxError(ur'Illegal character: "%s"' % c)
+ raise SyntaxError(u'Illegal character: "%s"' % c)
string = string[skip:]
return tree
@@ -474,15 +474,15 @@ def handle_keyword(name, node, string):
node = entry
elif name == 'end':
if not string.startswith('{matrix}'):
- raise SyntaxError(ur'Expected "\end{matrix}"!')
+ raise SyntaxError(u'Expected "\\end{matrix}"!')
skip += 8
node = node.close().close().close()
elif name in ('text', 'mathrm'):
if string[0] != '{':
- raise SyntaxError(ur'Expected "\text{...}"!')
+ raise SyntaxError(u'Expected "\\text{...}"!')
i = string.find('}')
if i == -1:
- raise SyntaxError(ur'Expected "\text{...}"!')
+ raise SyntaxError(u'Expected "\\text{...}"!')
node = node.append(mtext(string[1:i]))
skip += i + 1
elif name == 'sqrt':
@@ -520,7 +520,7 @@ def handle_keyword(name, node, string):
if string.startswith(operator):
break
else:
- raise SyntaxError(ur'Expected something to negate: "\not ..."!')
+ raise SyntaxError(u'Expected something to negate: "\\not ..."!')
node = node.append(mo(negatables[operator]))
skip += len(operator)
elif name == 'mathbf':
@@ -529,12 +529,12 @@ def handle_keyword(name, node, string):
node = style
elif name == 'mathbb':
if string[0] != '{' or not string[1].isupper() or string[2] != '}':
- raise SyntaxError(ur'Expected something like "\mathbb{A}"!')
+ raise SyntaxError(u'Expected something like "\\mathbb{A}"!')
node = node.append(mi(mathbb[string[1]]))
skip += 3
elif name in ('mathscr', 'mathcal'):
if string[0] != '{' or string[2] != '}':
- raise SyntaxError(ur'Expected something like "\mathscr{A}"!')
+ raise SyntaxError(u'Expected something like "\\mathscr{A}"!')
node = node.append(mi(mathscr[string[1]]))
skip += 3
elif name == 'colon': # "normal" colon, not binary operator
@@ -559,12 +559,10 @@ def handle_keyword(name, node, string):
return node, skip
def tex2mathml(tex_math, inline=True):
- """Return string with MathML code corresponding to `tex_math`.
-
+ """Return string with MathML code corresponding to `tex_math`.
+
`inline`=True is for inline math and `inline`=False for displayed math.
"""
-
+
mathml_tree = parse_latex_math(tex_math, inline=inline)
return ''.join(mathml_tree.xml())
-
-
diff --git a/docutils/utils/math/tex2mathml_extern.py b/docutils/utils/math/tex2mathml_extern.py
index a51221e1f..ce2d14173 100644
--- a/docutils/utils/math/tex2mathml_extern.py
+++ b/docutils/utils/math/tex2mathml_extern.py
@@ -141,7 +141,8 @@ def blahtexml(math_code, inline=True, reporter=None):
# self-test
if __name__ == "__main__":
- example = ur'\frac{\partial \sin^2(\alpha)}{\partial \vec r} \varpi \, \text{Grüße}'
+ example = (u'\\frac{\\partial \\sin^2(\\alpha)}{\\partial \\vec r}'
+ u'\\varpi \\, \\text{Grüße}')
# print(latexml(example).encode('utf8'))
# print(ttm(example))
print(blahtexml(example).encode('utf8'))