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}
letter
class and pdftk.