About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-12-13: Ebook sale (12th December 2024 – 1st January 2025): cybercrime fiction short stories Unsocial Media and Smile for the Camera free; crime fiction short story The Briefcase free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.

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.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs