Repository navigation
fix(latex): resolve \input and \includegraphics for str sources - #4697
Conversation
A str source is read into a stream before it reaches the LaTeX backend,
and the handlers resolved \input, \include, \includegraphics and the
TikZ source root only for a Path input. So convert("paper/main.tex")
silently dropped every included file and figure image.
Add source_uri to LatexBackendOptions, like the HTML, Markdown and
AsciiDoc backends have, and let LatexFormatOption fill it from a local
str source. The backend resolves relative files against the directory
of the Path input or of source_uri. http(s) sources stay unchanged, and
the path traversal checks are the same as before.
Resolves docling-project#4694
Signed-off-by: usmanmateen <usmanmateen255@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ DCO Check Passed Thanks @usmanmateen, 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/
|
AI triage (advisory)Checked commit The PR fixes LaTeX Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
The |
|
cc @DanielNg0729 @adityasasidhar: this is the SDK |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
MarkdownBackendOptions.source_uri resolves relative image paths, but MarkdownFormatOption did not fill it in from the input source, so a local Markdown file converted with fetch_images=True could not load its own relative images. The other backends that use source_uri, HTML, AsciiDoc, and LaTeX since #4697, fill it in from the input. Add the backend_options_for_input override to MarkdownFormatOption, the same way HTMLFormatOption and AsciiDocFormatOption already do it. Signed-off-by: Abdel <62770500+hktitof@users.noreply.github.com>
Issue resolved by this Pull Request:
Resolves #4694
A
strsource goes throughresolve_source_to_stream, so the LaTeX backend gets aBytesIO. The handlers resolved\input,\include,\includegraphicsand the TikZ source root only whenpath_or_streamwas aPath, soDocumentConverter().convert("paper/main.tex")dropped every included file and figure image without a log message.This follows the pattern the HTML, Markdown and AsciiDoc backends already use:
LatexBackendOptionsgets asource_uri: Optional[PurePath]field. It is a local path only, because the LaTeX backend only reads local files.LatexFormatOption.backend_options_for_inputfillssource_urifrom astrsource that is not an http(s) URL, using the sameAnyHttpUrlcheck asresolve_source_to_stream. Unlike HTML, it does this when no backend options are set too, because aPathinput already resolves included files by default. User-supplied options are kept, and an explicitsource_uriwins._source_dironce, from thePathinput or fromsource_uri, and the three handlers use it instead of checkingisinstance(self.path_or_stream, Path).Pathinputs, streams withoutsource_uri, http(s) sources and the CLI (#4532) behave as before. The path-traversal checks are unchanged and now run against_source_dir.Checklist:
strsource now behaves like aPath)Review evidence:
str 'Main text.\n\nImage: fig.jpg\n\n<!-- image -->' [False]onmain. With this change, thestrandPathlines match: the\inputsection is there and the figure has an image.tests/data/latex/sources/1706.03762/main.texas astrsource: 12,090 characters and no pictures onmain; 60,797 characters and 5 figures with images here, the same as aPathsource.tests/test_latex/test_basic.py: astrsource (absolute and relative to the working directory) resolves\inputand\includegraphics; a stream withsource_uriresolves them too;backend_options_for_inputsetssource_urionly for a localstr, not for an http(s) URL or aPath, and keeps other options. All 4 fail onmainand pass here.pytest tests/test_latex: 137 passed (133 onmainplus the 4 new tests).ruff format --check,ruff checkandtach checkpass.ty checkreports nothing new; the two warnings inlatex/backend.pyare on lines that are unchanged frommain.tests/test_cli.py, because my environment doesn't havetorchvision. This PR doesn't change the CLI.#4696 (CMYK figures) also touches
handlers/macros.py, but in a different part of the file, so the two PRs don't overlap.🤖 Generated with Claude Code