# Generating two different pdfs out of one tex file?

Is there a way to automatically generate two different pdf files with one run of pdflatex?

I would like to produce a german and an english version of the same document. I know how to define a command acting as a switch (e.g. \germanenglish), which I could use like

\germanenglish{Deutscher Text}{english text}


Yet the best solution for now is defining a command in the preamble used to switch the switch. More convenient, however, would be a way of having latex produce

filename_de.tex
filename_en.tex


with one click.

• Something like my answer here: tex.stackexchange.com/questions/258687/… ??? – user31729 Sep 15 '15 at 18:36
• Of course, there are other answers as well, not only mine ... ;-) – user31729 Sep 15 '15 at 18:41
• @ChristianHupfer -- of course two different pdf files can be generated from a single tex file, but, as far as i've seen, not at the same time, which is what is asked here. if "one run of pdflatex" could be considered to be what would be produced with two different arara directives specified at the top of the file, then yes, but that would actually be two separate runs of pdflatex, just done in one continuous "session". (nit picker at work.) – barbara beeton Sep 15 '15 at 19:08
• Related: Polyglot note-keeping? – Mike Renfro Sep 15 '15 at 20:13

Thanks to the comments, I was able to solve the problem as follows:

\ProvidesPackage{altlang}[2015/09/20 Alternative Languages Package]

\RequirePackage{xstring}
\RequirePackage{etoolbox}

\newtoggle{alternativelanguage}
\togglefalse{alternativelanguage}

\IfSubStr*{\jobname}{\secondlang}{%
\toggletrue{alternativelanguage}%
}{%
\togglefalse{alternativelanguage}%
}

\newcommand{\lang}[2]{\iftoggle{alternativelanguage}{#2}{#1}}

\newcommand{\producealternativelanguage}{%
\iftoggle{alternativelanguage}{}{%
\StrBefore*{\jobname}{\firstlang}[\substrbefore]
\StrBehind*{\jobname}{\firstlang}[\substrbehind]
\edef\myjobname{\substrbefore\secondlang\substrbehind}
\def\space{ }
\immediate\write18{pdflatex --jobname=\myjobname\space \jobname.tex}
}
}

\endinput


Usage:

%% file myfile_de.tex
...
\newcommand{\firstlang}{_de}
\newcommand{\secondlang}{_en}

\usepackage{altlang}

...
\producealternativelanguage

\begin{document}
\lang{deutscher Text}{english text}
\end{document}

%% pdflatex-ing with shell-escape being enabled
%% will produce myfile_de.tex and myfile_en.tex