Require #\name for LaTeX symbols, render canvas at device pixel ratio, and keep mobile keyboard from covering the tree#8
Conversation
…rols to top on mobile Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/48759929-9b18-4e12-aafe-9360db561da6 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the expression-tree page to (1) make LaTeX symbol rendering for custom tokens opt-in via #\name, (2) render the canvas sharply on HiDPI/mobile by honoring devicePixelRatio, and (3) prevent the mobile keyboard from pushing the controls over the tree by removing vertical centering.
Changes:
- Require
#\namefor LaTeX-command custom identifiers; render bare#nameas upright text (\mathrm{...}). - Scale the canvas backing store by DPR while keeping drawing coordinates in CSS pixels; fix PNG/SVG export sizing to remain in logical units.
- Adjust
.controlslayout to stay near the top of the viewport when the virtual keyboard opens.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tree.js |
Makes LaTeX symbol lookup opt-in (only for identifiers starting with \) and updates identifier-to-LaTeX mapping rules accordingly. |
infixToPostfix.js |
Extends allowed character set and tokenizer to accept an optional backslash immediately after # in custom identifiers. |
index.html |
Updates the input placeholder example to the new #\pi syntax. |
canvas.js |
Implements DPR-aware canvas sizing/transform and updates PNG/SVG export dimensions to use CSS sizes. |
app.css |
Pins the controls near the top to avoid keyboard-induced re-centering over the tree. |
README.md |
Updates documented syntax and examples to reflect #\name opt-in symbol rendering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| the mobile keyboard opening (which shrinks the visual viewport and | ||
| re-centers anything using `margin: auto`) does not push the input | ||
| down over the tree. */ | ||
| margin: 1rem auto 0 auto; |
There was a problem hiding this comment.
The four-value margin shorthand is redundant here (margin: 1rem auto 0 auto). Since left/right are both auto, this can be simplified to margin: 1rem auto 0; (or margin: 1rem auto 0 auto only if you intentionally want to be explicit).
| margin: 1rem auto 0 auto; | |
| margin: 1rem auto 0; |
Three issues on the expression tree page:
#phisilently rendered as the Greek letter φ; the symbol lookup should be opt-in via#\phi, and bare#phishould display as the textphi.Symbol lookup is now opt-in via
\infixToPostfix.js: tokenizer accepts one optional\immediately after#as part of the identifier (ALLOWED_CHARACTERS_REGEXextended accordingly).tree.js:LATEX_SYMBOL_MAPis only consulted for names starting with\; the\is stripped before subscript splitting and re-attached before lookup so#\theta12→ θ₁₂ and#\theta_foo→ θ_foo still work. Unknown#\foois passed through to KaTeX as raw\foo;#foofalls back to\mathrm{foo}.#\phi\phi\phi#phiphi\mathrm{phi}#\theta12\theta12\theta_{12}#foo_barfoo_bar\mathrm{foo}_{bar}Canvas rendered at
devicePixelRatioresizeCanvassets the backing store tocssSize × dpr, pinscanvas.style.{width,height}to the CSS size, and applies a matchingsetTransform(dpr, 0, 0, dpr, 0, 0); all drawing code continues to use CSS pixels.clearCanvasresets the transform beforeclearRectso it covers the full backing store.cssWidth/cssHeightso the user-selected export scale isn't multiplied by DPR and the SVGviewBoxstays in logical units.Controls no longer re-center over the tree when the keyboard opens
.controlsswitched frommargin: auto(flex vertical centering) tomargin: 1rem auto 0. The input stays pinned near the top of the viewport, so shrinking the visual viewport for the virtual keyboard no longer pushes it down onto the top-anchored tree nodes.