Skip to content

Fix physical quantitiy handdrawn latex#264

Merged
m-messer merged 1 commit into
mainfrom
fix/physical_quantitiy_latex_fix
Jul 22, 2026
Merged

Fix physical quantitiy handdrawn latex#264
m-messer merged 1 commit into
mainfrom
fix/physical_quantitiy_latex_fix

Conversation

@m-messer

Copy link
Copy Markdown
Member

Problem

Previewing a physical-quantity LaTeX expression whose value contains LaTeX syntax, such as when from hand-drawn maths.

When previewing \frac{x}{y} kg in compareExpressions with physical _quantity enabled, the value (\frac{x}{y}) will be parsed directly by sympy instead of parsing via LaTeX first, causing the preview function to throw an exception.

Changes

  • app/utility/physical_quantity_utilities.py: PhysicalQuantity._all_forms() now converts the value string through parse_latex() before parsing it with SymPy, guarded by is_latex, mirroring the existing conversion pattern used in physical_quantity_preview.py.
  • app/preview_implementations/physical_quantity_preview.py: also catch tokenize.TokenError alongside SyntaxError so any other not-yet-found unconvertible-LaTeX edge case are handled correctly
  • app/tests/physical_quantity_preview_test.py: added test_latex_physical_quantity_preview, to test various inputs for preview

@m-messer
m-messer merged commit 3a1d63b into main Jul 22, 2026
19 checks passed
@m-messer
m-messer deleted the fix/physical_quantitiy_latex_fix branch July 22, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants