Skip to content

fix(latex): keep braces and spaces inside \verb - #5190

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
Fahmid-Arman:fix/latex-verb-braces
Nov 16, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
Fahmid-Arman:fix/latex-verb-braces

Conversation

@Fahmid-Arman

Copy link
Copy Markdown
Contributor

Issue resolved by this Pull Request:
Resolves #5189

The generic macro argument code turned every non-group argument into text with arg.latex_verbatim().strip("{} "). pylatexenc passes \verb|...| content as a LatexCharsNode, which has no delimiters to strip, so the strip removed the content's own braces and spaces. Both copies of that code, _extract_all_macro_args_inline in handlers/macros.py (body text) and the loop in utils/text.py (headings and other arguments), now use a characters argument's chars as is and keep the strip for other arguments.

Checklist:

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

Review evidence:

Source Before After
\section{The \verb|{x}| key} heading The x key heading The {x} key
... \verb|\section{Intro}| and ... as \verb|{}|. ... \section{Intro and ... as . ... \section{Intro} and ... as {}.
  • New test_latex_verb_keeps_braces_and_spaces in tests/test_latex/test_macros.py covers both cases. It fails on main and passes with the change.
  • No reference data changes: converting every source under tests/data/latex gives the same documents as the groundtruth .json files.
  • pytest tests/test_latex: all pass except test_e2e_latex_conversions, which fails on main here as well because this environment has no renderer for the LaTeX figures (predicted image is None); its Markdown, indented text, DocLang and LaTeX comparisons pass.
  • 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

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

@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 0eb8acacd9. The analysis read the diff only. It did not run code from this pull request.

The PR fixes LaTeX \verb handling. The generic macro argument code now keeps the braces and spaces inside \verb content, in body text and in headings. It adds one regression test.

Topic labels added: bug.

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

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 added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 5, 2026

@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 0eb8acacd9. It read the code and did not run it.

I found no defect. The change in docling/backend/latex/handlers/macros.py:820 and docling/backend/latex/utils/text.py:359 is narrow: only a LatexCharsNode argument skips the strip, and other argument types behave as before. The regression test checks both the heading case and the body-text case. I could not read the installed pylatexenc source, so I could not confirm that it returns \verb content as a LatexCharsNode. The fix and the test depend on that claim.

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

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/latex/utils/text.py 0.00% 1 Missing ⚠️

📢 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 #5188 and #5192. The full results are in #5192 (comment). For this PR: all papers converted without errors, and no output changed. The 4 \verb uses in those papers have no braces or spaces, and those are the only cases this PR changes.

@PeterStaar-IBM
PeterStaar-IBM merged commit 3809406 into docling-project:main Nov 16, 2026
55 checks passed
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 strips braces and spaces from \verb content

2 participants