Repository navigation
fix(latex): convert accent and letter macros in body text - #4517
Conversation
Accent macros in running text lost their accent (caf\'e -> cafe), \~n lost
its letter (Espa\~na -> Espa a) and letter macros such as \o, \ss and \L
produced nothing. The inline macro path had no accent handling, and the
latex2text conversion in _process_macro was never reached.
Convert accents that carry an argument and the standard letter macros with
pylatexenc's latex2text in both the inline path and _macro_node_to_text,
unless the document redefines the name. \~{} and \^{} keep their literal
~ and ^.
Resolves docling-project#4514
Signed-off-by: pandasuwu <suhani.m024@gmail.com>
|
✅ DCO Check Passed Thanks @pandasuwu, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
latex2text does not know the document's own macros, so an accent on one
dropped the letter: with \newcommand{\vowel}{e}, caf\'{\vowel} became
"caf". When the accent's argument uses a document macro, expand it with
the backend first and then apply the accent, giving "café".
Signed-off-by: pandasuwu <suhani.m024@gmail.com>
The argument of an accent was expanded only one level, so a chain such as
\newcommand{\letter}{e} \newcommand{\vowel}{\letter} left \letter, which
latex2text then dropped: caf\'{\vowel} became "caf". Expand the argument
level by level until no document macros remain, then apply the accent.
An argument that never resolves is kept without the accent.
Signed-off-by: pandasuwu <suhani.m024@gmail.com>
A macro defined in terms of itself must stop expanding and keep its text, as on main, instead of looping or dropping it. Signed-off-by: pandasuwu <suhani.m024@gmail.com>
An accent with no parsed argument (pylatexenc gives \t none) converts the same without the early return, and tolerant parsing never raises LatexWalkerParseError, so neither branch was reachable or needed. Signed-off-by: pandasuwu <suhani.m024@gmail.com>
geoHeil
left a comment
There was a problem hiding this comment.
LGTM. Both earlier text-loss cases are fixed on d7ba852. All 124 LaTeX tests pass. I also checked macro chains, macros with arguments, redefined letters, and conversion in headings, captions, and table cells. No remaining blocking findings.
|
Hi @PeterStaar-IBM @ceberam, a gentle ping on this one. @geoHeil has approved it after two rounds of review, and the remaining Mergify protection needs a second approval because the PR updates tests (the ground-truth changes are text corrections only, e.g. |
Signed-off-by: pandasuwu <suhani.m024@gmail.com>
AI triage (advisory)Checked commit The PR fixes accent and letter macros in the LaTeX backend body text, so that macros such as Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR description lists the exact author names that are corrected (e.g. The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at e939160ba8. It read the code and did not run it.
The PR correctly fixes accent and letter macros in body text, headings, and table cells. Two rounds of reviewer feedback were resolved: custom-macro arguments in accents are now expanded iteratively, with a cycle guard. The removed MACROS_ACCENTS branch in _process_macro was unreachable, so its deletion is safe. Check that bare \~ (no argument, previously mapped to a space) now silently produces ~ instead — the test covers \~{} and \~n but not the bare form; confirm that this behavior change is acceptable.
A maintainer makes the merge decision. This review never approves the pull request.
Accent macros in running text lost their accent,
\~nlost its letter, and letter macros such as\o,\ssand\Lproduced nothing (#4514). The inline macro path (_process_macro_node_inline) had no accent handling:\'efell through to the generic branch, which kept only the argument, and\~nmatchedMACROS_INLINE_VERBATIMand became a space. TheLatexNodes2Textconversion in_process_macrowas never reached, because that method is only called forMACROS_STRUCTURALmacros.Input:
Before:
After:
The fix adds
_char_macro_to_texttoTextHelperMixin. It converts an accent macro that carries an argument, or one of the standard text-mode letter macros (newMACROS_LETTERSinconstants.py), with pylatexenc'slatex2text. Both the inline path and_macro_node_to_text(headings, captions, table cells, macro arguments) use it. It leaves alone:\newcommand/\renewcommand,\~{}and\^{}, which keep their literal~and^(e.g.http://x.org/\~{}user);latex2textrenders these as an empty string.The now-unreachable
MACROS_ACCENTSbranch in_process_macrois removed.Tests.
test_latex_accent_macrosaid accents "are converted to Unicode characters" but only asserted"caf" in md. It now checks the exact text for accents,\~n, letter macros,\~{}and a heading, and fails on main.Ground truth. Regenerated with
DOCLING_GEN_TEST_DATA=1. Only text changes, all corrections:1706.03762:Caglar Gulcehre→Çaglar Gülçehre,Jurgen→Jürgen,ukasz Kaiser→Łukasz Kaiser(\Lwas dropped)arXiv-2501.01300v2:Universitat Munchen→Universität München,Strae→Straße,Fakultat fur→Fakultät fürpytest tests/test_latex: 123 passed.prek run --all-files: passed.Issue resolved by this Pull Request:
Resolves #4514
Checklist: