Repository navigation
fix(latex): flush text at every \item and drop empty item terms - #4644
DanielNg0729 merged 3 commits into
Conversation
pylatexenc gives a plain \item an argument list of [None]. The list is truthy, so since docling-project#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]>
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 docling-project#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 docling-project#4579. The backend
drops the -- ligature from all text today; docling-project#4416 works on dashes.
Signed-off-by: Daniel Nguyen <[email protected]>
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]>
|
✅ DCO Check Passed Thanks @DanielNg0729, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
geoHeil
left a comment
There was a problem hiding this comment.
Reviewed head 7a3df2e6872ae096d0fe141bd15195f88622ddbb.
No blockers found. The change fixes list item boundaries for non-standard list environments, removes empty LaTeX item terms, and keeps the LaTeX node traversal type-safe. The focused LaTeX tests pass, the full LaTeX suite passes apart from the existing image-reference failure on both base and head, and the hosted CI checks are green.
Summary
While reviewing #4579, i notice something havent been resolved. This is to follow up with it. #4579 keeps the term of
\item[term], so\item[Latency] Time to first byte.now exportsLatency: Time to first byte.. Two other cases changed with it:itemize,enumerateanddescription. pylatexenc gives a plain\itemthe argument list[None]. That list is truthy, so every\itemnow takes the term branch, and the text buffer is no longer flushed at each item._process_listhides this for the threeENV_LISTenvironments, because it splits the items first. Other list environments (compactitem,compactdesc,inparaenum,list) reach the inline text path as one node list, so all their items become one text item.\item[\textbullet],\item[\quad]and\item[\hspace{1em}]then export that source.There is one commit for each change:
fix(latex): start a new text item at every \item: callflush_fn()for every\item, before the term is added.fix(latex): drop an \item term that converts to empty text: one helper,_item_term(), now reads the term for the inline path and for_nodes_to_text(). It drops a term that converts to empty text, and it checks forLatexGroupNodeinstead of usinghasattr. Table cells go through_nodes_to_text(), so a list in a table cell no longer shows the raw macro either. That leak existed before fix(latex): preserve description list item terms #4579.refactor(latex): replace attribute probing with type checks: AGENTS.md asks us to avoidhasattr(...)andgetattr(...). This commit replaces the other 36 probes indocling/backend/latex/withisinstancechecks against the pylatexenc classes. Four tree walkers repeated the same probes, so they now share a newiter_child_nodelists()helper._parse_tablenow keeps each cell's spans in the row with the cell, instead of in private attributes onTableCell. The conversion output does not change. I am happy to move this commit to a separate PR if you prefer.Checklist: