Skip to content

fix(latex): read \paragraph and \part titles as headings - #5188

Open
Fahmid-Arman wants to merge 1 commit into
docling-project:mainfrom
Fahmid-Arman:fix/latex-paragraph-part-headings
Open

Fahmid-Arman wants to merge 1 commit into
docling-project:mainfrom
Fahmid-Arman:fix/latex-paragraph-part-headings

Conversation

@Fahmid-Arman

Copy link
Copy Markdown
Contributor

Issue resolved by this Pull Request:
Resolves #5187

pylatexenc's default macro specs misspell \paragraph as pagagraph and have no \part, so neither macro got its {title} argument and the LaTeX backend read the title as body text, glued to the next paragraph. LATEX_CONTEXT_DB now declares both with the same spec pylatexenc uses for the other sectioning commands (*[{), so their titles reach the existing heading handler, which already maps part to level 1 and paragraph to level 4.

Checklist:

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

Review evidence:

Source Before After
\part{Background} text Background level 1 heading Background
\paragraph{Contributions.} We propose... text Contributions. We propose... level 4 heading Contributions., then text We propose...
\subparagraph{Details.} More text. level 5 heading (unchanged) level 5 heading (unchanged)
  • test_latex_subparagraph_heading (tests/test_latex/test_macros_more.py) now checks the levels of both \paragraph and \subparagraph, and test_latex_heading_levels (tests/test_latex/test_macros.py) checks the exact headings, including \part. Both fail on main and pass with the change.
  • Reference data: the groundtruth for 1706.03762 and 2412.19437, the two sources that use \paragraph, is regenerated. The diff turns titles like Encoder:The encoder is composed of... and Residual Dropout We apply dropout... into headings followed by their text. The .json files keep the picture images from main: this environment has no renderer for the LaTeX figures, so I regenerated the files and restored only pictures[*].image. Apart from those images, the converted documents match the new .json files exactly. No other groundtruth file changes.
  • pytest tests/test_latex: all pass except test_e2e_latex_conversions, which fails on main here as well, with predicted image is None for the figures. Its Markdown, indented text, DocLang and LaTeX comparisons pass with the new groundtruth.
  • ruff format and ruff check (v0.17.2) are clean on the changed files.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @Fahmid-Arman, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 13d1c46199. The analysis read the diff only. It did not run code from this pull request.

The PR adds \part and \paragraph macro specs to LATEX_CONTEXT_DB, so the LaTeX backend reads their titles as headings instead of body text. It tightens two heading tests and regenerates the LaTeX reference data for two sources.

Topic labels added: bug.

CI safety: no concern found. A maintainer must still approve CI.

Reference data changes

Change Files
structure 2
text 8
  • structure tests/data/latex/groundtruth/1706.03762_main.tex.json: section_header: 25 → 30
  • structure tests/data/latex/groundtruth/2412.19437_main.tex.json: section_header: 54 → 89; text: 394 → 393
  • text tests/data/latex/groundtruth/1706.03762_main.tex.dclg: +10 / -5 lines
  • text tests/data/latex/groundtruth/1706.03762_main.tex.itxt: +513 / -508 lines
  • text tests/data/latex/groundtruth/1706.03762_main.tex.latex: +17 / -7 lines
  • text tests/data/latex/groundtruth/1706.03762_main.tex.md: +17 / -7 lines
  • text tests/data/latex/groundtruth/2412.19437_main.tex.dclg: +69 / -35 lines
  • text tests/data/latex/groundtruth/2412.19437_main.tex.itxt: +619 / -585 lines
  • text tests/data/latex/groundtruth/2412.19437_main.tex.latex: +114 / -46 lines
  • text tests/data/latex/groundtruth/2412.19437_main.tex.md: +114 / -46 lines

Assessment: expected. The section_header counts rise (25 to 30 and 54 to 89), as expected when \paragraph titles become headings. The .md, .latex, .itxt and .dclg files change in the same way. The one-item drop in text for 2412.19437 is small and plausible, for example from an empty \paragraph body, but the summary does not show the cause.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot 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.

AI first review (advisory): no blocker found

This review covers the full diff at 13d1c46199. It read the code and did not run it.

I found no defect. The new MacroSpec entries make \part and \paragraph reach the existing heading handler, which already maps them to levels 1 and 4.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 5, 2026
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM PeterStaar-IBM added the latex issue related to LaTeX backend label Nov 6, 2026
@Fahmid-Arman

Copy link
Copy Markdown
Contributor Author

I checked this on 27 arXiv papers along with #5190 and #5192. The full results are in #5192 (comment). For this PR: all papers converted without errors. The 171 \paragraph titles in 12 papers became level-5 headings with their text in a separate paragraph, and no words changed except one title that was glued to the next sentence ("[GPTNeo].We remove"), which is now split. A paper that redefines \paragraph with \@startsection gives the same output as before.

@maxmnemonic maxmnemonic 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.

Let's keep the heading fix, but preserve document-defined versions of \paragraph and \part

The new parser specs consume their arguments before the custom macro expander can read them. For example:

\renewcommand{\paragraph}[1]{#1}
\paragraph{Keep me} Body.

The base produces Keep me Body.
but this PR produces #1 Body.

Please adjust parsing or argument expansion so custom definitions retain their arguments. Add regression tests for both commands, and keep the normal, starred, and optional-title heading behavior working.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working latex issue related to LaTeX backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LaTeX backend reads \paragraph and \part titles as body text

3 participants