Entering formulas in LaTeX

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

As mentioned earlier in this chapter, most authors use a macro package such as LaTeX for preparing documents. LaTeX provides a number of high-level commands for entering mathematical notation. These commands make LaTeX a very compact and expressive markup language for describing mathematical expressions. This section provides a quick review of the LaTeX syntax for entering formulas.

In LaTeX, there are two main modes for displaying mathematics:

  • Math mode: for formulas embedded in text. To enter formulas in this mode, you enclose them in $...$, \(...\), or \begin{math}...\end{math}.
  • Display math mode: for formulas shown in a separate paragraph and in the center of the page. To enter formulas in this mode, you enclose them in $$...$$, \[...\], or \begin{displaymath}...\end{displaymath}.

In addition, a variant of the display math mode, called equation mode, automatically adds a number to the equation. In this mode, you indicate formulas by wrapping them in the text \begin{equation}...\end{equation}.

The following sections cover some of the commands for common mathematical constructs.

Scripts and indices

The caret (^) is used for superscripts, and the underscore (_) for subscripts:

Scripts and indices: example 1

$r^2=x_1^2 + x_2^2 + x_3^2$

You can display multiple script indices as shown below:

Scripts and indices: example 2

$T^{a}_{bc}$

In the above expression, the base is followed by pairs of matched subscripts and superscripts. The members of each pair appear vertically aligned in the displayed expression.

The order of the subscript or superscript within the pair is not relevant. For example, the above tensor can also be represented as follows:

$T{_bc)^{a}$

Fractions and radicals

Fractions are represented by the command \frac{}{}, where the first argument is the numerator and the second is the denominator. Here is an example:

Fractions and radicals: example 1

$\frac{x}{y}$

Square roots are represented by \sqrt{}, as shown here:

Fractions and radicals: example 2

$\sqrt{x+1}$

The optional argument can be used to indicate roots other than square roots. For example, a cube root would be written as shown below:

Fractions and radicals: example 3

$\sqrt[3]{x+1}$

Operators and symbols

A large number of extended characters and mathematical symbols have special names. They can be inserted using a command of the form \name. The list of supported characters includes uppercase and lowercase Greek letters as well as operators, arrows, and other symbols. The following table shows some examples of LaTeX commands for special characters.

Table: LaTeX commands for special characters.

Character LaTeX command

π

\pi

Γ

\Gamma

\infty

\rightarrow

\leq

\cup

\bigcup

\subseteq

Several packages, such as amsymb, define additional symbols used in specialized areas of mathematics. You can insert these symbols in a document by loading the appropriate package.

LaTeX includes commands, such as \sin, \cos, \exp, and \log, to represent common functions. The names of such functions are displayed in an upright font and an extra space is added before their arguments.

The commands \int, \sum, and \product represent the integral, summation, and product symbols, respectively. You can specify the upper and lower limits for these symbols using the standard ^ and _ notation used for subscripts and superscripts. These operators are displayed differently depending on whether you choose math mode or display math mode. In math mode, the symbol appears smaller and the limits are shown as subscripts and superscripts. In display math mode, the symbol is shown in a slightly larger size and the limits are shown as underscripts and overscripts.

Here is an example of an integral in math mode:

Operators and symbols: example 1

$\int_0^\pi {\sin(x)\thinsp dx}$

Here is the same integral shown in display math mode:

Operators and symbols: example 2

$$\int_0^\pi {\sin(x)\thinsp dx}$$

In the above examples, the \thinsp command inserts a thin space between the function and the differential, which is conventional for integrals. You can insert blank spaces of specified sizes using the commands \negthinsp, \thinsp, \medsp, \thicksp, \quad, and \qquad. The first four of these can also be entered using the equivalent shorthand notation \!, \,, \:, and \;.

The command \space{h} {d} {w} inserts a blank space of height h, depth d, and width w. The command \phantom renders its contents invisibly. The \space and \phantom commands correspond to the MathML elements mspace and mphantom, respectively.

Delimiters and accents

You can use the commands \left and \right before delimiters, such as parentheses, brackets, and braces. This makes the delimiters stretchable, so they automatically expand to cover their contents. Note that to use curly brackets as delimiters, you must escape them as \{ and \}, since by default they are interpreted as enclosing arguments.

The following example uses \left and \right to indicate delimiters:

Delimiters and accents: example 1

$\left(\frac{1}{1+x^2}\right )^5$

The commands \bar, \hat, \check, \tilde, \vec, and \dot place an accent with a one-character width over their argument, as shown here:

\bar{A}

\hat{A}

\check{A}

\tilde{A}

\vec{A}

Ȧ

\dot{A}

To make the first five of these accents stretchable, use their wide versions: \widebar{}, \widehat{}, \widecheck{}, \widetilde{}, and \widevec{}.

To place a stretchable brace over or under an expression, use the commands \overbrace{} and \underbrace{}. The commands \overset{}{} and \underset{}{} place the first argument over the second argument. You can also enter lowered, centered, diagonal, and vertical ellipses using the commands \ldots, \cdots, \ddots, and \vdots, respectively.

Here is an example involving a centered ellipse:

Delimiters and accents: example 2

\overset{\text{$n$ terms}}{\overbrace{1+2+\cdots+n}}

Entering text

You can enter text in math mode in a specific style by using one of the commands shown in the following table.

Table: Commands used in math mode.

Style TeX name

Roman

\mathrm{AbC}

Italic

\mathit{AbC}

Bold

\mathbf{AbC}

Fraktur

\mathfr{AbC}

Sans serif

\mathsf{AbC}

Typewriter

\mathtt{AbC}

Calligraphic

\mathcal{AbC}

You can also insert text in the middle of an equation using the \text{} command, which is similar to the MathML element mtext.

Matrices, tables, and arrays

Matrices, tables, and arrays are represented using the \array{} command. The elements of the array are specified in its argument using a double backslash (\\) to separate rows and an ampersand (&) to separate any two entries in a row, as you can see here:

Matrices, tables, and arrays

$\left(\array{a & b \\ c & d}\right$

In the above example, the \left and \right commands are used to place stretchable brackets around the elements of the matrix.

   

<< back next >>

 

 

 

Tipp der data2type-Redaktion:
Zum Thema MathML bieten wir auch folgende Schulungen zur Vertiefung und professionellen Fortbildung an:

 

Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.


CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America