I am currently working on a project (in Python) that requires a PDF report to be compiled from various results. These results are stored as variables and inserted into a copy of the .tex by substituting keywords throughout the .tex file, using the following:
replacements = {'TITLEPLACEHOLDER':experiment_name}
with open(latex_file) as infile, open(latex_file_output, 'w') as outfile:
for line in infile:
for src, target in replacements.items():
line = line.replace(src, target)
outfile.write(line)
After that I have a .tex file with my substitutions, let's call the file "my-latex-file-copy.tex'.
In the same folder as the new .tex file there is a .bib which is imported into the .tex, and an IMAGES folder with various images inserted into the .tex.
At this point I am stuck, I need to compile a PDF using the new .tex, which will include the .bib and the images. The output directory for this PDF is declared previously as a string.
I thought that doing the following would work:
replacements = {'TITLEPLACEHOLDER':experiment_name}
doc = Document()
with open(latex_file) as infile, open(latex_file_output, 'w') as outfile:
for line in infile:
for src, target in replacements.items():
line = line.replace(src, target)
outfile.write(line)
doc.append(NoEscape(outfile))
doc.generate_pdf(clean_tex=False,silent=True,compiler='pdflatex')
But unfortunately it either creates a PDF containing the same text as in the .tex file (unfortmatted) or returns the following error:
CalledProcessError: Command '['pdflatex', '--interaction=nonstopmode', 'C:\\Users\\me\\Documents\\University\\project\\predict\\default_filepath.tex']' returned non-zero exit status 1.
Any help would be muchly appreciated :)