Can one TeX file output to multiple PDF files?
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.
Yes it is possible if you enable \write18
(e.g. pdflatex --shell-escape
with MiKTeX). Then you can call pdflatex
again inside your document. An example (the code is not from me). It will generate three documents \jobname1
-\jobname3
:
Case insensitive operating systems (e.g. Windows/MacOS)
\documentclass{article}
\ifx\conditionmacro\undefined
\immediate\write18{%
pdfLaTeX --jobname="\jobname1"
\gdef\string\conditionmacro{1}\string\input\space\jobname
}%
\immediate\write18{%
pdfLaTeX --jobname="\jobname2"
\gdef\string\conditionmacro{2}\string\input\space\jobname
}%
\immediate\write18{%
pdfLaTeX --jobname="\jobname3"
\gdef\string\conditionmacro{3}\string\input\space\jobname
}%
\expandafter\stop
\fi
\begin{document}
\ifnum\conditionmacro=1 Condition is 1\fi
\ifnum\conditionmacro=2 Condition is 2\fi
\ifnum\conditionmacro=3 Condition is 3\fi
\verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}
Case sensitive operating systems (e.g. Linux)
As noted in Martin Heller's comment you need to change this code for case sensitive operating systems to:
\documentclass{article}
\ifx\conditionmacro\undefined
\immediate\write18{%
pdflatex --jobname="\jobname1"
"\gdef\string\conditionmacro{1}\string\input\space\jobname"
}%
\immediate\write18{%
pdflatex --jobname="\jobname2"
"\gdef\string\conditionmacro{2}\string\input\space\jobname"
}%
\immediate\write18{%
pdflatex --jobname="\jobname3"
"\gdef\string\conditionmacro{3}\string\input\space\jobname"
}%
\expandafter\stop
\fi
\begin{document}
\ifnum\conditionmacro=1 Condition is 1\fi
\ifnum\conditionmacro=2 Condition is 2\fi
\ifnum\conditionmacro=3 Condition is 3\fi
\verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}
Edit for lualatex
in newer luatex version \write18 has no special meaning anymore and can't be used like this. You then need the shellesc package which overloads \write
. It also offers a \ShellEscape
which can be used (also with pdflatex) instead of the primitive commands. The example looks then like this.
\documentclass{article}
\usepackage{shellesc}
\ifx\conditionmacro\undefined
\ShellEscape{%
lualatex --jobname="\jobname1"
"\gdef\string\conditionmacro{1}\string\input\space\jobname"
}%
\ShellEscape{%
lualatex --jobname="\jobname2"
"\gdef\string\conditionmacro{2}\string\input\space\jobname"
}%
\ShellEscape{%
lualatex --jobname="\jobname3"
"\gdef\string\conditionmacro{3}\string\input\space\jobname"
}%
\expandafter\stop
\fi
\begin{document}
\ifnum\conditionmacro=1 Condition is 1\fi
\ifnum\conditionmacro=2 Condition is 2\fi
\ifnum\conditionmacro=3 Condition is 3\fi
\verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}
The answer is no, TeX outputs one PDF file.
I'd use a tool to split the PDF files afterwards. pdfpages (TeX) pdfsam, and pdftk should do the trick.