Include variables from source file to template

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:

\newcommand{\ArticleNo}{123456}


In the template file:

\begin{document}
This is the article \ArticleNo
\end{document}


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.

• 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.

Example:

report_x.tex:

\newcommand{\ArticleNo}{123456}
\input{template}


template.tex:

\documentclass{article}
\begin{document}
This is the article \ArticleNo
\end{document}


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

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


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

\colorlet{bookTitleColor}{violet}


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.