adr
file?Tests on empty fields are simply tests on an empty argument. Unlike tests on specific contents, which are preferably performed with \Ifstr
, the test on an empty field is therefore better performed with \IfArgIsEmpty
. Both statements are provided by package scrbase
and are therefore automatically available when using any KOMA-Script class.
Both statements can thus be used for personalized German serial letters, for example (the example is in German, because German gendering is much more complicated than in English):
\begin{filecontents}{\jobname.adr} % {last name}{first name}{street}{zip code}{city}{gender}{}{abbreviation} \addrentry{Muster}{}{Stra\ss e 1}{12345}{Hier}{}{}{}{TESTA} \addrentry{Nachname}{Peter}{Stra\ss e 2}{54321}{Dort}{m}{}{}{TESTB} \addrentry{}{Petra}{Stra\ss e 3}{98765}{Anderswo}{f}{}{}{TESTC} \addrentry{}{}{Stra\ss e 1}{12345}{Hier}{}{}{}{TESTD} \end{filecontents} \documentclass{scrlttr2} \usepackage[ngerman]{babel} \usepackage[T1]{fontenc} % Empfänger: #1 = Vorname, #2 = Nachname, #3 = Ersatzbezeichnung \newcommand*{\IntelliName}[3]{% \IfArgIsEmpty{#1}{% \IfArgIsEmpty{#2}{#3}{ #2}% }{ #1% \IfArgIsEmpty{#2}{}{\ #2}% }% } \renewcommand{\addrentry}[9]{% \begin{letter}{% \IntelliName{#2}{#1}{Bewohner:in}\\ #3\\ #4 #5% } \opening{Hallo\IntelliName{#2}{#1}{},} wir teilen Ihnen hiermit mit, dass das Haus demnächst mit einer Videoklingelanlage. Jede\Ifstr{#6}{m}{r Bewohner}{% \Ifstr{#6}{f}{ Bewohnerin}{ Person, die hier wohnt,}% } erhält einen eigenen Zugangscode für unsere geniale SmartPhone-App \texttt{WatchMeEveryWhery}. \closing{Mit freundlichen Grüßen}\ \end{letter} } \setkomavar{subject}{Neue Klingelanlage} \setkomavar{fromname}{Ausbeuter \& Co.} \setkomavar{fromaddress}{Wir-kriegen-alle-Weg 666\\77777 Freibeuting} \setkomavar{signature}{Ihre Hausverwaltung} \let\raggedsignature\raggedright \begin{document} \input{\jobname.adr} \end{document}
In the definition of \IntelliName
, the \IfArgIsEmpty
tests are used to ensure that meaningful addressing can take place regardless of whether the last name and first name fields in the adr
file are actually assigned. If both the first name (argument 1) and the last name (argument 2) are empty, the replacement name from argument 3 is used.
With the nested \Ifstr
test in the letter text, a gender-specific naming is ensured. For this purpose, the sixth argument of \addrentry
is evaluated accordingly.