Implement math formula insertion tool using KaTeX#3
Conversation
- Enable the mathsTool button (remove disabled class) - Add KaTeX CSS/JS via CDN for LaTeX formula rendering - Add modal dialog with live preview for entering LaTeX formulas - Add tool=4 handler for mathsTool in tool switch - Add case 4 in addElement() to show modal on canvas click - Insert rendered formula as draggable element on the whiteboard - Support Enter key to insert and cancel to reset state - Update welcome modal text to mention math formulas Agent-Logs-Url: https://github.com/ionutfinta/WhiteboardJS/sessions/eaf4b9ab-bbf0-4902-93a5-f99bada3a018 Co-authored-by: ionutfinta <56076718+ionutfinta@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR implements end-to-end math formula insertion on the whiteboard using KaTeX, wiring up the previously disabled √ toolbar tool.
Changes:
- Adds KaTeX CSS/JS via CDN and introduces a new “Insert Math Formula” Bootstrap modal with live preview.
- Enables the
mathsToolbutton in the toolbar and wires it to tool ID4. - Implements formula insertion in
jquery.whiteboard.js, placing rendered KaTeX output at the click/tap location inside a draggable whiteboard element.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/index.html |
Enables the math tool button, adds KaTeX CDN assets, and adds the math insertion modal UI. |
src/jquery.whiteboard.js |
Registers/selects the math tool and implements modal open, live preview, and insertion of a draggable rendered formula element. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <label class="btn btn-dark"> | ||
| <input type="radio" name="toolRadio" id="mathsTool" autocomplete="off"><i class="las la-square-root-alt"></i> | ||
| </label> |
There was a problem hiding this comment.
The repo has two entrypoints: src/index.html (served by src/app.js) and the root index.html (used for the GitHub Pages demo). This PR enables mathsTool only in src/index.html; the root index.html still has the maths button disabled and doesn’t load KaTeX, so the hosted demo won’t show this feature. Consider updating the root index.html as well (or consolidating to avoid duplicated UI).
|
|
||
| //-- Math formula modal: reset tool on cancel | ||
| $("#mathModal").on("hidden.bs.modal", function() { | ||
| mathInsertCoords = null; |
There was a problem hiding this comment.
The comment says “reset tool on cancel”, but the handler only clears mathInsertCoords and leaves the current tool as mathsTool. Either update the comment to match the intended behavior, or actually reset the active tool (e.g., trigger #mouseTool on modal close / cancel) so users don’t get stuck repeatedly reopening the modal on the next click.
| mathInsertCoords = null; | |
| mathInsertCoords = null; | |
| if (tool === 4) { | |
| $("#mouseTool").trigger("click"); | |
| } |
|
@copilot apply changes based on the comments in this thread |
…t tool on modal cancel - Enable mathsTool button in root index.html (GitHub Pages demo) - Add KaTeX CSS/JS CDN links to root index.html - Add math formula modal to root index.html - Add math tool handling (tool=4, modal, insert, preview) to inline script - Fix modal dismiss handler to reset tool to mouse pointer on cancel Agent-Logs-Url: https://github.com/ionutfinta/WhiteboardJS/sessions/f5f2b29a-17a2-43b7-b943-d51c160a3008 Co-authored-by: ionutfinta <56076718+ionutfinta@users.noreply.github.com>
Applied both review comments in commit
|
The math tool button (
la-square-root-alt) was present in the toolbar but disabled with no implementation. This wires it up end-to-end in both entrypoints.Changes
katex.min.cssandkatex.min.js(v0.16.21) to bothsrc/index.htmland rootindex.htmldisabledclass from themathsToollabel in both entrypointskatex.render(), Insert/Cancel actions, and Enter key support in both entrypointsjquery.whiteboard.jsand root inline script):mathsToolas tool 4 in the radio change handlercase 4inaddElement()captures click coordinates and opens the modal<span>, wraps it in a draggable.wbjs-elcontainer, positions it at click locationUsage
Select √ tool → click canvas → type LaTeX (e.g.
\frac{-b \pm \sqrt{b^2-4ac}}{2a}) → see live preview → Insert.