Skip to content

Commit 8b5712d

Browse files
committed
Make function names, "...", and "∞" be considered mis if in mtext. Same check as for mos.
1 parent c6f67a3 commit 8b5712d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/canonicalize.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,19 @@ impl CanonicalizeContext {
888888
CanonicalizeContext::make_roman_numeral(mathml);
889889
return Some(mathml);
890890
}
891+
// common bug: trig functions, lim, etc., should be mi
892+
if ["…", "⋯", "∞"].contains(&text) ||
893+
crate::definitions::SPEECH_DEFINITIONS.with(|definitions|
894+
if let Some(hashset) = definitions.borrow().get_hashset("FunctionNames") {
895+
hashset.contains(text)
896+
} else {
897+
false
898+
}
899+
) {
900+
set_mathml_name(mathml, "mi");
901+
return Some(mathml);
902+
}
903+
891904
// allow non-breaking whitespace to stay -- needed by braille
892905
if IS_WHITESPACE.is_match(text) {
893906
// normalize to just a single non-breaking space
@@ -5268,6 +5281,39 @@ mod canonicalize_tests {
52685281
</math>";
52695282
assert!(are_strs_canonically_equal(test_str, target_str, &[]));
52705283
}
5284+
5285+
#[test]
5286+
fn trig_mtext() {
5287+
let test_str = "<math><mtext>sin</mtext><mi>x</mi>
5288+
<mo>+</mo><mtext>cos</mtext><mi>y</mi>
5289+
<mo>+</mo><munder><mtext>lim</mtext><mi>D</mi></munder><mi>y</mi>
5290+
</math>";
5291+
let target_str = "<math>
5292+
<mrow data-changed='added'>
5293+
<mrow data-changed='added'>
5294+
<mi>sin</mi>
5295+
<mo data-changed='added'>&#x2061;</mo>
5296+
<mi>x</mi>
5297+
</mrow>
5298+
<mo>+</mo>
5299+
<mrow data-changed='added'>
5300+
<mi>cos</mi>
5301+
<mo data-changed='added'>&#x2061;</mo>
5302+
<mi>y</mi>
5303+
</mrow>
5304+
<mo>+</mo>
5305+
<mrow data-changed='added'>
5306+
<munder>
5307+
<mi>lim</mi>
5308+
<mi>D</mi>
5309+
</munder>
5310+
<mo data-changed='added'>&#x2061;</mo>
5311+
<mi>y</mi>
5312+
</mrow>
5313+
</mrow>
5314+
</math>";
5315+
assert!(are_strs_canonically_equal(test_str, target_str, &[]));
5316+
}
52715317

52725318
#[test]
52735319
fn trig_negative_args() {

0 commit comments

Comments
 (0)