Skip to content

fix(latex): skip minted's language and bracketed options before code - #4544

Open
ankit2235 wants to merge 2 commits into
docling-project:mainfrom
ankit2235:fix/latex-code-env-arguments
Open

ankit2235 wants to merge 2 commits into
docling-project:mainfrom
ankit2235:fix/latex-code-env-arguments

Conversation

@ankit2235

@ankit2235 ankit2235 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

_extract_verbatim_content only skipped an optional [...] after \begin{env}, using a non-greedy \[.*?\]. Two cases leaked markup into the code item:

  • minted takes a mandatory language argument, which became the first line of the code: \begin{minted}{python} gave {python}\nx = 1.
  • An lstlisting option value containing ], such as caption={A [nested] cap}, ended the option match early and left cap}] in the code.

The pattern now skips an optional argument whose {...} values may contain brackets, and, for minted only, the {language} argument after it. verbatim, plain lstlisting, multi-line options, and code that itself starts with [ or { behave as before.

The new parametrized test covers minted with and without options and lstlisting with a bracketed caption, with an indented code line so the first-line indentation from #4502 stays covered. It fails on main and passes with this change; the other LaTeX tests pass unchanged.

Using minted's language (or lstlisting's language=) as the code item's language is left for a follow-up.

Issue resolved by this Pull Request:
Resolves #4542

Checklist:

  • Documentation has been updated, if necessary. (not needed)
  • Examples have been added, if necessary. (not needed)
  • Tests have been added, if necessary.

Signed-off-by: Ankit Kumar <ankitkumar19473@gmail.com>
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 3, 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 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@ankit2235

Copy link
Copy Markdown
Contributor Author

Hi, friendly ping in case this got lost, happy to change anything if needed.

Signed-off-by: Ankit Kumar <ankitkumar19473@gmail.com>

# Conflicts:
#	docling/backend/latex/utils/text.py
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working labels Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

This pull request updates _extract_verbatim_content to skip optional arguments with nested brackets. It also skips mandatory language arguments for minted code environments.

Topic labels added: bug.

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

1 related pull request(s) in the same code
PR State Signal Assessment
#4502 merged referenced as #4502 related: PR #4502 preserves first-line indentation in code environments, whereas this PR excludes environment arguments from extracted code.

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 Oct 15, 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 765e1a36c4. It read the code and did not run it.

I found no defect that blocks the merge. The new regex in _extract_verbatim_content handles the three cases in the PR. The minted language is skipped only for minted, and the group patterns use disjoint alternatives, so they do not backtrack badly. The regression test checks the exact code text, so it fails on the old pattern.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LaTeX backend leaks minted's language argument and bracketed lstlisting options into the code

1 participant