Skip to content

feat(cli): add latex output format - #4101

Merged
cau-git merged 1 commit into
docling-project:mainfrom
aron-intframe:feat/cli-latex-output
Aug 31, 2026
Merged

cau-git merged 1 commit into
docling-project:mainfrom
aron-intframe:feat/cli-latex-output

Conversation

@aron-intframe

Copy link
Copy Markdown
Contributor

The LaTeX serializer has been available in docling-core since v2.54 (docling-project/docling-core#445), but the docling CLI cannot emit it. This adds latex to OutputFormat and wires it through export_documents, so docling <source> --to latex writes <name>.tex (standalone document, default serializer params). Addresses the LaTeX part of #343; mathpix-markdown-it is not covered.

Verified against docling-core's own golden files: converting test/data/doc/{2408.09869v3_enriched,activities,polymers}.json with --to latex reproduces the corresponding .gt.tex exactly (43,965 / 1,344 / 10,909 chars). Also smoke-tested end-to-end on tests/data/pdf/sources/2305.03393v1-pg9.pdf (sections, table, caption render as expected).

Known limitations, stated upfront: pictures are emitted as % image placeholders (referenced-image wiring could follow in a later PR), and convert-remote needs a service version that also knows latex.

Checklist:

  • Documentation has been updated, if necessary. (docs/usage/supported_formats.md; the CLI reference is auto-generated)
  • Examples have been added, if necessary. (none needed)
  • Tests have been added, if necessary. (tests/test_cli.py::test_cli_exports_latex)

Expose the LaTeXDocSerializer from docling-core as a CLI output format:
docling <source> --to latex writes <name>.tex next to the other exports.

Addresses the LaTeX part of docling-project#343.

Signed-off-by: INTFRAME <hello@intframe.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @aron-intframe, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Aug 28, 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)(?:\(.+\))?(!)?:

@PeterStaar-IBM PeterStaar-IBM 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!

@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@aron-intframe

Copy link
Copy Markdown
Contributor Author

Thanks for the approval. Before it lands I re-verified the branch as it stands (98847320, merge-base with main is d2283add = current main, so 0 commits behind), and I found one thing in my own PR description that needs correcting.

Correction to the PR body: "reproduces the corresponding .gt.tex exactly" is off by exactly one character. The CLI output matches docling-core's golden LaTeX files in content, but the .gt.tex files end with a final newline and the CLI does not write one. Running the CLI over the three docling-core fixtures (docling-core checked out at v2.92.0, the version resolved here) and comparing character-for-character:

$ for n in 2408.09869v3_enriched activities polymers; do \
    python -m docling.cli.main docling-core/test/data/doc/$n.json \
      --from json_docling --to latex --output out_tex; done
$ python compare.py
2408.09869v3_enriched: cli_chars=43965 gt_chars=43966 equal=False equal_ignoring_final_newline=True
activities: cli_chars=1344 gt_chars=1345 equal=False equal_ignoring_final_newline=True
polymers: cli_chars=10909 gt_chars=10910 equal=False equal_ignoring_final_newline=True

The whole delta is the trailing \n:

$ diff out_tex/activities.tex docling-core/test/data/doc/activities.gt.tex
61c61
< \end{document}
\ No newline at end of file
---
> \end{document}

I have not changed this on the branch, because it is what the CLI already does for its other text outputs — DoclingDocument.save_as_markdown ends in filename.write_text(md_out, encoding="utf-8") with no newline appended either, so .tex behaves like .md today. If you would prefer .tex files to end with a newline, say so and I will push the one-line fp.write(ser_res.text + "\n"); I did not push it unprompted since it would touch an already-approved branch.

Tests re-run on the branch:

$ python -m pytest tests/test_cli.py::test_cli_exports_latex -q
1 passed in 3.29s

$ python -m pytest tests/test_cli.py -q
2 failed, 55 passed in 4.79s

The two failures are test_cli_help and test_cli_convert, and they are environment-only: my venv installs [convert-core,extract-core,format-pdf,format-office,format-opendocument,format-web,format-latex,format-email,cli,feat-chunking] plus CPU torch, so docling_ibm_models and the service-client extra are missing. I checked out main at d2283add in the same venv and got the identical two failures, so they are not from this PR.

Not verified, stated plainly: (1) convert-remote --to latex end to end, since I have no docling-serve instance here that advertises latex — that is still the known gap in the PR body; (2) compiling an emitted .tex with a real LaTeX engine, since there is no TeX distribution in this sandbox. The --to latex output is byte-compared against docling-core's own goldens rather than typeset.

@cau-git
cau-git merged commit c4b0fc7 into docling-project:main Aug 31, 2026
26 checks passed
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.

3 participants