Using PyLaTex, I currently I have to use an editor to strip off the "/usepackage{'foo'}" statements from PyLaTex generated external tex files so that my main.py file can open, read and append each external tex file. The resulting main.tex file builds correctly but I don't want to have to manually edit the external tex files each time. Any ideas?

  • 1
    We can't be sure without an MWE, but it sound like declaring \renewcommand*\usepackage[2][]{} for the time of the inclusion should work.
    – schtandard
    Jun 20, 2019 at 22:07

1 Answer 1


If anyone else has this problem:

You can generate tex files not only from pylatex.Document, but also from pylatex.Section objects (Section,Subsection,..):

 def generate_tex(self, your_title, path, file_name):
    section = Section(your_title)

    # add some stuff to your section

    file_path = os.path.join(path, file_name)

This generates a tex file without package declarations.


%your added stuff

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .