LaTeX: a str source drops \input / \include files and \includegraphics figures
Bug
DocumentConverter().convert("paper/main.tex") drops everything the file pulls in with \input / \include, and no \includegraphics figure gets an image. The conversion reports SUCCESS and nothing is logged. The same file passed as a Path converts fully.
A str source goes through resolve_source_to_stream, so the LaTeX backend receives a BytesIO. The macro handler resolves included files and images only when path_or_stream is a Path (the includegraphics and input / include branches of handlers/macros.py; handlers/environments.py uses the same check for the TikZ source root). With a stream, both branches are skipped.
#4531 found the same symptom in the CLI and mentioned this SDK case as a separate follow-up. #4532 fixed only the CLI. The HTML, AsciiDoc and Markdown backends have a source_uri backend option for this, which their format options fill from a str source; LatexBackendOptions has no equivalent.
The README's Python example passes a str source ("a document via a local path or URL"), so a multi-file paper converted this way loses most of its text without a warning.
Steps to reproduce
from pathlib import Path
from PIL import Image
from docling.document_converter import DocumentConverter
Path("intro.tex").write_text("\\section{Introduction}\nThis sentence lives in intro.tex.\n")
Image.new("RGB", (200, 100), "blue").save("fig.jpg")
Path("main.tex").write_text(
"\\documentclass{article}\n\\usepackage{graphicx}\n\\begin{document}\n"
"Main text.\n\\input{intro}\n\\includegraphics{fig.jpg}\n\\end{document}\n"
)
for source in ["main.tex", Path("main.tex")]:
doc = DocumentConverter().convert(source).document
print(type(source).__name__, repr(doc.export_to_markdown()[:60]),
[p.image is not None for p in doc.pictures])
# str 'Main text.\n\nImage: fig.jpg\n\n<!-- image -->' [False]
# PosixPath 'Main text.\n\n## Introduction\n\nThis sentence lives in intro.te' [True]
With the repository's own paper, tests/data/latex/sources/1706.03762/main.tex (seven \inputs), a str source gives 12,090 characters of Markdown and no pictures. The same file as a Path gives 60,797 characters, including the "Training Data and Batching" subsection, and 5 figures with images.
Proposed fix
Follow the pattern of the other backends: add source_uri to LatexBackendOptions, have LatexFormatOption.backend_options_for_input fill it from a local str source, and resolve \input, \include, \includegraphics and the TikZ source root against its directory when the input is a stream. Remote sources and the existing path-traversal checks stay as they are.
Docling version
main at 3181d9f (2.135.0)
Python version
Python 3.12.13
I'll send a PR with tests for this.