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

Chapter 9: Writing Math Formulas

At the beginning of this book, in Chapter 1, Getting Started with LaTeX, we promised that LaTeX offers excellent quality for mathematical typesetting. Now it's time to prove this. By the end of this chapter, you will be able to write beautiful mathematical texts.

To benefit from LaTeX's math capabilities, we shall now deal with the following:

  • Writing basic formulas
  • Typesetting multi-line formulas
  • Exploring the wealth of math symbols
  • Building math structures

That's a tremendous undertaking—let's tackle it!

Technical requirements

You can use a local LaTeX installation, or you can compile the example code online at https://latexguide.org/chapter-09.

The code is available on GitHub: https://github.com/PacktPublishing/LaTeX-Beginner-s-Guide-2nd-Edition-/tree/main/Chapter_09_-_Writing_Math_Formulas.

In this chapter, we will use the following packages: amsmath, amssymb, geometry, latexsym, and upgreek.

Furthermore, we will briefly discuss these packages: amsthm, dsfont, graphicx, mathtools, ntheorem, siunitx, xits, and zapfino.

You can find further code examples in Chapter 10, Advanced Mathematics of LaTeX Cookbook with compilable code on that book's website at https://latex-cookbook.net/chapter-10.

Writing basic formulas

LaTeX offers three writing modes:

  • Paragraph mode: The text is typeset as a sequence of words in lines, paragraphs, and pages. That's what we used in the previous chapters.
  • Left-to-right mode: The text is a sequence of words, but LaTeX typesets it from left to right without breaking the line. For instance, the argument of \mbox will be typeset in this mode; so \mbox prevents hyphenation.
  • Math mode: Here, LaTeX treats letters as math symbols. That's why they're typeset in italics, which is common practice for variables. A lot of symbols can only be used in math mode. Such symbols are roots, sum signs, relation signs, math accents, arrows, and various delimiters, such as brackets and braces. LaTeX ignores space characters between letters and symbols. Instead, the spacing depends on the type of symbols—spacing of relation signs is different from spacing of opening or closing delimiters. All math expressions require this mode...

Typesetting multi-line formulas

We shall use the amsmath package to typeset a very long formula and a system of equations:

  1. Start a new document on A6 paper size to have a smaller text width, so we can see what happens with line breaks without typing super long formulas:
    \documentclass{article}
    \usepackage[a6paper]{geometry}
  2. Load the amsmath package, and begin the document:
    \usepackage{amsmath}
    \begin{document}
  3. Use the multline environment to span a long equation over three lines. End the lines with a double backslash \\, except the last one:
    \begin{multline}
      \sum = a + b + c + d + e \\
               + f + g + h + i + j \\
               + k + l + m + n
    \end{multline}
    \end{document}
  4. Click on Typeset to compile, and look at the formula:

    Figure 9.16 – A formula spanning three lines

  5. Now we handle a system of equations. Use the gather environment...

Exploring the wealth of math symbols

Let's go beyond writing variables and basic math operators. We may need many symbols for particular purposes: relation signs, unary and binary operators, function-like operators, sum and integral symbols and variants of the latter, arrows, and many more. LaTeX and additional packages offer thousands of symbols for many purposes.

So, let's look at some math symbols and the commands for producing them. We shall cover many standard LaTeX symbols; the latexsym package provides some additional symbols. Even more symbols are accessible using, for instance, the amssymb package.

Binary operation symbols

Besides plus and minus, there are a few more operations:

Figure 9.19 – Binary operation symbols

You need to have \usepackage{latexsym} in your document preamble to be able to use the symbols in the last row here.

Binary relation symbols

Values of expressions might be equal, in which case you just need...

Building math structures

Variables and constants are simple. But there are more complex objects, such as binomial coefficients, vectors, and matrices. We shall figure out how to typeset such structures.

Let's begin with simple arrays.

Creating arrays

For arranging math expressions within a surrounding expression, there's the array environment. We use it exactly like a tabular environment. However, it requires math mode, and all of its entries are made using math mode as well.

For example, we can use variable-sized parentheses around an array:

\[
  A = \left(
    \begin{array}{cc}
      a_{11} & a_{12} \\
      a_{21} & a_{22}
    \end{array}
  \right)
\]

This produces a matrix:

Figure 9.33 – A simple array

There are specific commands for matrices.

Typesetting matrices

The amsmath package provides...

Summary

Now we can write complex math formulas, and we've got the necessary tools to write scientific texts. We worked with the amsmath package, which provides us with many features tailored to traditional mathematical typesetting.

We can now fine-tune math expressions, align and number equations, and use various math symbols from symbol fonts. In the next chapter, we will also work with fonts, in general.

lock icon
The rest of the chapter is locked
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 €14.99/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