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
27 changes: 16 additions & 11 deletions src/commands/math/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,22 +966,27 @@ var Fraction =
// Handle the case of an integer followed by a simplified fraction such as 1\frac{1}{2}.
// Such combinations should be spoken aloud as "1 and 1 half."
// Start at the left sibling of the fraction and continue leftward until something other than a digit or whitespace is found.
var precededByInteger = false;
let sawDigit = false;

let sibling;
// Scan until you see something other than a digit or space
for (
var sibling: NodeRef | undefined = this[L];
sibling && sibling[L] !== undefined;
sibling = this[L];
sibling &&
sibling.ctrlSeq &&
(sibling.ctrlSeq === '\\ ' || intRgx.test(sibling.ctrlSeq ?? ''));
sibling = sibling[L]
) {
// Ignore whitespace
if (sibling.ctrlSeq === '\\ ') {
continue;
} else if (intRgx.test(sibling.ctrlSeq || '')) {
precededByInteger = true;
} else {
precededByInteger = false;
break;
if (intRgx.test(sibling.ctrlSeq)) {
sawDigit = true;
}
}
const lastNodeSeen = sibling;

// `precededByInteger` is true if everything we saw while scanning is digits and spaces, and
// we saw at least one digit.
const precededByInteger =
sawDigit && !(lastNodeSeen && lastNodeSeen.ctrlSeq === '.');
if (precededByInteger) {
output += 'and ';
}
Expand Down
30 changes: 30 additions & 0 deletions test/unit/aria.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,36 @@ suite('aria', function () {
assertAriaEqual('left parenthesis');
});

test('testing mathspeak for mixed fractions', function () {
const mq = mathField;
mq.latex('1+2\\frac{3}{4}');
mq.select();
assert.equal(mq.mathspeak().trim(), '1 plus 2 and 3 fourths');

mq.latex('1.2\\frac{3}{4}');
mq.select();
assert.equal(mq.mathspeak().trim(), '1.2 3 fourths');

mq.latex('a\\frac{3}{4}');
mq.select();
assert.equal(mq.mathspeak().trim(), '"a" 3 fourths');

mq.latex('a1\\frac{3}{4}');
mq.select();
assert.equal(mq.mathspeak().trim(), '"a" 1 and 3 fourths');

mq.latex('1\\left(x\\right)\\frac{3}{4}');
mq.select();
assert.equal(
mq.mathspeak().trim(),
'1 left parenthesis, "x" , right parenthesis 3 fourths'
);

mq.latex('1+2\\ \\ \\frac{3}{4}');
mq.select();
assert.equal(mq.mathspeak().trim(), '1 plus 2 and 3 fourths');
});

test('testing beginning and end alerts', function () {
mathField.typedText('sqrt(x)');
mathField.keystroke('Home');
Expand Down
Loading