Repository navigation
fix(latex): typeset non-breaking spaces, dashes and quotes - #4416
MohammadHijjawi97 wants to merge 4 commits into
Conversation
|
✅ DCO Check Passed Thanks @MohammadHijjawi97, all your commits are properly signed off. 🎉 |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
* fix(latex): start a new text item at every \item pylatexenc gives a plain \item an argument list of [None]. The list is truthy, so since #4579 every \item takes the term branch, and the text buffer is no longer flushed at an item. A list environment that is not itemize, enumerate or description reaches this path as one node list. Its items then merge into one text item: compactitem with "Alpha" and "Beta" gives "Alpha\nBeta". Flush the text buffer at every \item, before the term is added. Signed-off-by: Daniel Nguyen <[email protected]> * fix(latex): drop an \item term that converts to empty text When the optional \item argument converts to empty text, the term fallback used the raw LaTeX source. Macros that give no text then leak into the export: \item[\textbullet] bullet macro gives "\textbullet: bullet macro", and \quad and \hspace{1em} behave the same way. Before #4579 these items gave "bullet macro". Read the term in one helper for the inline path and for _nodes_to_text, and drop a term that converts to empty text. The helper checks the pylatexenc LatexGroupNode type instead of probing with hasattr. Table cells use _nodes_to_text, so a list in a cell no longer gets the raw macro either. \item[--] now gives "Dash bullet" again, as before #4579. The backend drops the -- ligature from all text today; #4416 works on dashes. Signed-off-by: Daniel Nguyen <[email protected]> * refactor(latex): replace attribute probing with type checks AGENTS.md asks us to avoid hasattr(...) and getattr(...) probing. The LaTeX backend probed nodes and cells in 36 places. - An argument in argnlist has a node list only when it is a LatexGroupNode, so check that type. - Four tree walkers repeated the same probes for the node list and the group arguments of a node. iter_child_nodelists() now yields these lists, with isinstance checks against the pylatexenc classes that have them. - Every LatexNode has pos, and every LatexMathNode has displaytype, so read them directly. Check LatexSpecialsNode for the & cell separator. - _parse_table set private attributes on TableCell for the spans and the multicolumn placeholders, and read them back with getattr. Keep (cell, col_span, row_span) in the row instead, and None for a covered column. This also removes three type: ignore comments. The conversion output does not change. Signed-off-by: Daniel Nguyen <[email protected]> --------- Signed-off-by: Daniel Nguyen <[email protected]>
|
Hi @MohammadHijjawi97, thank you for this pull request. It has a merge conflict with git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-leaseWe can continue with the review and CI after that. |
pylatexenc parses ~, --, ---, `` and '' as specials nodes, not as chars, and the backend skipped those nodes, so their text vanished and the words around them ran together: "Fig.~1" became "Fig.1", "Dr.~Smith" became "Dr.Smith", the page range "10--20" became "1020" and ``quoted'' text lost its quotation marks. Bibliographies were hit hardest, since author initials and page ranges are written this way. Emit the typeset text for these specials, both for body text and for text taken from macro and group arguments, and regenerate the LaTeX ground truth accordingly. Signed-off-by: Mohammad Hijjawi <[email protected]>
Signed-off-by: Peter Staar <[email protected]>
9e266bc to
56c5e06
Compare
maxmnemonic
left a comment
There was a problem hiding this comment.
Approach is good, but grouped text with inline math still looses spaces and punctuation.
For example:
\textbf{See Fig.~1 on pages 10--20 and $x$.}
Expected:
See Fig. 1 on pages 10–20 and $x$.
Actual:
See Fig.1 on pages 1020 and $x$.
Please handle LatexSpecialsNode in _append_inline_nodes.
Also add tests for specials inside groups and formatted text that contain inline math.
…text Signed-off-by: Mohammad Hijjawi <[email protected]>
A group or formatted text that contains inline math goes through
_append_inline_nodes, which skipped specials nodes. So
"\textbf{See Fig.~1 on pages 10--20 and $x$.}" still became
"See Fig.1 on pages 1020 and $x$.". Emit the typeset text for specials
there too, and add tests for plain groups, \textbf, \emph and
\bfseries groups with inline math.
Signed-off-by: Mohammad Hijjawi <[email protected]>
|
@maxmnemonic Thanks for the review. You were right: groups and formatted text that contain inline math go through I added |
AI triage (advisory)Checked commit This pull request preserves LaTeX special characters during conversion. It emits text for non-breaking spaces, dashes, and quotation marks. Topic labels added: CI safety: no concern found. A maintainer must still approve CI. Reference data changes
Assessment: expected. The reference data changes add the converted text for LaTeX non-breaking spaces, dashes, and quotes. The |
pylatexenc parses
~,--,---,``and''as specials nodes rather than chars, and the LaTeX backend skipped those nodes. Their text vanished and the surrounding words ran together, which is most visible in bibliographies, where author initials and page ranges are written this way.Input:
Before:
After:
The fix emits the typeset text for these specials in body text and in text taken from macro/group arguments (e.g.
\textbf{1990--2000}), via oneSPECIALS_TEXTmap inconstants.py.~becomes a plain space, matching the existing\~handling inmacros.py.The existing tilde test only checked that "Smith" was present; it now checks the spacing, and a new test covers dashes and quotes (both fail on main). The LaTeX ground truth was regenerated with
DOCLING_GEN_TEST_DATA=1; the changes are corrections such asJimmyLei→Jimmy Lei,770778→770–778,etal.→et al.andFigure[fig:model-arch]→Figure [fig:model-arch].pytest tests/test_latex: 90 passed.Checklist: