engine: surface math the go-tex/math layer drops (Diagnostics.MathDropped) - #34
Merged
Merged
Conversation
…pped)
When go-tex/math meets a command it does not implement it returns
"unknown command \X", and the engine (in lenient mode) drops the WHOLE
equation and tallies the trigger. Until now that tally landed in the same
skippedCS map as text-mode undefined commands, so a formula's silently-lost
content was conflated with a missing text macro — and in -report-skipped it
even printed with a doubled backslash.
Separate the two. recordMathSkip now also tallies into a dedicated
mathDropped map (same key), and Diagnostics lifts those keys OUT of Skipped
into a new MathDropped field: text-mode gaps in Skipped, math-layer drops in
MathDropped. The raw skippedCS is untouched, so SkippedCommands and every
existing caller/test keep the same behaviour.
Surfaced in the -report-skipped CLI report (its own "math equation group(s)
dropped" section) and the wasm diagnostics object ("mathDropped"). A
regression test proves an unknown math command surfaces under MathDropped and
NOT under Skipped, that a malformed equation is counted under the "$math$"
sentinel, that valid math drops nothing, and that the snapshot is a copy.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instrumentation #3 — surface MATH content the math layer drops
Feasibility finding
The go-tex/math parser does not silently swallow unknown control words:
parse.goreturns a hard errortexmath: unknown command \X(and other structural errors like\left without \right). The engine already catches these inrenderMathResolvingMacros/makeMath, and in lenient mode drops the whole equation and tallies the trigger viarecordMathSkip. So go-tex/math already exposes unhandled tokens through its error return — bullet 1 of the task applies, and no change to the go-tex/math module is needed.The one gap: that tally landed in the same
skippedCSmap as text-mode undefined commands, so a formula's silently-lost content was conflated with a missing text macro. In-report-skippeda math key (which carries its own\) was even printed with a doubled backslash.(The only genuinely-silent degradations in go-tex/math are within array/column-spec parsing — an unknown column letter falls back to centred, stray punctuation is ignored. These are rendering approximations, not content drops, and are not worth a math-module change.)
Approach chosen
Separate math drops from text skips, without touching rendering or the existing
skippedCSsurface:recordMathSkipnow also tallies into a dedicatedmathDropped map[string]int(same key).Diagnostics()lifts those keys out ofSkippedinto a newMathDroppedfield (added at the end of the struct — trivial merge). Text-mode gaps stay inSkipped; math-layer drops go inMathDropped.skippedCSis unchanged, soSkippedCommands()and every existing caller/test keep identical behaviour.-report-skippedCLI report (its own "math equation group(s) dropped" section) and the wasm diagnostics object (mathDropped).Tests (RED without / GREEN with)
mathdropped_test.go+ a CLITestRunReportMathDropped:MathDroppedand not underSkipped(proving the separation), whileSkippedCommands()still carries it;\left(unclosed) is counted under the$math$sentinel;\frac,\sum,\cdot,\alpha) drops nothing;Verified by temporarily disabling the tally: both new tests go RED (the report even reproduced the old doubled-backslash conflation), GREEN once restored.
Gates
GOWORK=off go test -race ./...greengofmt -lclean,go vet ./...cleanGOWORK=off GOOS=js GOARCH=wasm go build ./...green🤖 Generated with Claude Code