Skip to content

Commit 929f957

Browse files
authored
Merge pull request #326 from desmosinc/sclower/more-fractions-and-question-mark
Mathspeak tweaks
2 parents df2216c + 1e1dc34 commit 929f957

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/commands/math/basicSymbols.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ if (!CharCmds['\\']) CharCmds['\\'] = LatexCmds.backslash;
877877

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

880+
LatexCmds['?'] = bindVanillaSymbol('?', '?', 'question mark');
881+
880882
LatexCmds['□'] = LatexCmds.square = bindVanillaSymbol(
881883
'\\square ',
882884
'\u25A1',
@@ -1447,7 +1449,7 @@ LatexCmds['÷'] =
14471449
LatexCmds.div =
14481450
LatexCmds.divide =
14491451
LatexCmds.divides =
1450-
bindBinaryOperator('\\div ', '÷', '[/]', 'over');
1452+
bindBinaryOperator('\\div ', '÷', '[/]', 'divided by');
14511453

14521454
class Sim extends BinaryOperator {
14531455
constructor() {

src/commands/math/commands.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ var Fraction =
884884
var numText = getCtrlSeqsFromBlock(this.getEnd(L));
885885
var denText = getCtrlSeqsFromBlock(this.getEnd(R));
886886

887-
// Shorten mathspeak value for whole number fractions whose denominator is less than 10.
887+
// Shorten mathspeak value for whole number fractions whose denominator has a special spoken form.
888888
if (
889889
(!opts || !opts.ignoreShorthand) &&
890890
intRgx.test(numText) &&
@@ -897,7 +897,7 @@ var Fraction =
897897
} else if (denText === '3') {
898898
newDenSpeech = isSingular ? 'third' : 'thirds';
899899
} else if (denText === '4') {
900-
newDenSpeech = isSingular ? 'quarter' : 'quarters';
900+
newDenSpeech = isSingular ? 'fourth' : 'fourths';
901901
} else if (denText === '5') {
902902
newDenSpeech = isSingular ? 'fifth' : 'fifths';
903903
} else if (denText === '6') {
@@ -908,6 +908,14 @@ var Fraction =
908908
newDenSpeech = isSingular ? 'eighth' : 'eighths';
909909
} else if (denText === '9') {
910910
newDenSpeech = isSingular ? 'ninth' : 'ninths';
911+
} else if (denText === '10') {
912+
newDenSpeech = isSingular ? 'tenth' : 'tenths';
913+
} else if (denText === '11') {
914+
newDenSpeech = isSingular ? 'eleventh' : 'elevenths';
915+
} else if (denText === '12') {
916+
newDenSpeech = isSingular ? 'twelfth' : 'twelfths';
917+
} else if (denText === '100') {
918+
newDenSpeech = isSingular ? 'hundredth' : 'hundredths';
911919
}
912920
if (newDenSpeech !== '') {
913921
var output = '';

test/unit/typing.test.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ suite('typing with auto-replaces', function () {
148148

149149
suite('MathspeakShorthand', function () {
150150
test('fractions', function () {
151-
// Testing singular numeric fractions from 1/2 to 1/10
151+
// Testing singular numeric fractions from 1/2 to 1/112, and 1/100
152152
mq.latex('\\frac{1}{2}');
153153
assertMathspeak('1 half');
154154
mq.latex('\\frac{1}{3}');
155155
assertMathspeak('1 third');
156156
mq.latex('\\frac{1}{4}');
157-
assertMathspeak('1 quarter');
157+
assertMathspeak('1 fourth');
158158
mq.latex('\\frac{1}{5}');
159159
assertMathspeak('1 fifth');
160160
mq.latex('\\frac{1}{6}');
@@ -166,15 +166,21 @@ suite('typing with auto-replaces', function () {
166166
mq.latex('\\frac{1}{9}');
167167
assertMathspeak('1 ninth');
168168
mq.latex('\\frac{1}{10}');
169-
assertMathspeak('StartFraction, 1 Over 10, EndFraction');
170-
171-
// Testing plural numeric fractions from 31/2 to 31/10
169+
assertMathspeak('1 tenth');
170+
mq.latex('\\frac{1}{11}');
171+
assertMathspeak('1 eleventh');
172+
mq.latex('\\frac{1}{12}');
173+
assertMathspeak('1 twelfth');
174+
mq.latex('\\frac{1}{100}');
175+
assertMathspeak('1 hundredth');
176+
177+
// Testing plural numeric fractions from 31/2 to 31/12, and 31/100
172178
mq.latex('\\frac{31}{2}');
173179
assertMathspeak('31 halves');
174180
mq.latex('\\frac{31}{3}');
175181
assertMathspeak('31 thirds');
176182
mq.latex('\\frac{31}{4}');
177-
assertMathspeak('31 quarters');
183+
assertMathspeak('31 fourths');
178184
mq.latex('\\frac{31}{5}');
179185
assertMathspeak('31 fifths');
180186
mq.latex('\\frac{31}{6}');
@@ -186,15 +192,21 @@ suite('typing with auto-replaces', function () {
186192
mq.latex('\\frac{31}{9}');
187193
assertMathspeak('31 ninths');
188194
mq.latex('\\frac{31}{10}');
189-
assertMathspeak('StartFraction, 31 Over 10, EndFraction');
195+
assertMathspeak('31 tenths');
196+
mq.latex('\\frac{31}{11}');
197+
assertMathspeak('31 elevenths');
198+
mq.latex('\\frac{31}{12}');
199+
assertMathspeak('31 twelfths');
200+
mq.latex('\\frac{31}{100}');
201+
assertMathspeak('31 hundredths');
190202

191203
// Fractions with negative numerators should be shortened
192204
mq.latex('\\frac{-1}{2}');
193205
assertMathspeak('negative 1 half');
194206
mq.latex('\\frac{-3}{2}');
195207
assertMathspeak('negative 3 halves');
196208
mq.latex('-\\frac{3}{4}');
197-
assertMathspeak('negative 3 quarters');
209+
assertMathspeak('negative 3 fourths');
198210

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

0 commit comments

Comments
 (0)