[Tex/LaTex] Can one TeX file output to multiple PDF files

compilingjobnamepdf

I'd like to be able to create a TeX file that will output multiple PDF files with one compilation. I'm not even sure if this is possible. Here is the setup:

I am writing dozens of cover letters for job applications, and wish for them to all look "personalized". So I defined a function which calls multiple variables, such as the address, name of the institution, open position, etc., and outputs a "personalized" cover letter for each function call. The problem is that compilation of the TeX file outputs just one file. Since I will be submitting all of these files online eventually, I would like each letter to be in its own file. Is there a way to do this at the TeX level?

Best Answer

How do you store this information? You could just have one info-file for each letter

% letter1.adr
\def\toname{Foo}

and

% letter2.adr
\def\toname{Bar}

and then have a main file

% main.tex
\documentclass[addrfield]{scrlttr2}
\input \jobname.adr

\begin{document}
\begin{letter}{\toname}
\opening{Dear \toname, }
 A nice letter.
\end{letter}
\end{document}

Then you can compile all letters from the command line with something like

for %i in (*.adr) do pdflatex -jobname=%i main.tex

The koma bundle also provides tools for more sophisticated address files.

Related Question