Merge pull request #681 from desmosinc/add-multiplication-symbol-cherrypicked

Add option to use multiplication symbol instead of cdot
diff --git a/src/commands/math.js b/src/commands/math.js
index c3d0978..a8d8d6f 100644
--- a/src/commands/math.js
+++ b/src/commands/math.js
@@ -395,20 +395,24 @@
     while (pageX < node.jQ.offset().left) node = node[L];
     return node.seek(pageX, cursor);
   };
-  _.chToCmd = function(ch) {
+  _.chToCmd = function(ch, options) {
     var cons;
     // exclude f because it gets a dedicated command with more spacing
     if (ch.match(/^[a-eg-zA-Z]$/))
       return Letter(ch);
     else if (/^\d$/.test(ch))
       return Digit(ch);
+    else if (options && options.typingSlashWritesDivisionSymbol && ch === '/')
+      return LatexCmds['÷'](ch);
+    else if (options && options.typingAsteriskWritesTimesSymbol && ch === '*')
+      return LatexCmds['×'](ch);
     else if (cons = CharCmds[ch] || LatexCmds[ch])
       return cons(ch);
     else
       return VanillaSymbol(ch);
   };
   _.write = function(cursor, ch) {
-    var cmd = this.chToCmd(ch);
+    var cmd = this.chToCmd(ch, cursor.options);
     if (cursor.selection) cmd.replaces(cursor.replaceSelection());
     cmd.createLeftOf(cursor.show());
   };
diff --git a/src/commands/math/commands.js b/src/commands/math/commands.js
index 9fa95e1..d059765 100644
--- a/src/commands/math/commands.js
+++ b/src/commands/math/commands.js
@@ -193,7 +193,7 @@
     this.ends[L].write = function(cursor, ch) {
       if (cursor.options.autoSubscriptNumerals && this === this.parent.sub) {
         if (ch === '_') return;
-        var cmd = this.chToCmd(ch);
+        var cmd = this.chToCmd(ch, cursor.options);
         if (cmd instanceof Symbol) cursor.deleteSelection();
         else cursor.clearSelection().insRightOf(this.parent);
         return cmd.createLeftOf(cursor.show());
diff --git a/test/unit/typing.test.js b/test/unit/typing.test.js
index c3c89f1..578af1f 100644
--- a/test/unit/typing.test.js
+++ b/test/unit/typing.test.js
@@ -1065,4 +1065,25 @@
       assert.equal(mq.keystroke('Shift-Left').typedText('^').latex(), '^2');
     });
   });
+
+  suite('alternative symbols when typing / and *', function() {
+    test('typingSlashWritesDivisionSymbol', function() {
+      mq.typedText('/');
+      assertLatex('\\frac{ }{ }');
+
+      mq.config({ typingSlashWritesDivisionSymbol: true });
+
+      mq.keystroke('Backspace').typedText('/');
+      assertLatex('\\div');
+    });
+    test('typingAsteriskWritesTimesSymbol', function() {
+      mq.typedText('*');
+      assertLatex('\\cdot');
+
+      mq.config({ typingAsteriskWritesTimesSymbol: true });
+
+      mq.keystroke('Backspace').typedText('*');
+      assertLatex('\\times');
+    });
+  });
 });