Repository navigation
Conversation
9 tasks done
This branch has not been deployed
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.
Related Issue(s)
Fixes #613. Related: #614.
Motivation and Context
The Stanford CS336 assignment PDF uses
NewCM10-Regular,NewCM10-Bold, andNewCM10-Italicfor ordinary prose, alongsideNewCMMath-Bookfor mathematics. The precise formula-font patterns currently match everyNewCM/NewComputerModernfont, so the body text is classified as formulas and protected with placeholders rather than sent for translation.This also explains why
--formular-font-pattern ".*Math.*"cannot work around the issue: the precise built-in pattern returns before the custom pattern is evaluated.Summary of Changes
In
babeldoc/format/pdf/document_il/utils/formular_helper.py, narrow the two precise matches toNewCMMathandNewComputerModernMath. Ordinary NewCM fonts can then follow the existing text/custom-pattern classification, while actual math fonts remain protected.In
tests/test_formular_helper.py, cover regular/bold/italic text, PDF subset prefixes, both math-font spellings, existing Computer Modern/Latin Modern behavior, and page/XObject font scopes. Each case runs with the default formula pattern and the custom.*Math.*pattern.#614 restores the paragraph bounding-box IoU fallback; this change addresses the separate font-classification cause documented in #613.
PR Type
Breaking Changes
None.
Testing Instructions
uv run pytest tests/test_formular_helper.py -q: 24 passed, importing the production module and using the real IL dataclasses.uv run ruff check .: passed.uv run ruff format --check babeldoc/format/pdf/document_il/utils/formular_helper.py tests/test_formular_helper.py: passed.git diff --check: passed.PyMuPDF inspection of the linked PDF found 97,688 characters in
NewCM10-Regular, 6,105 in bold, 884 in italic, and 2,674 inNewCMMath-Book, confirming that the affected font names occur in the reported document.Contributor Checklist
Limitations
Verification covers offline font classification, font-resource scopes, and the source PDF's font metadata. End-to-end translation through an external service is unverified.
Summary by cubic
Fixes #613:
NewCMtext fonts (e.g.NewCM10-Regular) were matched by the precise formula-font pattern and protected as math, preventing translation. The pattern now only matches math fonts (NewCMMath*,NewComputerModernMath*), so ordinary NewCM text fonts classify as text. Adds regression tests for font classification and page/XObject scopes, including the custom.*Math.*pattern.Written for commit 2c86910. Summary will update on new commits.