Skip to content

fix(latex): keep the first-line indentation of code environments - #4502

Merged
DanielNg0729 merged 2 commits into
docling-project:mainfrom
ankit2235:fix/latex-code-indentation
Oct 3, 2026
Merged

DanielNg0729 merged 2 commits into
docling-project:mainfrom
ankit2235:fix/latex-code-indentation

Conversation

@ankit2235

@ankit2235 ankit2235 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Same fix as #4487, for the LaTeX backend. _extract_verbatim_content returned match.group(1).strip(), which removed the leading indentation of the first code line while later lines kept theirs, so the relative indentation of verbatim and lstlisting code changed.

This trims only line breaks before the code and whitespace after it (lstrip("\r\n").rstrip()), keeping the first line's indentation. Code whose first line is not indented is unchanged.

The new test is parametrized over verbatim and lstlisting. It fails on main and passes with this change. The existing LaTeX tests, including the e2e groundtruth comparison, pass unchanged.

Issue resolved by this Pull Request:
Resolves #4501

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 2, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

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

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@DanielNg0729
DanielNg0729 self-requested a review October 3, 2026 12:04

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

Thank you @ankit2235 for this fix and for keeping it consistent with #4487!

One small could you delete the comment inside the code, i feel like the PR body is enough to describe this fix and also 1 small fix here

Comment thread docling/backend/latex/utils/text.py Outdated
Signed-off-by: Ankit Kumar <ankitkumar19473@gmail.com>
@ankit2235
ankit2235 requested a review from DanielNg0729 October 3, 2026 13:23

@DanielNg0729 DanielNg0729 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

@DanielNg0729
DanielNg0729 merged commit 51fe9ff into docling-project:main Oct 3, 2026
26 checks passed
@ankit2235
ankit2235 deleted the fix/latex-code-indentation branch October 15, 2026 17:21
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 strips the first-line indentation of verbatim and lstlisting code

2 participants