Exercise 7: Writing a Letter using the letter class (Solution)
This is a solution to the more adventurous part of Exercise 7. For the solution to the basic part, just add the sender details using the commands shown below.
\documentclass[12pt]{letter}
\usepackage[a4paper]{geometry}
\usepackage[british]{babel}
\usepackage{datatool}
\DTLloaddb{people}{people.csv}
\DTLloaddb{countries}{country-codes.csv}
% sender details
\name{Mr Big Head}
\signature{Big Head}
\location{Secret Lab of Experimental Stuff}
\address{University of Somewhere\\Some City\\AB3 4YZ}
\telephone{0123456789}
\begin{document}
\newcommand*{\Id}{2}% customer id
\xDTLassignfirstmatch{people}{id}{\Id}{%
\Surname=surname,%
\Forenames=forenames,%
\Title=title,%
\AddressI=address1,%
\AddressII=address2,%
\Town=town,%
\County=county,%
\Postcode=postcode,%
\CountryCode=country%
}
\xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name}
\begin{letter}{ \DTLifnullorempty{\Title}{}{\Title\ }\Forenames\
\Surname\\%
\AddressI\\
\DTLifnullorempty{\AddressII}{}{\AddressII\\}%
\Town\\%
\DTLifnullorempty{\County}{}{\County\\}%
\Postcode\\\CountryName}
\opening{Dear \DTLifnullorempty{\Title}{\Forenames}{\Title} \Surname}
\thispagestyle{firstpage}
This is an imaginary letter.
This is the second paragraph of the letter.
\closing{Yours sincerely}
\ps PS: this is a postscript.
\encl{Photocopy of something interesting\\
Photocopy of something rather dull}
\cc{Prof Important Person\\Dr Bor Ing}
\end{letter}
\end{document}
Download letter.tex or letter.pdf.
