Book Image

LaTeX Cookbook

By : Stefan Kottwitz
Book Image

LaTeX Cookbook

By: Stefan Kottwitz

Overview of this book

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise. With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily. Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.
Table of Contents (19 chapters)
LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Writing a letter


Letters have a specific structure. Commonly, they have an addressee field at a fixed position, which should be visible in the envelope window. It also should show a back address, of yourself as the sender. An opening text and a closing phrase are usual elements, and you may add fold marks and enclosures.

How to do it...

We will use a KOMA-Script class, which has been specifically designed for letters, named scrlttr2. Take a look at the following steps:

  1. Use the scrlttr2 class, activate the address field and fold marks using the options as follows, and align the sender's address to the right:

    \documentclass[addrfield=true,foldmarks=true,
      fromalign=right]{scrlttr2}
  2. Provide your name and your address using the \setkomavar command:

    \setkomavar{fromname}{Thomas Smith}
    \setkomavar{fromaddress}{123 Blvd \\ City, CC 12345}
  3. Write a date, either \today for today, or any date as text:

    \date{\today}
  4. Begin the document:

    \begin{document}
  5. Open a letter environment, with the recipient's address as an argument:

    \begin{letter}{Agency \\ 5th Avenue \\
                   Capital City, CC 12345}
  6. Start with an opening, and let your letter text follow:

    \opening{Dear Sir or Madam,}
    the actual content of the letter follows.
  7. End with closing words:

    \closing{Yours sincerely}
  8. End the letter environment and the document:

    \end{letter}
    \end{document}
  9. Compile the document. Here is the upper part of the output:

That was pretty easy! You got a fully fledged formal letter with addressing information, an envelope window support, date of writing, phrases, signature, and even fold marks.

Now you can enter the real addresses and the actual letter text.

How it works...

When loading the letter class scrlttr2, we activated the address field, switched on fold marks, and set the options for aligning the sender's address to the right.

The scrlttr2 class is quite different from other classes, so it has a special interface. Using the \setkomavar command, we set the content of class variables, similar to the \renewcommand command. Here, we set the name and address. The KOMA-Script manual explains all the available variables. As mentioned in the recipe Writing a book, you can open it by typing the texdoc scrguien command in Command Prompt, or online at http://texdoc.net/pkg/scrguien.

We used a letter environment for the actual content, including the opening and closing phrases. The address is a mandatory argument for that environment. You can have several letter environments in a single document.

There's more...

For improving input and hyphenation, and for changing the font, take a look at the first recipe in Chapter 2, Tuning the Text.

Let's take a look at some letter specific options.

Separating paragraphs

Instead of indenting the beginnings of paragraphs, you can indicate a paragraph break with an empty line instead. For this, simply add the following option to the comma-separated list of class options at the beginning:

parskip=full

Use the parskip=half option for less space between paragraphs.

Changing the signature

If you would like to use a signature that is different from your specified name for the address, you can modify the corresponding variable content in the preamble:

\setkomavar{signature}{Thomas}

It would be indented. You can get it left-aligned by specifying the following code:

\renewcommand{\raggedsignature}{\raggedright}

The preceding code also belongs to the preamble.

Adding enclosures

If you wish to add enclosures to your letter, it's a common practice to mention them. You can do this by inserting an \encl command right before the \end{letter} command:

\encl{Curriculum vitae, certificates}

You can change the default encl: if you like by modifying the corresponding variable before calling the \encl option:

\setkomavar*{enclseparator}{Attached}

We used the starred version, \setkomavar*, which modifies the description of a variable instead of its content, which actually is :, that is, a colon followed by a space.