Reader small image

You're reading from  LaTeX Beginner's Guide - Second Edition

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801078658
Edition2nd Edition
Tools
Right arrow
Author (1)
Stefan Kottwitz
Stefan Kottwitz
author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz

Right arrow

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.

Previous PageNext Page
You have been reading a chapter from
LaTeX Beginner's Guide - Second Edition
Published in: Oct 2021Publisher: PacktISBN-13: 9781801078658
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime

Author (1)

author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz