Large Language Models

LaTeX Notes

Published 2024-01-31. Last modified 2024-02-08.
Time to read: 4 minutes.

This page is part of the llm collection.

Most math markup systems have some kind of relationship with TeX and LaTeX. These are my LaTeX notes for the MathLive flavor of LaTeX.

TeX is a language created by Donald Knuth to typeset documents attractively and consistently. Knuth started writing the TeX typesetting engine in 1977 to explore the potential of the digital printing equipment that was beginning to infiltrate the publishing industry at that time, in the hope that he could reverse the trend of deteriorating typographical quality that he saw affecting his own books and articles.

While TeX is a programming language in the sense that it is Turing complete, its main job is to serve as a markup language for describing how your document should look. The fine control TeX offers over document structure and formatting makes it a powerful and formidable tool.

TeX is renowned for being extremely stable, for running on many different kinds of computers, and for being virtually bug free. The version numbers of TeX are converging toward the mathematical constant π, with the current version number being 3.1415926.

LaTeX (pronounced either "Lah-tech" or "Lay-tech") is a set of macros for TeX created by Leslie Lamport. Its purpose is to simplify the TeX typesetting, especially for documents containing mathematical formulae. Within the typesetting system, its name is formatted as LATEX.

TeX is both a typographical and logical markup language, and one has to take account of both issues when writing a TeX document. In creating LaTeX, Lamport's aim was to split those two aspects. A typesetter can make a template and the writers can focus on LaTeX logical markup despite perhaps not know anything about typesetting.

In addition to the commands and options LaTeX offers, many other authors have contributed extensions, called packages or styles, which you can use for your documents. Many of these are bundled with most TeX/LaTeX software distributions; more can be found in the Comprehensive TeX Archive Network (CTAN).
 – From Wikipedia

Terms

Many terms can be entered just as they are. However, you can group terms by enclosing them within { curly braces }. For example, x_t and x_{t} both render the t as a subscript: x_t.

You need to group terms in order to modify them as a unit. For example, x_t-1 renders as x_t-1, which is fine, unless you meant x_{t-1}, which would be written as x_{t-1}.

Symbols

Greek

Greek symbols can be upper and lower case. Each font displays greek and other LaTeX symbols differently, and some fonts do not display them at all. You can specify them several ways; in decreasing order of preference:

  1. LaTeX symbol, e.g. \alpha (\alpha), \Alpha (\Alpha), \overline\alpha} (\overline\alpha})
  2. HTML entity name, e.g. α (α), Α (Α)

Special

Tilde (~) is written as \sim, which displays as \sim

Operators

  • Addition and subtraction: 1+2-3 renders as 1+2-3
  • Multiplication and division: 1*2/3 renders as 1*2/3
  • Exponentiation: x^y renders as x^y
  • Subscript: x_y renders as x_y. If you need an extra-low subscript, use two underbars: x__{T-1} renders as x__{T-1}.
  • Log and natural log: \log_{2}{42} renders as \log_{2}{42}
  • Natural log: \ln(42) renders as \ln(42)

Arrows

Many types of arrows are possible, including annotated arrows:

  • \rightarrow (\rightarrow)
  • \longrightarrow{x} (\longrightarrow{x})

Functions

These symbols are like functions in that they require parameters.

Fractions

Use \frac to write a fraction. It accepts two parameters, the numerator and the denominator. For example:

g(x) = \frac{1}{x} renders as g(x) = \frac{1}{x}

Integrals

Write as \int^upperBound_lowerBound or \int_lowerBound^upperBound.
For example:

F(x) = \int^a_b \frac{1}{3}x^3 and F(x) = \int^b_a \frac{1}{3}x^3 both render as:

F(x) = \int^b_a \frac{1}{3}x^3

Parentheses, Brackets, etc.

To cause LaTeX to display a large left parenthesis write \left(; for a large right parenthesis, write \right). Every \left requires a matching \right, however the type of parenthese or bracket that follows need not match. This works for all types of parentheses and brackets, including (), [] and {}.

For example, the following are all legal. They usually automatically adjust their height according to the content that follows.

  • (...) displays as (...)
  • \left(...\right) displays as \left(...\right)
  • \left[...\right] displays as \left[...\right]
  • \left\{...\right\} displays as \left\{...\right\}
  • \left(...\right] displays as \left(...\right]
  • \left\{...\right) displays as \left\{...\right)

Note: left and right squiggly braces must be escaped when used with \left or \right, as shown above.

You can also use angled parentheses (<> or \langle\rangle) (\langle\rangle) and a vertical bar (|). For example:

  • \langle...\rangle displays as \langle...\rangle
  • <...> displays as <...>
  • \left\langle...\right\rangle displays as \left\langle...\right\rangle
  • \left<...\right> displays as \left<...\right>
  • |...| displays as |...|
  • \left|...\right| displays as \left|...\right|

If you do not want a closing parenthesis displayed, use a period (.) after \right. For example (again, note the squiggly parenthesis must be escaped):

  • \left(...\right. displays as \left(...\right.
  • \left\{...\right. displays as \left\{...\right.
  • \left[...\right. displays as \left[...\right.
  • \left<...\right. displays as \left<...\right.
  • \left\langle...\right. displays as \left\langle...\right.
  • \left|...\right. displays as \left|...\right.

The parentheses will usually resize automatically, but you can also manually control the size of round parentheses only with \big(, \Big(, \bigg(, and \Bigg(. These do not need to be matched. For example:

  • \big(...\big) displays as \big(...\big)
  • \Big(...\Big) displays as \Big(...\Big)
  • \bigg(...\bigg) displays as \bigg(...\bigg)
  • \Bigg(...\Bigg) displays as \Bigg(...\Bigg)

For better spacing, use \bigl(, \bigr), \Bigl(, \Bigr), \biggl(, \biggr), \Biggr)

  • \bigl(...\bigr) displays as \bigl(...\bigr)
  • \Bigl(...\Bigr) displays as \Big(...\Bigr)
  • \biggl(...\biggr) displays as \biggl(...\biggr)
  • \Biggl(...\Biggr) displays as \Biggl(...\Biggr)

The other types of parentheses do not work with big variants:

  • \big{\big] displays as \big{\big]
  • \bigl{\bigr] displays as \bigl{\bigr]
  • \Big{\Big] displays as \Big{\Big]
  • \bigg{\bigg] displays as \bigg{\bigg]
  • \Bigg{\Bigg] displays as \Bigg{\Bigg]

Complete documentation is here.

Alignment and Line Breaks

Locations within a series of equations can be horizontally aligned by wrapping them within \begin{aligned} ... \end{aligned} and marking the alignment points with an ampersand (&).

Two backslashes (\\) causes a line break. This is useful for a sequence of statements that must be evaluated in order (top to bottom).

Aligned equal signs
\begin{aligned}
x & = 1 + 2 \\
longVariableName & = x * 3
\end{aligned}

Renders as:

\begin{aligned} x & = 1 + 2 \\ longVariableName & = x * 3 \end{aligned}

You could also write the ampersands without introducing extra whitespace by using {squiggly parentheses}:

Aligned equal signs without extra whitespace
\begin{aligned}
x&{=} 1 + 2 \\
longVariableName&{=} x * 3
\end{aligned}

Renders as:

\begin{aligned} x&{=} 1 + 2 \\ longVariableName&{=} x * 3 \end{aligned}

CSS Classes and Rotated Text

CSS Classes can be applied to portions of an equation by using \class{className}.

Here is a CSS class called rotate270 that rotates text counterclockwise 90 degrees:

Shell
.rotate270 {
  display: inline-block;
  font-size: 12pt;
  transform: rotate(270deg) translate(0, 130%);
  transform-origin: 50% 50%;
}

In the above CSS style, note that the order of the translation operations is significant:

  1. rotate(270deg)
  2. translate(0, 130%) # TODO this X,Y displacement vector was fudged for demonstration purposes. Need a more accurate expression.

Use the CSS class to rotate text in front of a large open square bracket like this:

MathLive content
\displaystyle
\class{rotate270}{\text{Repeat until t=1}}\left[\begin{aligned}
\\
x&{=} 1 + 2 \\
y&{=} x * 3 \\
\end{aligned}

Renders as:

\displaystyle \class{rotate270}{\text{Repeat until t=1}}\left[\begin{aligned} \\ x&{=} 1 + 2 \\ y&{=} x * 3 \\ \end{aligned}

References



* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.