Skip to content

fix(cli): keep local LaTeX sources in place so included files resolve - #4532

Merged
DanielNg0729 merged 2 commits into
docling-project:mainfrom
wak327:fix/latex-input-relative-to-source
Oct 4, 2026
Merged

DanielNg0729 merged 2 commits into
docling-project:mainfrom
wak327:fix/latex-input-relative-to-source

Conversation

@wak327

@wak327 wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

The CLI copies each local input into a temporary directory before converting it. The LaTeX backend resolves \input, \include and \includegraphics relative to the document's own directory, so after the copy none of those files are found and their content is silently dropped. On the repository's test paper (tests/data/latex/sources/1706.03762/main.tex) the CLI produced 12 KB of Markdown instead of about 61 KB, and none of the figures.

Local HTML files already skip the copy for the same reason (their relative images). This adds an _is_latex_source check next to _is_html_source so local .tex / .latex files are passed through in place too. Remote LaTeX sources and all other formats are unchanged.

With the change, the test paper converts to the same text as DocumentConverter().convert(Path(...)), including the \input sections and the five figures.

The new CLI test converts a main.tex that only \inputs a sibling body.tex and checks the sibling's text is in the output. On main the output is empty.

Issue resolved by this Pull Request:
Resolves #4531

Checklist:

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

The CLI copied every local non-HTML input into a temporary directory
before converting it. The LaTeX backend resolves \input, \include and
\includegraphics relative to the document's directory, so after the copy
all included files and figures were silently dropped. Pass local LaTeX
files through in place, as is already done for HTML.

Resolves docling-project#4531

Signed-off-by: Waleed Khalid <[email protected]>
@wak327

wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@adityasasidhar @PeterStaar-IBM could you take a look? The LaTeX backend (#2890) resolves included files relative to the source, and this extends the in-place handling the CLI already does for local HTML (#3506) to .tex files. I kept it to LaTeX to stay close to that precedent; if you'd rather stop copying local files for every format, I'm happy to rework it that way.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @wak327, 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 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Looks great @wak327.

If you can, please go ahead and run the change on a bigger latex source and confirm the regressions holdup.

@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 @wak327 for fixing this.
i have one small, optional thought: _is_html_source also keeps the file in place when --from html is the only format, whatever the extension. Would it be worth doing the same for LaTeX, so that --from latex on a file without a .tex extension still resolves its \inputs?

@wak327

wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Looks great @wak327.

If you can, please go ahead and run the change on a bigger latex source and confirm the regressions holdup.

Thanks! I ran every LaTeX source under tests/data/latex/sources through the CLI before and after the change, and compared against DocumentConverter().convert(Path(...)). With the fix, the CLI output is byte-identical to the SDK on all 9 sources. The two that use \input are the ones that change: 1706.03762 goes from 12 KB to 61 KB of Markdown, and 2412.19437 (DeepSeek-V3) from 98 KB to 122 KB. The other 7 are unchanged.

@wak327

wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @wak327 for fixing this. i have one small, optional thought: _is_html_source also keeps the file in place when --from html is the only format, whatever the extension. Would it be worth doing the same for LaTeX, so that --from latex on a file without a .tex extension still resolves its \inputs?

Good point, I checked it. Unlike HTML, which is also detected from its content (_detect_html_xhtml), LaTeX is only detected by its .tex/.latex extension. So with --from latex, a file like paper.ltx or paper is skipped as "format None" before the CLI's copy step is reached, and mirroring the HTML rule wouldn't change the result today. I'd rather not add a branch that can't be exercised. If you'd like it anyway for symmetry, I'm happy to add it, or to open a separate issue for detecting LaTeX by content (e.g. a leading \documentclass), after which the single-format rule would make sense.

Mirror _is_html_source: with --from latex alone, hand the file over in
place whatever its extension, so its \input and \includegraphics paths
stay resolvable.

Signed-off-by: Waleed Khalid <[email protected]>
@wak327

wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@DanielNg0729 I've added it in 6fbfb43 so --from latex mirrors --from html and keeps the source in place whatever its extension, with a CLI test that checks the converter gets the original path rather than a temp copy. Detecting LaTeX by content is still needed for such files to convert end to end. I can open a separate issue for that if you'd like.

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.

CLI drops LaTeX \input/\include files and \includegraphics figures

3 participants