I need to automate reports programmatically by using a template. The template contains the standard textes and structure. When a report should be generated, there are a few values to be included in the document. The positions of these values are given by the template. I would like to manage this with two files: a template file and a value file, which should be merged together. I tried it this way:

In the value file:


In the template file:

This is the article \ArticleNo

How can I import these variables, so they can be used in the template? There are about 20 Variables to be written. I generate the file, which contains the values, by python and compile it programmatically.

  • 1
    Welcome to TeX.SX! What about \input{values.tex} within the preamble? – TeXnician Oct 31 '17 at 13:15

Instead of importing the value file into the template, you could do it the other way around. Then compile the value file. With this, once the template is written, you don't have to touch it anymore. And you'll get pdfs named after the value files. You just need to add the line \input{template} at the end of your report file.





This is the article \ArticleNo

Then compiling report_x.tex will give you report_x.pdf.

  • Thank you very much! This is going to solve my Problem. I always tried to Input the values... but I didn't think of doing it the other way round. – traceurSaimn Nov 1 '17 at 7:41

I did the same thing to automate the cover page generation of the books i write .. in the file bookInfo.tex I define book parameters with commands like (for example)

\def\bookTitle {Quantum Mechanics}
\def\bookSubTitle {Principles and Applications}
\def\bookEdition {2n edition}

and in the cover.tex I simply write

\textbf {\color{bookTitleColor}{\bookTitle}}\blackink\\
\LARGE \color{bookTitleColor}{\bookSubTitle}\blackink\\
\LARGE \bookEdition}

where the bookTitleColor is defined in bookInit.tex also with the command


In this way, i change only these values and the cover page of the book is updated automatically after compilation. I hope this is what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.