I'm up to use LaTeX for writing my letters, invoices, other stuff and I'm nearly finished with setting up my templates using the KOMA class scrlttr2
. One thing remains…
I got an address-file where I put my contacts/clients like this:
\adrentry{name}{surname}{address}{phone}{F1}{F2}{comment}{LABELNAME}
Then I use it in my main .tex
file:
...
\input{contacts.adr}
\begin{letter}{\LABELNAME}
....
This is working pretty well, but I want to have a special formatting. Depending on F1, where I put the gender of my contact, I want to have "Mr." or "Mrs." or if not present "Company" right before the name. And I can't figure out how that could be done. I've read a lot of examples showing how to generate a bulk letter but can't transform this to my case of just formatting one address instead of them all.
But maybe that points someone else in the right direction so he can help me out?
\renewcommand*{\adrentry}[8]{
\begin{letter}{#2 #1\\#3}
\if #5m \opening{Dear Mr. #1,} \fi
\if #5w \opening{Dear Mrs. #1,} \fi
Some text in which the arguments can be used as well.
\closing{Bye,}
\end{letter}
}
So what I want to achieve is something that might look like this (It's not working, I know):
\renewcommand*{\adrentry}[8]{
\if #5m Mr. #2 #1\\ \fi
\if #5w Mrs. #2 #1\\ \fi
\if #5c #2\\#6\\ \fi % It's a company, #6 states the contact person
#3
}
Any ideas, links, etc.?
Oh boy, I hope you can follow and thanks in advance!
EDIT:
It follows a minimal working example showing the state that I have, not including the feature described above (since I o not know how to do that 😉
The address file (contacts.adr) including a person and a company:
\adrentry{Cool Company Inc.}{}{Companystreet 21\\12345 Elsewhere}{}{c}{Mr. Tim Tailor}{}{CCI}
\adrentry{Meier}{Michael}{Meierstreet 34\\45636 Nowhere}{}{m}{}{}{MEIER}
The tex file using scrlttr2:
\documentclass[
paper=a4,
version=last,
enlargefirstpage,
fontsize=11pt]{scrlttr2}
\usepackage[english,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
% global koma vars
\setkomavar{fromname}{Max Myname}
\setkomavar{fromphone}{+49\,123\,45678910}
\setkomavar{fromemail}{mymail@gmail.com}
\setkomavar{backaddress}{Max Myname, Some Street 12, 012345 Somewhere}
\setkomavar{fromaddress}{Some Street 12\\012345 Somewhere}
\begin{document}
\setkomavar{subject}{The subject}
\setkomavar{date}{\today}
\setkomavar{place}{Dresden}
\setkomavar{yourmail}{1.1.2013}
\setkomavar{yourref}{76/54/321}
\setkomavar{myref}{123/456/789}
\input{contacts.adr}
\begin{letter}{\MEIER}
\opening{Dear Mr. Meier}
\lipsum[7]
\closing{Sincerely yours}
\end{letter}
\end{document}
The above produces
Michael Meier
Meierstreet 34
45636 Nowhere
and
Cool Company Inc.
Companystreet 21
12345 Elsewhere
But I'd like it to produce
Mr.
Michael Meier
Meierstreet 34
45636 Nowhere
and
Cool Company Inc.
Mr. Tim Tailor
Companystreet 21
12345 Elsewhere
Best Answer
Nice question; I solved it by changing
\addrentry
and adding something innocuous to\begin{letter}
, that will do nothing if a subsequent\makeopening
command doesn't follow.In the usual
\addentry
command, the last argument is used to build a control sequence that stores the address lines. I add also the building of an opening line, which forMEIER
is stored in\opening@MEIER
. This command is called by\makeopening
(using the hook added before).Here are the two letters (relevant parts only)