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 Answer
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)
section.generate_tex(filepath=file_path)
This generates a tex file without package declarations.
"file_name.tex":
\subsection{your_title}%
%your added stuff
\renewcommand*\usepackage[2][]{}
for the time of the inclusion should work.