SinclaM / desmos-unlocked

Browser extension for better user control of the Desmos graphing calculator configuration
MIT License
9 stars 1 forks source link

Support shortucts for more LaTeX commands #2

Closed SinclaM closed 2 years ago

SinclaM commented 2 years ago

The extension uses the autoCommands MathQuill configuration option, which in theory can support any LaTeX command. However, the Desmos graphing calculator heavily limits the amount of recognized symbols. So, although MathQuill can handle shortcuts like nabla, partial, and aleph without issue, they are not recognized by the calculator.

If possible, the extension should try to unlock the rest of the autoCommands and provide a way to enable them through the UI.

SinclaM commented 2 years ago

It looks like Desmos restricts the amount of recognized symbols while initializing LatexCmds in the minified calculator_desktop-[hash].js. I'd guess this is to discourage users from enabling too many shortcuts in order to prevent conflicts. For example, even among the few autoCommands supported in the calculator, psi conflicts with epsilon, upsilon, and Upsilon.

A possible workaround might involve modifying calculator_desktop-[hash].js before allowing it to load. But that is likely to conflict with DesModder, which does its own blocking and modifications.

SinclaM commented 2 years ago

Locally overriding a target function in calculator_desktop-[hash].js with the corresponding function from build/mathquill.js, from the MathQuill source code, and replacing instances of mq- with dcg-mq- is confirmed to add (probably?) all LaTeX symbols to the calculator. For example:

image

Since this modifies the internals of the calculator, it is a somewhat fragile approach, and will almost certainly conflict with DesModder if done naively.

SinclaM commented 2 years ago

A possible way to make the override during any point in runtime:

  1. Run the modified calculator_desktop-[hash].js script, having changed the target function but otherwise leaving all the modules the same
  2. Run the script that initializes the calculator. Taken verbatim from the page HTML:
    require(['toplevel/calculator_desktop', 'testbridge', 'jquery'], function (calcPromise, TestBridge, $) {
    calcPromise.then(function(calc) {
    $('.dcg-loading-div-container').hide();
        window.Calc = calc;
        TestBridge.ready();
    });
    });
  3. The last step will create another instance of the graphing calculator, but with the extended version of MathQuill. We need to remove the original instance of the calculator to make the page usable again, so all that's left is to remove the '.dcg-wrapper' element from '.graph-container'. It's actually probably more sensible to do this removal before the previous step.

A couple thoughts:

SinclaM commented 2 years ago

Success! e4291734d55fa17b6e4f524669b5a0b5f7011427 gives a very crude implementation of extending MathQuill, but it works. It employs the same module override method used by DesModder to override the mathquill_src module. The code is an absolute mess, and DesModder compatibility hasn't been tested yet, but this is a good step forward.

SinclaM commented 2 years ago

6 implements the MathQuill extension for all browsers, with DesModder compatibility. All that's left is to allow for user configuration of this behavior through the popup UI.