diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index aec1b0d02d..73c5ff91dc 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -64,6 +64,7 @@ class RSTMarkup(Markup): def escape_rst_chars(self, text): text = text.replace('*', '\\*') + text = text.replace('^', '\\^') return text def inline_math(self, text): @@ -73,6 +74,8 @@ class RSTMarkup(Markup): while start_pos >= 0 and end_pos >= 0: original = text[start_pos:end_pos+2] formula = original[2:-2] + formula = formula.replace('\\*', '*') + formula = formula.replace('\\^', '^') replacement = ":math:`" + formula.replace('\n', ' ').strip() + "`" text = text.replace(original, replacement) @@ -300,6 +303,9 @@ class RSTFormatting(Formatting): start = "" body = parts[0] + body = body.replace('\\*', '*') + body = body.replace('\\^', '^') + if len(start) > 0: text += start + "\n" text += "\n.. math::\n\n" diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index 9403d419a8..a4b059fbf3 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -81,6 +81,10 @@ class TestMarkup(unittest.TestCase): s = self.markup.convert("[*bold] and {italic*}") self.assertEqual("**\*bold** and *italic\**", s) + def test_escape_hat_character(self): + s = self.markup.convert("x^2") + self.assertEqual("x\^2", s) + def test_paragraph_with_italic(self): self.assertEqual("A sentence with a *italic* word", self.markup.convert("A sentence with a {italic} word")) @@ -411,6 +415,16 @@ class TestMathMarkup(unittest.TestCase): " \\frac{s_{ij} r_{ij} }{2} \\right)\n" " \\exp \\left( - s_{ij} r_{ij} \\right) \\end{equation}\n\n", s) + def test_detect_latex_equation_with_mult(self): + s = self.txt2rst.convert("\\begin\\{equation\\} a = b * c \\end\\{equation\\}\n") + self.assertEqual("\n.. math::\n\n" + " \\begin{equation} a = b * c \\end{equation}\n\n", s) + + def test_detect_latex_equation_with_pow(self): + s = self.txt2rst.convert("\\begin\\{equation\\} a = b^c \\end\\{equation\\}\n") + self.assertEqual("\n.. math::\n\n" + " \\begin{equation} a = b^c \\end{equation}\n\n", s) + def test_detect_inline_latex_equation(self): s = self.txt2rst.convert("Masses: \\begin\\{equation\\} M' = M + m \\end\\{equation\\}\n" "\\begin\\{equation\\} m' = \\frac \\{M\\, m \\} \\{M'\\} \\end\\{equation\\}\n") @@ -426,6 +440,9 @@ class TestMathMarkup(unittest.TestCase): def test_detect_inline_math(self): self.assertEqual(":math:`x^2`", self.markup.convert("\\( x^2 \\)")) + def test_detect_inline_math_mult(self): + self.assertEqual(":math:`x * 2`", self.markup.convert("\\( x * 2 \\)")) + def test_detect_multiline_inline_math(self): line = "\\(\\sqrt \\{ \\frac \\{2\, k_B \\mathtt\\{Tcom\\}\, m'\\}\n" \ "\\{\\mathrm dt\\, \\mathtt\\{damp\\_com\\} \\}\n" \