Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ def test_free_response_question_with_maths(self):
<math display="block">
<semantics>
<mrow>
<msubsup><mo>∑</mo><mi>n</mi><mi>s</mi></msubsup>
<munderover><mo>∑</mo><mi>n</mi><mi>s</mi></munderover>
<mi>x</mi>
<msup><mi>a</mi><mi>n</mi></msup>
</mrow>
Expand Down
60 changes: 58 additions & 2 deletions contentcuration/contentcuration/tests/utils/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def test_mixed_inline_and_block(self):
"</p>\n"
"<p>And this is block math:</p>\n"
'<math display="block">'
"<semantics><mrow><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow>"
"<mi>n</mi></mrow></msubsup><msub><mi>x</mi><mi>i</mi></msub><mo>=</mo><mi>y</mi></mrow>"
"<semantics><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow>"
"<mi>n</mi></mrow></munderover><msub><mi>x</mi><mi>i</mi></msub><mo>=</mo><mi>y</mi></mrow>"
'<annotation encoding="application/x-tex">\sum_{i=1}^{n} x_i = y</annotation></semantics>' # noqa W605
"</math>"
"<p>Back to text with more inline: "
Expand All @@ -132,6 +132,62 @@ def test_mixed_inline_and_block(self):

self._assert_conversion(markdown_text, expected)

def test_block_sum_uses_munderover(self):
"""Block-mode \\sum with sub+superscript must use <munderover>, not <msubsup>"""

markdown_text = "$$\\sum_{i=1}^{n} x_i$$"
expected = (
'<math display="block">'
"<semantics><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow>"
"<mi>n</mi></mrow></munderover><msub><mi>x</mi><mi>i</mi></msub></mrow>"
'<annotation encoding="application/x-tex">\\sum_{i=1}^{n} x_i</annotation></semantics>'
"</math>"
)

self._assert_conversion(markdown_text, expected)

def test_inline_sum_uses_msubsup(self):
"""Inline-mode \\sum with sub+superscript must use <msubsup>, not <munderover>"""

markdown_text = "The sum $$\\sum_{i=1}^{n} x_i$$ is finite."
expected = (
"<p>The sum "
'<math display="inline"><semantics><mrow><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow>'
"<mi>n</mi></mrow></msubsup><msub><mi>x</mi><mi>i</mi></msub></mrow>"
'<annotation encoding="application/x-tex">\\sum_{i=1}^{n} x_i</annotation></semantics></math>'
" is finite.</p>\n"
)

self._assert_conversion(markdown_text, expected)

def test_block_prod_uses_munderover(self):
"""Block-mode \\prod with sub+superscript must use <munderover>"""

markdown_text = "$$\\prod_{k=0}^{n} a_k$$"
expected = (
'<math display="block">'
"<semantics><mrow><munderover><mo>∏</mo><mrow><mi>k</mi><mo>=</mo><mn>0</mn></mrow><mrow>"
"<mi>n</mi></mrow></munderover><msub><mi>a</mi><mi>k</mi></msub></mrow>"
'<annotation encoding="application/x-tex">\\prod_{k=0}^{n} a_k</annotation></semantics>'
"</math>"
)

self._assert_conversion(markdown_text, expected)

def test_block_int_unaffected(self):
"""Block-mode \\int should still use <msubsup> (not affected by munderover fix)"""

markdown_text = "$$\\int_{a}^{b} f(x) dx$$"
expected = (
'<math display="block">'
"<semantics><mrow><msubsup><mo>∫</mo><mrow><mi>a</mi></mrow><mrow>"
'<mi>b</mi></mrow></msubsup><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>d</mi><mi>x</mi></mrow>'
'<annotation encoding="application/x-tex">\\int_{a}^{b} f(x) dx</annotation></semantics>'
"</math>"
)

self._assert_conversion(markdown_text, expected)

def test_no_math_content(self):
"""Test that regular markdown without math still works"""

Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ packaging>=21.0
pycountry
langcodes==3.5.1
pydantic==2.12.5
latex2mathml==3.78.0
latex2mathml==3.78.1
markdown-it-py==4.0.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ kombu==5.6.1
# via celery
langcodes==3.5.1
# via -r requirements.in
latex2mathml==3.78.0
latex2mathml==3.78.1
# via -r requirements.in
le-utils==0.2.12
# via -r requirements.in
Expand Down
Loading