10.2 Entering Formulas in LaTeX

 < Day Day Up > 



10.2 Entering Formulas in LaTeX

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:

  • r2 = x21 + x22 + x23

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

You can display multiple script indices as shown below:

  • Tabc

    $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:

Tabc

    $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:

    $\frac{x}{y}$ 

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

    $\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:

    $\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. Table 10.1 shows some examples of LaTeX commands for special characters.

Table 10.1: 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. Thenames 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:

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

Here is the same integral shown in display math mode:

    $$\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:

    $\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:

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:

    \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 Table 10.2.

Table 10.2: Commands Used in Math Mode

Style

TeX Name

Rendering

Roman

\mathrm{AbC}

AbC

Italic

\mathit{AbC}

AbC

Bold

\mathbf{AbC}

AbC

Fraktur

\mathfr{AbC}

A bC

Sans serif

\mathsf{AbC}

AbC

Typewriter

\mathtt{AbC}

AbC

Calligraphic

\mathcal{AbC}

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:

    $\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.



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net