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
4 changes: 3 additions & 1 deletion src/commands/math/basicSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ if (!CharCmds['\\']) CharCmds['\\'] = LatexCmds.backslash;

LatexCmds.$ = bindVanillaSymbol('\\$', '$', 'dollar');

LatexCmds['?'] = bindVanillaSymbol('?', '?', 'question mark');

LatexCmds['□'] = LatexCmds.square = bindVanillaSymbol(
'\\square ',
'\u25A1',
Expand Down Expand Up @@ -1447,7 +1449,7 @@ LatexCmds['÷'] =
LatexCmds.div =
LatexCmds.divide =
LatexCmds.divides =
bindBinaryOperator('\\div ', '÷', '[/]', 'over');
bindBinaryOperator('\\div ', '÷', '[/]', 'divided by');

class Sim extends BinaryOperator {
constructor() {
Expand Down
12 changes: 10 additions & 2 deletions src/commands/math/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ var Fraction =
var numText = getCtrlSeqsFromBlock(this.getEnd(L));
var denText = getCtrlSeqsFromBlock(this.getEnd(R));

// Shorten mathspeak value for whole number fractions whose denominator is less than 10.
// Shorten mathspeak value for whole number fractions whose denominator has a special spoken form.
if (
(!opts || !opts.ignoreShorthand) &&
intRgx.test(numText) &&
Expand All @@ -897,7 +897,7 @@ var Fraction =
} else if (denText === '3') {
newDenSpeech = isSingular ? 'third' : 'thirds';
} else if (denText === '4') {
newDenSpeech = isSingular ? 'quarter' : 'quarters';
newDenSpeech = isSingular ? 'fourth' : 'fourths';
} else if (denText === '5') {
newDenSpeech = isSingular ? 'fifth' : 'fifths';
} else if (denText === '6') {
Expand All @@ -908,6 +908,14 @@ var Fraction =
newDenSpeech = isSingular ? 'eighth' : 'eighths';
} else if (denText === '9') {
newDenSpeech = isSingular ? 'ninth' : 'ninths';
} else if (denText === '10') {
newDenSpeech = isSingular ? 'tenth' : 'tenths';
} else if (denText === '11') {
newDenSpeech = isSingular ? 'eleventh' : 'elevenths';
} else if (denText === '12') {
newDenSpeech = isSingular ? 'twelfth' : 'twelfths';
} else if (denText === '100') {
newDenSpeech = isSingular ? 'hundredth' : 'hundredths';
}
if (newDenSpeech !== '') {
var output = '';
Expand Down
28 changes: 20 additions & 8 deletions test/unit/typing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ suite('typing with auto-replaces', function () {

suite('MathspeakShorthand', function () {
test('fractions', function () {
// Testing singular numeric fractions from 1/2 to 1/10
// Testing singular numeric fractions from 1/2 to 1/112, and 1/100
mq.latex('\\frac{1}{2}');
assertMathspeak('1 half');
mq.latex('\\frac{1}{3}');
assertMathspeak('1 third');
mq.latex('\\frac{1}{4}');
assertMathspeak('1 quarter');
assertMathspeak('1 fourth');
mq.latex('\\frac{1}{5}');
assertMathspeak('1 fifth');
mq.latex('\\frac{1}{6}');
Expand All @@ -166,15 +166,21 @@ suite('typing with auto-replaces', function () {
mq.latex('\\frac{1}{9}');
assertMathspeak('1 ninth');
mq.latex('\\frac{1}{10}');
assertMathspeak('StartFraction, 1 Over 10, EndFraction');

// Testing plural numeric fractions from 31/2 to 31/10
assertMathspeak('1 tenth');
mq.latex('\\frac{1}{11}');
assertMathspeak('1 eleventh');
mq.latex('\\frac{1}{12}');
assertMathspeak('1 twelfth');
mq.latex('\\frac{1}{100}');
assertMathspeak('1 hundredth');

// Testing plural numeric fractions from 31/2 to 31/12, and 31/100
mq.latex('\\frac{31}{2}');
assertMathspeak('31 halves');
mq.latex('\\frac{31}{3}');
assertMathspeak('31 thirds');
mq.latex('\\frac{31}{4}');
assertMathspeak('31 quarters');
assertMathspeak('31 fourths');
mq.latex('\\frac{31}{5}');
assertMathspeak('31 fifths');
mq.latex('\\frac{31}{6}');
Expand All @@ -186,15 +192,21 @@ suite('typing with auto-replaces', function () {
mq.latex('\\frac{31}{9}');
assertMathspeak('31 ninths');
mq.latex('\\frac{31}{10}');
assertMathspeak('StartFraction, 31 Over 10, EndFraction');
assertMathspeak('31 tenths');
mq.latex('\\frac{31}{11}');
assertMathspeak('31 elevenths');
mq.latex('\\frac{31}{12}');
assertMathspeak('31 twelfths');
mq.latex('\\frac{31}{100}');
assertMathspeak('31 hundredths');

// Fractions with negative numerators should be shortened
mq.latex('\\frac{-1}{2}');
assertMathspeak('negative 1 half');
mq.latex('\\frac{-3}{2}');
assertMathspeak('negative 3 halves');
mq.latex('-\\frac{3}{4}');
assertMathspeak('negative 3 quarters');
assertMathspeak('negative 3 fourths');

// Fractions with negative denominators should not be shortened
mq.latex('\\frac{1}{-2}');
Expand Down