Skip to content

fix(latex): flush text at every \item and drop empty item terms - #4644

Merged
DanielNg0729 merged 3 commits into
docling-project:mainfrom
DanielNg0729:fix/latex-description-term-regressions
Oct 8, 2026
Merged

DanielNg0729 merged 3 commits into
docling-project:mainfrom
DanielNg0729:fix/latex-description-term-regressions

Conversation

@DanielNg0729

@DanielNg0729 DanielNg0729 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

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 exports Latency: Time to first byte.. Two other cases changed with it:

  1. Items merge in list environments other than itemize, enumerate and description. pylatexenc gives a plain \item the argument list [None]. That list is truthy, so every \item now takes the term branch, and the text buffer is no longer flushed at each item. _process_list hides this for the three ENV_LIST environments, 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.
  2. Raw LaTeX leaks into the text. When the term converts to empty text, the fallback uses the term's LaTeX source. \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: call flush_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 for LatexGroupNode instead of using hasattr. 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 avoid hasattr(...) and getattr(...). This commit replaces the other 36 probes in docling/backend/latex/ with isinstance checks against the pylatexenc classes. Four tree walkers repeated the same probes, so they now share a new iter_child_nodelists() helper. _parse_table now keeps each cell's spans in the row with the cell, instead of in private attributes on TableCell. The conversion output does not change. I am happy to move this commit to a separate PR if you prefer.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

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]>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @DanielNg0729, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

@DanielNg0729
DanielNg0729 requested review from PeterStaar-IBM and geoHeil and removed request for PeterStaar-IBM October 8, 2026 03:03

@geoHeil geoHeil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DanielNg0729
DanielNg0729 merged commit 560bb54 into docling-project:main Oct 8, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants