Make AsciiMath work with Vite
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Issue Summary
Vite uses strict mode, so the usage of arguments.callee fails. Besides removing arguments.callee from the relevant JS files, Vite compatibility evidently requires slight changes to an additional AsciiMath JS file.
Steps to Reproduce:
See https://excalidraw-mcjzus0ve-excalidraw.vercel.app/ (source commit https://github.com/excalidraw/excalidraw/pull/6037/commits/27a8cda8fdf7e7bc4e0d44f27bfa11cee21fc1cd) for an example of https://github.com/mathjax/MathJax-src/pull/854 in use. In this deployment:
- Select "Math" in the toolbar.
- Type
\(\alpha\)and press "Escape". - Rendering fails with the browser console error "ReferenceError: MathJax is not defined", traced back to an AsciiMath JS file.
Technical Details:
- MathJax Version: 3.2.2/4.0.0-beta.3
- Client OS: Linux
- Browser: Multiple
I am configuring and loading MathJax via loadMathJax() in src/element/subtypes/mathjax/implementation.tsx.
Supporting Information:
- Example of
arguments.calleefailing: https://excalidraw-k7bnvq58q-excalidraw.vercel.app/ (source commit https://github.com/excalidraw/excalidraw/pull/6037/commits/dd5053149a20acfa2817b5ef943897d4d08ea3a4). - Browser console error for
arguments.callee: "Uncaught (in promise) TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them". - Omitting the change to
js/input/asciimath/mathjax2/input/AsciiMath.jsin https://github.com/excalidraw/excalidraw/pull/6037/commits/27a8cda8fdf7e7bc4e0d44f27bfa11cee21fc1cd results in the browser console error "Uncaught (in promise) ReferenceError: global is not defined". - I have been using an extended version of https://github.com/mathjax/MathJax-src/pull/854 with
patch-packagein production on https://math.preview.excalidraw.com/ without issue. See excalidraw/excalidraw#7063 for the patch as I would submit it against the MathJax-srcdevelopbranch.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the relevant AsciiMath JavaScript files, especially js/input/asciimath/mathjax2/input/AsciiMath.js and the legacy shim.js, then review the loadMathJax() entry point in src/element/subtypes/mathjax/implementation.tsx and the referenced patch. Reproduce the Vite deployment case and verify that Math rendering completes without the strict-mode or global errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, vite
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100