Skip to content

fix(latex): preserve description list item terms - #4579

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
taran-dev4u:fix/latex-description-list-terms
Oct 6, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
taran-dev4u:fix/latex-description-list-terms

Conversation

@taran-dev4u

Copy link
Copy Markdown
Contributor

Issue resolved by this Pull Request:
Resolves #4516

Description list item terms (\item[Term]) were dropped during conversion because _process_macro_node_inline\ routed them through \MACROS_STRUCTURAL\ to _process_macro\ where \item\ was a no-op.

This extracts the optional term in _process_item_macro_inline, prepends it to the item text buffer as {term}: , and supports \LatexSpecialsNode\ in _nodes_to_text. Added unit tests in \ ests/test_latex/test_lists.py\ covering plain, formatted, and special symbol description terms.

Checklist:

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

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @taran-dev4u, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 5, 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)(?:\(.+\))?(!)?:

@taran-dev4u
taran-dev4u marked this pull request as ready for review October 5, 2026 12:06
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/latex/utils/text.py 0.00% 7 Missing ⚠️
docling/backend/latex/handlers/macros.py 70.58% 2 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

_process_list retains item nodes with optional arguments, but _process_macro_node_inline routed them through MACROS_STRUCTURAL to _process_macro where item was ignored, dropping terms like \item[Latency].

Extract the optional term in _process_item_macro_inline, prepend it to the item text buffer as '{term}: ', and preserve structural macro flushing on items without optional arguments. Add tests covering plain, formatted, and special symbol description terms.

Fixes docling-project#4516

Signed-off-by: Taran Mamidala <[email protected]>
@taran-dev4u
taran-dev4u force-pushed the fix/latex-description-list-terms branch from df3f22f to d247a12 Compare October 5, 2026 14:28

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@taran-dev4u

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @PeterStaar-IBM!

@PeterStaar-IBM
PeterStaar-IBM merged commit 0d08287 into docling-project:main Oct 6, 2026
26 checks passed
@taran-dev4u
taran-dev4u deleted the fix/latex-description-list-terms branch October 6, 2026 18:07
DanielNg0729 added a commit that referenced this pull request Oct 8, 2026
* 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]>
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.

LaTeX backend drops the term of description list items (\item[Term])

3 participants