JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.24k stars 287 forks source link

[Question] How can I just compile an existing TeX document? #350

Open MartinThoma opened 2 years ago

MartinThoma commented 2 years ago

I am currently looking at different options to generate nice PDF documents. I like the approach of PyLaTeX and I wondered if one can use PyLaTeX to compile an existing TeX document.

I could also do something like this:

import os

os.system("pdflatex thedoc.tex")

But then I might need to deal with intermediate files (log / aux / ...) and having to re-run (e.g. for bibtex / indices / references).

Is it possible to compile an existing TeX document via PyLaTeX? Where are limitations?

marijnschraagen commented 2 years ago

PyLaTeX itself uses Latexmk for compiling (see https://mg.readthedocs.io/latexmk.html). This is a build tool that automatically performs reruns if needed, runs bibtex etc., and can clean up temporary files afterwards. You can use Latexmk with the relevant options via os.system("latexmk thedoc.tex"). Of course you can also bypass Python and run Latexmk directly from any programming language/toolchain/shell script that fits the use case.

mmarras commented 2 years ago

Possible duplicate of #321