Book Image

LaTeX Beginner's Guide - Second Edition

By : Stefan Kottwitz
4 (1)
Book Image

LaTeX Beginner's Guide - Second Edition

4 (1)
By: Stefan Kottwitz

Overview of this book

LaTeX is high-quality open source typesetting software that produces professional prints and PDF files. It's a powerful and complex tool with a multitude of features, so getting started can be intimidating. However, once you become comfortable with LaTeX, its capabilities far outweigh any initial challenges, and this book will help you with just that! The LaTeX Beginner's Guide will make getting started with LaTeX easy. If you are writing mathematical, scientific, or business papers, or have a thesis to write, this is the perfect book for you. With the help of fully explained examples, this book offers a practical introduction to LaTeX with plenty of step-by-step examples that will help you achieve professional-level results in no time. You'll learn to typeset documents containing tables, figures, formulas, and common book elements such as bibliographies, glossaries, and indexes, and go on to manage complex documents and use modern PDF features. You'll also get to grips with using macros and styles to maintain a consistent document structure while saving typing work. By the end of this LaTeX book, you'll have learned how to fine-tune text and page layout, create professional-looking tables, include figures, present complex mathematical formulas, manage complex documents, and benefit from modern PDF features.
Table of Contents (16 chapters)

Understanding how LaTeX reads our input

Before we continue writing, let's look at how LaTeX understands what we type:

  • Besides simple alphabet characters, we can directly type (or copy and paste) accented characters, such as ä, ü, and ö, as well as further characters from other languages, such as Greek or Russian.
  • A space in the input code will appear as a space in the output document. Several consecutive spaces are treated as one space.
  • An end of a line in the source code is treated as a space.
  • An empty line in the source code is treated as a paragraph break.

There are some characters with special meanings:

  • A backslash, \, starts a LaTeX command or a LaTeX macro.
  • Curly braces and square brackets are used for command arguments.
  • A dollar sign, $, starts and ends math mode, which we will explore in Chapter 9, Writing Math Formulas.
  • A percent sign, %, tells LaTeX to ignore the rest of the line.

Let's expand upon that last point: the percent sign introduces a comment. Everything following a percent sign until the end of the line will be ignored by LaTeX and won't be printed out. This enables you to insert notes into your document. It's often used in LaTeX templates to inform the user of what the template does or requires the user to do at a certain point. Note that the end of the line, normally behaving as a space, will also be ignored after a percent sign.

Easing experimenting by trial and error

If you want to disable a command temporarily, it may be favorable to insert a percent sign instead of deleting the command. That way, you're able to undo this change easily by removing the percent sign.

If that is how the percent sign works, what should we do if we want to write 100% in our text? And what about the other special symbols? Let's figure out how to solve that issue in the next section.

Printing out special symbols

Common text mostly contains uppercase and lowercase letters, digits, and punctuation characters that you can simply type into your editor. However, some characters are reserved for LaTeX commands and cannot be used directly. We already encountered such characters, including the percent sign and curly braces. To fix this issue, there are LaTeX commands to print such symbols.

We will write a very short example printing out an amount of dollars and a percent number, along with some other symbols:

  1. Create a new document and enter the following lines:
    \documentclass{article}
    \begin{document}
    Statement \#1:
    50\% of \$100 equals \$50.
    More special symbols are \&, \_, \{ and \}.
    \end{document}
  2. Click the Typeset button to compile the document.
  3. Check out the output:
Figure 2.2 – Special symbols

Figure 2.2 – Special symbols

By putting a backslash before a special symbol, we turned it into a LaTeX command. The only purpose of this commend is to print out that symbol.

Printing the backslash

You may be wondering how to print a backslash. The command for printing a backslash is \textbackslash. If you would like to know what \\ might be used for, it is used as a shortcut for a line break. That may seem a bit odd, but line breaks occur frequently whereas backslashes are rarely needed in the output, therefore this shortcut has been chosen.

There's a wealth of symbols that we can use for math formulas, chess notation, zodiac signs, music scores, and more. We don't need to deal with those symbols for now, but we shall return to that subject in Chapter 9, Writing Math Formulas, when we will need symbols to typeset math formulas.

Now that we know how to enter pure text, let's find out how we can format it.