Skip to content

Don't trap on invalid inter-element spacing (e.g. Relation followed by Binary Operator)#67

Open
SuperGooey wants to merge 1 commit into
mgriebling:mainfrom
SuperGooey:fix/invalid-interelement-spacing
Open

Don't trap on invalid inter-element spacing (e.g. Relation followed by Binary Operator)#67
SuperGooey wants to merge 1 commit into
mgriebling:mainfrom
SuperGooey:fix/invalid-interelement-spacing

Conversation

@SuperGooey
Copy link
Copy Markdown

Problem

MTTypesetter.getInterElementSpace(_:_:) asserts that the inter-element spacing type for an adjacent atom pair is never .invalid:

assert(spaceType != .invalid, "Invalid space between \(left) and \(right)")

But some perfectly valid math lists produce an .invalid adjacency — most commonly a Relation immediately followed by a Binary Operator, e.g. x = -1, a = -b + c, y < -3. In a DEBUG build this assert traps and crashes the app on valid equations. In release the assertion is compiled out and the function already falls through to return 0, so release behavior is "zero spacing" — only debug crashes.

Fix

Handle .invalid explicitly by returning 0 spacing (matching the existing release-build fall-through), instead of asserting:

if spaceType == .invalid { return 0 }

This makes debug and release consistent and stops valid equations from crashing debug builds. No change to spacing for any non-.invalid adjacency.

🤖 Generated with Claude Code

getInterElementSpace() asserted that the spacing type for an adjacent
pair of atoms is never `.invalid`. But some perfectly valid math lists
produce an `.invalid` adjacency in the inter-element spacing table — most
notably a Relation immediately followed by a Binary Operator, as in
`x = -1` (an `=` Relation followed by a `-` Binary Operator).

In debug builds this `assert` traps and crashes the host app on a valid
equation. In release builds the assertion is compiled out and the
function simply falls through to `return 0`, so release and debug already
disagreed on behavior.

Replace the assert with an explicit `if spaceType == .invalid { return 0 }`
so both configurations render such adjacencies with zero inter-element
spacing instead of crashing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant