Repository navigation
fix(cli): keep local LaTeX sources in place so included files resolve - #4532
DanielNg0729 merged 2 commits into
Conversation
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]>
|
@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 |
|
✅ DCO Check Passed Thanks @wak327, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
adityasasidhar
left a comment
There was a problem hiding this comment.
Looks great @wak327.
If you can, please go ahead and run the change on a bigger latex source and confirm the regressions holdup.
DanielNg0729
left a comment
There was a problem hiding this comment.
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?
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. |
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]>
|
@DanielNg0729 I've added it in 6fbfb43 so |
The CLI copies each local input into a temporary directory before converting it. The LaTeX backend resolves
\input,\includeand\includegraphicsrelative 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_sourcecheck next to_is_html_sourceso local.tex/.latexfiles 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\inputsections and the five figures.The new CLI test converts a
main.texthat only\inputs a siblingbody.texand checks the sibling's text is in the output. Onmainthe output is empty.Issue resolved by this Pull Request:
Resolves #4531
Checklist: