Repository navigation
fix(latex): number the items of enumerate lists - #4518
Conversation
|
✅ 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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
geoHeil
left a comment
There was a problem hiding this comment.
Please keep each source item as one list item when it contains a display equation or other content that flushes the text buffer. I confirmed the case below on c147215. All 124 LaTeX tests pass, but they do not cover this case.
|
@pandasuwu can you please follow up here? |
|
@PeterStaar-IBM Done, could u please see my reply to @geoHeil's review above |
geoHeil
left a comment
There was a problem hiding this comment.
The speed regression is fixed: 600 items take 0.016 s on this head, versus 0.016 s on the base. All 135 LaTeX tests pass. One Markdown regression remains for an item that starts with a quote; see below.
geoHeil
left a comment
There was a problem hiding this comment.
The simple quote case is fixed. The block-content and speed fixes also hold. All 138 LaTeX tests pass on 464562c. A leading paragraph break still leaves a text-only item empty; see below.
Ruff, pinned ty 0.0.33 (existing warning policy), Tach, and the lock check pass. The local line check fails on 10 unchanged files. CI fast checks pass; the merge protection still needs two approvals.
AI triage (advisory)Checked commit The PR makes the LaTeX backend number the items of CI safety: no concern found. A maintainer must still approve CI. 3 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR sets The |
|
Thanks for the updates. I rechecked One existing blocker remains: block content can leave its list item in Markdown. I ran the five cases in docling-core #888 is still open. Please keep this PR on hold until that fix is released and required here. Then remove the expected-failure marker and update the affected tests and reference output. The backend changes otherwise look good in the cases I checked. Ruff, ty with the current warning policy, Tach, dprint, and the lock check pass. |
|
Hello @geoHeil, I saw that docling-project/docling-core#888 will be dropped for docling-project/docling-core#830 casue the latter handles two more inline cases. So this PR now has to wait until #830 is merged and released. |
|
@pandasuwu a heads-up for your next rebase: since #3891 and docling-core 2.106.0, serializers join With Please keep this space when you rebase. |
|
Hi @pandasuwu, 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. |
The items of an enumerate are created with enumerated=True, and the content of each \item is added inside one list item, so every \item adds exactly one child to its list and the numbering matches the document. The first paragraph of an item becomes its text; a formula that starts an item goes on the line of the item, with the text after it. Empty items are kept. Rebased on main: a paragraph with inline math in a list item goes on the line of the item, a footnote in an item stays a child of the item, and text that continues the line keeps its leading space, since serializers join InlineGroup runs without a separator. Resolves docling-project#4515 Signed-off-by: pandasuwu <[email protected]>
cdb2ee1 to
2d4fff9
Compare
|
@PeterStaar-IBM The rebase is done. The branch is now one commit ( Changes to fit current
|
Since #4518 the list handler splits a list body into items before it reads an \input file. The \item lines of the file were then processed inside the previous item, so they became plain text and the later items got the wrong numbers. Read each \input file of a list body first and splice its nodes into the body, as LaTeX does with plain text inclusion. The file reading moves to _read_input(), which keeps the path, cycle and depth checks of the \input handler. Signed-off-by: Christoph Auer <[email protected]>
enumeratelists were converted to unordered lists (#4515). The LaTeX backend adds list items through the generic text path (doc.add_text(label=DocItemLabel.LIST_ITEM)), which creates them withenumerated=False, and nothing in the backend set it forenumerate. Markdown export therefore rendered-bullets, and the repository's ground truth recorded it:example_01.tex.mdshows the items "First item in ordered list" and "Second item in ordered list" as bullets.Input:
Before:
After:
Fix. The items of an
enumerateare created withenumerated=True; a nested list keeps its own kind.That alone is not enough, because docling-core numbers an item by its position among the children of its list group, and the backend could add more than one child per
\item. Anything that flushes the text buffer started a new sibling in the list:\[...\],equation) or a quote, together with the text after it.With numbering on, each of these would take a number, e.g.
1. First, the formula,3. continuation,4. Secondfor\item First \[x=1\] continuation. The new_process_list_itemtherefore creates the list item first and adds the whole content of the\iteminside it; the leading text then becomes the text of the item itself. Every\itemnow adds exactly one child to its list, whatever it contains. This is the structure the Markdown and HTML backends already produce for nested lists.The first paragraph of an item is written into the list item as it is added, whether it comes from the text buffer or is a paragraph between blank lines, and whichever call adds it. So it also becomes the text of the item after a leading blank line or when it is nested in a quote, another environment or a group, and no temporary item is created and deleted. Text added to a list item is split at blank lines, since a blank line inside the item text would end the list in a Markdown export.
doc.delete_items()rescans the whole document, and calling it per item made list conversion quadratic; the list code no longer deletes items. List conversion time grows linearly with the number of items, as on main.An empty
\item(no content, or only a\label) used to add no list item, so every later item would take a number one lower than in the typeset document. Every\itemnow adds a list item, even an empty one. The content before the first\itemis processed as before: whitespace, comments and macros such as\setlengthadd nothing, and stray text becomes a numbered item.An item that starts with
\footnote{...}or\newlinekeeps its text: a footnote is attached to the item as a child and does not become its text, and a\newlinebefore any content has nothing to break and is dropped.A display formula that starts an item, as in
\item \[x=1\] First, goes on the line of the item: an inline group that also takes the text up to the next blank line or other content, as the Word backend does for an equation in a paragraph. The Markdown export is1. $x=1$ Firstinstead of1.followed by the formula on its own line, which a CommonMark parser read as an empty item.Rebased on main (one commit). Changes to fit the current backend:
\footnoteis now processed with theFOOTNOTElabel. Only body text (TEXT,PARAGRAPH,LIST_ITEM) can become the text or the line of an item.InlineGroupruns without a separator. Text that continues the line of an item keeps one leading space, so the export is1. $x=1$ Firstand not1. $x=1$First.\hrefstays inline since fix(latex): keep \href links inline instead of splitting the paragraph #4600, so a link no longer splits an item. Thehrefcase is removed fromtest_latex_enumerate_item_with_block_content.equationkeeps its environment in the formula text since fix(latex): backend updates for better parsing of arxiv papers #4817.test_latex_enumerate_item_starting_with_formulaexpects\begin{equation}x=1\end{equation}for that case.Tests.
test_latex_list_enumerateonly assertedlen(list_items) >= 2; it now checks the items are enumerated and the Markdown is1. Alpha\n2. Beta. Nine new tests, all failing on main:test_latex_enumerate_numbering_with_nested_contentcovers a nested list, text after it, a second paragraph and a nestedenumerate, and checks the outer list is numbered 1 to 4.test_latex_enumerate_item_with_block_contentcovers an item containing display math, anequationand aquote, and checks the list has two direct items numbered 1 and 2.test_latex_enumerate_item_starting_with_footnote_or_newlinechecks that an item starting with a footnote or a\newlinekeeps its text, with the footnote inside the item.test_latex_enumerate_item_starting_with_nested_textcovers an item starting with a quote, a quote in a group and acenter, and checks the Markdown is1. First\n2. Second.test_latex_enumerate_item_starting_with_paragraph_breakcovers an item whose first paragraph follows a blank line, on its own, in a quote and in a group, and checks the item text, its children and the Markdown1. First\nContinuation\n2. Second.test_latex_enumerate_item_starting_with_formulacovers an item starting with\[...\]and with anequation, and checks the line of the item and the Markdown1. $x=1$ First\n2. Second.test_latex_enumerate_line_of_item_starting_with_formulachecks that a nested list ends the line of such an item and a footnote does not.test_latex_enumerate_empty_item_keeps_numberingcovers an empty\itemand one with only a\label, and checks the item after them is numbered 4.test_latex_enumerate_content_before_first_itemcovers a comment,\setlength, a\labeland stray text before the first\item.test_latex_enumerate_markdown_of_item_with_blockis marked as an expected failure until docling-project/docling-core#830 is released: the document tree keeps block content in its item, but the Markdown serializer writes it at column 0.Ground truth. Regenerated with
DOCLING_GEN_TEST_DATA=1; only list structure and numbering change:example_01.tex: the ordered list is numbered (1.,2.;enumeratein.latex,class="ordered"in.dclg).2305.03393(OTSL): the six syntax rules are numbered 1 to 6. The "Cross cell rule" item has a blank line between its title and its text, which used to produce a separate list item; that text is now inside rule 3, so the rules are not numbered 1 to 7. The.mdand.dclgexports still write that text outside the item, which is the serializer issue that fix(markdown): indent the block children of a list item to its content column docling-core#830 fixes.pytest tests/test_latexwith the locked docling-core 2.106.0: 218 passed, 1 skipped, 5 expected failures.prek runon the changed files: passed (Ruff, ty, Tach, max lines).Issue resolved by this Pull Request:
Resolves #4515
Checklist: