Difference between revisions of "LaTeX:Commands"

(Math Commands)
m (Math Commands)
 
(90 intermediate revisions by 45 users not shown)
Line 3: Line 3:
 
This page introduces various useful commands for rendering math in LaTeX, as well as instructions for building your own commands.
 
This page introduces various useful commands for rendering math in LaTeX, as well as instructions for building your own commands.
  
==Math Commands==
+
===Subscripts and Superscripts===
Here are some commonly used math commands in LaTeX.
+
Subscripts and superscripts (such as exponents) can be made using the underscore _ and caret ^ symbols respectively.
===Exponents and Subscripts===
 
Make exponents in LaTeX with ^ and subscripts with _ as shown in the examples below.
 
 
{| class="latextable"
 
{| class="latextable"
 
!Symbol !! Command!!Symbol!!Command
 
!Symbol !! Command!!Symbol!!Command
Line 18: Line 16:
 
| <math>2^{a_i}</math>||2^{a_i}||<math>2^a_i</math>||2^a_i
 
| <math>2^{a_i}</math>||2^{a_i}||<math>2^a_i</math>||2^a_i
 
|}
 
|}
Notice that we can apply both a subscript and an exponent at the same time, and that we can use {} to tell LaTeX what to apply a subscript or exponent to (compare the examples on the bottom row).
+
Notice that we can apply both a subscript and a superscript at the same time. For subscripts or superscripts with more than one character, you must surround what you want to be the exponent/superscript with curly braces. For example, <code>x^10</code> produces <math>x^10</math>, while <code>x^{10}</code> produces <math>x^{10}</math>.
 
 
Finally, notice that we use {} for any exponent or subscript that is more than one character. You have to do so, or you'll end up with <math>2^234</math> or <math>a^i+1_n-1</math> when you really want <math>2^{234}</math> or <math>a^{i+1}_{n-1}</math>.
 
  
 +
==Math Commands==
 +
Here are some commonly used math commands in <math>\LaTeX</math>:
 
===Fractions===
 
===Fractions===
 
{|class="latextable"
 
{|class="latextable"
 
!Symbol!!Command
 
!Symbol!!Command
 
|-
 
|-
|<math>\textstyle \frac{1}{2}</math>||\frac{1}{2}
+
|<math>\frac {1}{2}</math>||\frac{1}{2} or \frac12
 
|-
 
|-
| <math>\textstyle \frac{2}{x+2}</math>||\frac{2}{x+2}
+
| <math>\frac{2}{x+2}</math>||\frac{2}{x+2}
 
|-
 
|-
| <math>\textstyle \frac{1+\frac{1}{x}}{3x + 2}</math>||\frac{1+\frac{1}{x}}{3x + 2}
+
| <math>\frac{1+\frac{1}{x}}{3x + 2}</math>||\frac{1+\frac{1}{x}}{3x + 2}
 
|}
 
|}
Most fractions look better in (remember, you don't need the declaration if you are in <nowiki>\[...\]</nowiki> or <nowiki>$$...$$</nowiki> mode.) You can use \dfrac as a shortcut:
+
 
 +
 
 +
Notice that with fractions with a 1-digit numerator and a 1-digit denominator, we can simply group the numerator and the denominator together as one number. However, for fractions with either a numerator or a denominator that requires more than one character (or if the numerator starts with a letter), you need to surround everything in curly brackets.
 +
 
 +
Use \cfrac for continued fractions.
 
{| class="latextable"
 
{| class="latextable"
!Symbol !! Command
+
!Expression !! Command
|-
 
|<math>\frac{1}{2}</math>||\dfrac{1}{2}
 
|-
 
| <math>\frac{2}{x+2}</math>||\dfrac{2}{x+2}
 
|-
 
| <math>\frac{1+\frac{1}{x}}{3x + 2}</math>||\dfrac{1+\frac{1}{x}}{3x + 2}
 
|}
 
Use \cfrac for continued fractions:
 
{| class="latextable"
 
!Symbol !! Command
 
 
|-
 
|-
 
|<math>\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}</math>||\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}
 
|<math>\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}</math>||\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}
Line 53: Line 45:
 
!Symbol !! Command
 
!Symbol !! Command
 
|-
 
|-
|<math>\sqrt{2}</math>||\sqrt{2}
+
|<math>\sqrt{3}</math>||\sqrt{3}
 
|-
 
|-
 
| <math>\sqrt{x+y}</math>||\sqrt{x+y}
 
| <math>\sqrt{x+y}</math>||\sqrt{x+y}
Line 65: Line 57:
  
 
===Sums, Products, Limits and Logarithms===
 
===Sums, Products, Limits and Logarithms===
We use _ to get the 'bottom' parts of summations, products, and limits, as well as the subscripts of logarithms. We use ^ to get the 'top' parts of sums and products. (Integration symbols work the same way, as you'll see in the [[LaTeX:Commands#Calculus|calculus section]].) Click here for a few [[LaTeX:Commands#Other_Functions|other commands]] which take 'bottom' parts.
+
Use the commands \sum, \prod, \lim, and \log respectively. To denote lower and upper bounds, or the base of the logarithm, use _ and ^ in the same way they are used for subscripts and superscripts. (Lower and upper bounds for integrals work the same way, as you'll see in the [[LaTeX:Commands#Calculus|calculus section]])
 
{| class="latextable"
 
{| class="latextable"
 
!Symbol !! Command
 
!Symbol !! Command
Line 74: Line 66:
 
|-
 
|-
 
| <math>\textstyle \lim_{x\to\infty}\frac{1}{x}</math>||\lim_{x\to\infty}\frac{1}{x}
 
| <math>\textstyle \lim_{x\to\infty}\frac{1}{x}</math>||\lim_{x\to\infty}\frac{1}{x}
 +
|-
 +
| <math>\textstyle \lim\limits_{x\to\infty}\frac{1}{x}</math>||\lim\limits_{x\to\infty}\frac{1}{x}
 
|-
 
|-
 
|<math>\textstyle \log_n n^2</math>||\log_n n^2
 
|<math>\textstyle \log_n n^2</math>||\log_n n^2
Line 93: Line 87:
 
|<math>\sum\frac{1}{i}</math>||\sum\frac{1}{i}
 
|<math>\sum\frac{1}{i}</math>||\sum\frac{1}{i}
 
|-
 
|-
| <math>\frac{n}{n-1}</math>||\frac{n}{n-1}
+
| <math>\prod\frac{n}{n-1}</math>||\prod\frac{n}{n-1}
 
|-
 
|-
 
| <math>\textstyle \log n^2</math>||\log n^2
 
| <math>\textstyle \log n^2</math>||\log n^2
Line 117: Line 111:
 
!Symbol !! Command
 
!Symbol !! Command
 
|-
 
|-
|<math>\scriptstyle\binom{9}{3}</math>||\binom{9}{3}
+
|<math>\scriptstyle\binom{1}{1}</math>||\binom{1}{1}
 
|-
 
|-
 
| <math>\scriptstyle\binom{n-1}{r-1}</math>||\binom{n-1}{r-1}
 
| <math>\scriptstyle\binom{n-1}{r-1}</math>||\binom{n-1}{r-1}
Line 131: Line 125:
  
 
===Trigonometric Functions===
 
===Trigonometric Functions===
 +
 +
Most of these are just the abbreviation of the trigonometric function with simply a backslash added before the abbreviation.
 +
 
{| class="latextable"
 
{| class="latextable"
 +
 
!Symbol!!Command!!Symbol!!Command!!Symbol!!Command
 
!Symbol!!Command!!Symbol!!Command!!Symbol!!Command
 
|-
 
|-
Line 154: Line 152:
  
 
===Calculus===
 
===Calculus===
Below are examples of calculus rendered in LaTeX. Most of these commands have been introduced before. Notice how definite integrals are rendered (and the difference between regular math and display mode for definite integrals). The , in the integrals makes a small space before the dx.
+
Below are examples of calculus expressions rendered in LaTeX. Most of these commands have been introduced before. Notice how definite integrals are rendered (and the difference between inline math and display mode for definite integrals). The \, in the integrals makes a small space before the dx.
 
{| class="latextable"
 
{| class="latextable"
 
!Symbol !! Command
 
!Symbol !! Command
Line 161: Line 159:
 
|-
 
|-
 
| <math>\int 2x\,dx = x^2+C</math>||\int 2x\,dx = x^2+C
 
| <math>\int 2x\,dx = x^2+C</math>||\int 2x\,dx = x^2+C
|-
 
| <math>\int^5_1 2x\,dx = 24</math>||\int^5_1 2x\,dx = 24
 
 
|-
 
|-
 
| <math>\int^5_1 2x\,dx = 24</math>||\int^5_1 2x\,dx = 24
 
| <math>\int^5_1 2x\,dx = 24</math>||\int^5_1 2x\,dx = 24
Line 171: Line 167:
 
|}
 
|}
  
===Overline and Underline===
+
== LaTeX ==
 
 
{| class="latextable"
 
!Symbol !! Command
 
|-
 
|<math>\overline{a+bi}</math>||\overline{a+bi}
 
|-
 
| <math>\underline{431}</math>||\underline{431}
 
|}
 
 
 
 
===Other Functions===
 
===Other Functions===
 
{| class="latextable"
 
{| class="latextable"
Line 195: Line 182:
 
| <math>\textstyle\max</math>||\max||<math>\textstyle\min</math>||\min||<math>\Pr</math>||\Pr
 
| <math>\textstyle\max</math>||\max||<math>\textstyle\min</math>||\min||<math>\Pr</math>||\Pr
 
|-
 
|-
| <math>\sup</math>||\sup
+
| <math>\sup</math>||\sup||<math>\smiley</math>||\smiley
 
|}
 
|}
Some of these functions take 'bottom' parts just like sums and limits. Some render differently in display mode and regular math mode.
+
Some of these commands take subscripts in the same way sums, products, and logarithms do. Some render differently in display mode and inline math mode.
 
{| class="latextable"
 
{| class="latextable"
 
!Symbol !! Command!!Symbol !! Command!!Symbol !! Command
 
!Symbol !! Command!!Symbol !! Command!!Symbol !! Command
Line 206: Line 193:
 
|-
 
|-
 
| <math>\textstyle\min_x</math>||\min_x||<math>\Pr_x</math>||\Pr_x||<math>\sup_x</math>||\sup_x
 
| <math>\textstyle\min_x</math>||\min_x||<math>\Pr_x</math>||\Pr_x||<math>\sup_x</math>||\sup_x
 +
|-
 +
|
 
|}
 
|}
  
==Matrices==
+
==Matrices and Arrays==
We can build an array or matrix with the \begin{array} command, and use \left and \right to properly size the delimiters around the matrix:
+
We can typeset a matrix with the <code>matrix</code>, <code>bmatrix</code>, <code>pmatrix</code>, or <code>vmatrix</code> environments. The letters b, p, and v refer to the delimiters around the matrix (brackets, parentheses, and vertical bars, respectively). For example, the following code
<pre><nowiki>
+
 
The characteristic polynomial $f(\lambda)$ of the
+
<pre>
$3 \times 3$ matrix
+
\begin{bmatrix}
\[
+
1 & 2 & 3 \\
\left(
+
4 & 5 & 6 \\
 +
\end{bmatrix}
 +
</pre>
 +
produces the following <math>2 \times 3</math> matrix:
 +
\begin{bmatrix}
 +
1 & 2 & 3 \\
 +
4 & 5 & 6 \\
 +
\end{bmatrix}
 +
 
 +
 
 +
 
 +
We can also use the <code>array</code> environment to typeset arrays. For example, the following code
 +
<pre>
 
\begin{array}{ccc}
 
\begin{array}{ccc}
 
a & b & c \\
 
a & b & c \\
 
d & e & f \\
 
d & e & f \\
g & h & i \end{array}
+
g & h & i  
\right)\]
+
\end{array}
is given by the equation
 
\[ f(\lambda)
 
= \left|
 
\begin{array}{ccc}
 
\lambda - a & -b & -c \\
 
-d & \lambda - e & -f \\
 
-g & -h & \lambda - i \end{array}
 
\right|.\]
 
</nowiki>
 
 
</pre>
 
</pre>
More simply, we can use the shortcut commands in the amsmath package:
+
produces the following <math>3 \times 3</math> array:
<pre><nowiki>
+
 
The characteristic polynomial $f(\lambda)$ of the
+
<math>\begin{array}{ccc}
$3 \times 3$ matrix
 
\[
 
\begin{pmatrix}
 
 
a & b & c \\
 
a & b & c \\
 
d & e & f \\
 
d & e & f \\
g & h & i
+
g & h & i  
\end{pmatrix} \]
+
\end{array}</math>
is given by the equation
 
\[ f(\lambda)
 
= \begin{vmatrix}
 
\lambda - a & -b & -c \\
 
-d & \lambda - e & -f \\
 
-g & -h & \lambda - i
 
\end{vmatrix}.\]
 
</nowiki></pre>
 
You can read more about how the array command works [[LaTeX:Layout|here]] (it works the same as tabular) and more about using \left and \right [[LaTeX:Commands |here]].
 
 
 
We can also use this environment to typeset any mathematics that calls for multiple columns, such as funky function definitions like this one:
 
<pre><nowiki>
 
\[ f(x) = \left\{ \begin{array}{ll}
 
x+7 & \mbox{if $5< x$};\\
 
x^2-3 & \mbox{if $-3 \le x \le 5$};\\
 
-x & \mbox{if $x < -3$}.\end{array} \right. \]
 
</nowiki></pre>
 
 
 
But it would be better to use the cases environment and \text command that the amsmath package provides:
 
<pre><nowiki>
 
\[
 
f(x) = \begin{cases}
 
x+7 & \text{if $5< x$}; \\
 
x^2-3 & \text{if $-3 \le x \le 5$};\\
 
-x & \text{if $x < -3$}.
 
\end{cases}
 
\]
 
</nowiki></pre>
 
  
 
==Text Styles in Math Mode==
 
==Text Styles in Math Mode==
You can render letters in various styles in math mode. Below are examples; you should be able to use these with any letters. The \mathbb requires the amsfonts package to be include in your document's preamble.
+
You can render letters in various styles in math mode. Below are examples; you should be able to use these with any letters. The \mathbb requires the amsfonts package to be included in your document's preamble. Do not try to do \mathbb{year}. You'll get <math>\mathbb{year}</math>, and that looks nothing like it!
 
{| class="latextable"
 
{| class="latextable"
!Symbol !! Command!!Symbol !! Command!!Symbol !! Command!!Symbol !! Comand
+
!Symbol !! Command!!Symbol !! Command!!Symbol !! Command!!Symbol !! Command
 +
|-hcal{R}<math>||\mathcal{R}||</math>\mathfrak{R}<math>||\mathfrak{R}
 
|-
 
|-
|<math>\mathbb{R}</math>||\mathbb{R}||<math>\mathbf{R}</math>||\mathbf{R}||<math>\mathcal{R}</math>||\mathcal{R}||<math>\mathfrak{R}</math>||\mathfrak{R}
+
| [[Image:Mathbb1.gif]]||\mathbb{Z}||</math>\mathbf{Z}<math>||\mathbf{Z}||</math>\mathcal{Z}<math>||\mathcal{Z}||</math>\mathfrak{Z}<math>||\mathfrak{Z}
 
|-
 
|-
| [[Image:Mathbb1.gif]]||\mathbb{Z}||<math>\mathbf{Z}</math>||\mathbf{Z}||<math>\mathcal{Z}</math>||\mathcal{Z}||<math>\mathfrak{Z}</math>||\mathfrak{Z}
+
| </math>\mathbb{Q}<math>||\mathbb{Q}||</math>\mathbf{Q}<math>||\mathbf{Q}||</math>\mathcal{Q}<math>||\mathcal{Q}||</math>most useful in <nowiki>$$...$$</nowiki> or <nowiki>$...$</nowiki> mode, where breaking up the math mode would force the output on to a new line entirely.
|-
+
So
| <math>\mathbb{Q}</math>||\mathbb{Q}||<math>\mathbf{Q}</math>||\mathbf{Q}||<math>\mathcal{Q}</math>||\mathcal{Q}||<math>\mathfrak{Q}</math>||\mathfrak{Q}
+
<pre><nowiki>
|}
+
$$n^2 + 5 = 30\text{ so we have }n=\pm5$$
If you're persistent, you can dig a few more out of [ftp://ftp.ams.org/pub/tex/doc/amsfonts/amsfndoc.pdf this document].
+
</nowiki></pre>
 
 
If you want to drop a little bit of text in the middle of math mode, you can use the \text command. The \text command is most useful in <cmath>...</cmath> or <math>...</math> mode, where breaking up the math mode would force the output on to a new line entirely.
 
 
 
<cmath>n^2 + 5 = 30\text{ so we have }n=\pm5</cmath>
 
 
 
 
gives
 
gives
  
Line 308: Line 265:
 
The hypotenuse has length $\hypot{3}{4}$.
 
The hypotenuse has length $\hypot{3}{4}$.
  
I'm sick of writing `$\backslash$sqrt[3]{2}' all the time, just to get $\cbrt{2}$.
+
I'm sick of writing `$\backslash$sqrt[3]{2}$' all the time, just to get $\cbrt{2}$.
  
 
\end{document}
 
\end{document}
Line 337: Line 294:
 
\prob{What is $\sqrt{100}$?}{81}{10}{9}{1}
 
\prob{What is $\sqrt{100}$?}{81}{10}{9}{1}
  
\prob{Evaluate $\displaystyle\sum_{n=1}^\infty \frac{1}{n^2}$.}
+
\prob{Evaluate $\sum_{n=1}^\infty \frac{1}{n^2}$.}
{$\displaystyle\frac{1}{e}$} {$\displaystyle\frac{2}{\pi}$}
+
{$\frac{1}{e}$} {$\frac{2}{\pi}$}
{$\displaystyle\frac{\pi^3}{8}$} {$\displaystyle\frac{\pi^2}{6}$}
+
{$\frac{\pi^3}{8}$} {$\frac{\pi^2}{6}$}
  
 
\end{document}
 
\end{document}

Latest revision as of 20:55, 22 September 2024

LaTeX
About - Getting Started - Diagrams - Symbols - Downloads - Basics - Math - Examples - Pictures - Layout - Commands - Packages - Help

This page introduces various useful commands for rendering math in LaTeX, as well as instructions for building your own commands.

Subscripts and Superscripts

Subscripts and superscripts (such as exponents) can be made using the underscore _ and caret ^ symbols respectively.

Symbol Command Symbol Command
$2^{2}$ 2^2 $\textstyle a_i$ a_i
$\textstyle 2^{23}$ 2^{23} $\textstyle n_{i-1}$ n_{i-1}
$a^{i+1}_3$ a^{i+1}_3 $x^{3^2}$ x^{3^2}
$2^{a_i}$ 2^{a_i} $2^a_i$ 2^a_i

Notice that we can apply both a subscript and a superscript at the same time. For subscripts or superscripts with more than one character, you must surround what you want to be the exponent/superscript with curly braces. For example, x^10 produces $x^10$, while x^{10} produces $x^{10}$.

Math Commands

Here are some commonly used math commands in $\LaTeX$:

Fractions

Symbol Command
$\frac {1}{2}$ \frac{1}{2} or \frac12
$\frac{2}{x+2}$ \frac{2}{x+2}
$\frac{1+\frac{1}{x}}{3x + 2}$ \frac{1+\frac{1}{x}}{3x + 2}


Notice that with fractions with a 1-digit numerator and a 1-digit denominator, we can simply group the numerator and the denominator together as one number. However, for fractions with either a numerator or a denominator that requires more than one character (or if the numerator starts with a letter), you need to surround everything in curly brackets.

Use \cfrac for continued fractions.

Expression Command
$\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}$ \cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}

Radicals

Symbol Command
$\sqrt{3}$ \sqrt{3}
$\sqrt{x+y}$ \sqrt{x+y}
$\sqrt{x+\frac{1}{2}}$ \sqrt{x+\frac{1}{2}}
$\sqrt[3]{3}$ \sqrt[3]{3}
$\sqrt[n]{x}$ \sqrt[n]{x}

Sums, Products, Limits and Logarithms

Use the commands \sum, \prod, \lim, and \log respectively. To denote lower and upper bounds, or the base of the logarithm, use _ and ^ in the same way they are used for subscripts and superscripts. (Lower and upper bounds for integrals work the same way, as you'll see in the calculus section)

Symbol Command
$\textstyle \sum_{i=1}^{\infty}\frac{1}{i}$ \sum_{i=1}^{\infty}\frac{1}{i}
$\textstyle \prod_{n=1}^5\frac{n}{n-1}$ \prod_{n=1}^5\frac{n}{n-1}
$\textstyle \lim_{x\to\infty}\frac{1}{x}$ \lim_{x\to\infty}\frac{1}{x}
$\textstyle \lim\limits_{x\to\infty}\frac{1}{x}$ \lim\limits_{x\to\infty}\frac{1}{x}
$\textstyle \log_n n^2$ \log_n n^2

Some of these are prettier in display mode:

Symbol Command
$\sum_{i=1}^{\infty}\frac{1}{i}$ \sum_{i=1}^{\infty}\frac{1}{i}
$\prod_{n=1}^5\frac{n}{n-1}$ \prod_{n=1}^5\frac{n}{n-1}
$\lim_{x\to\infty}\frac{1}{x}$ \lim_{x\to\infty}\frac{1}{x}

Note that we can use sums, products, and logarithms without _ or ^ modifiers.

Symbol Command
$\sum\frac{1}{i}$ \sum\frac{1}{i}
$\prod\frac{n}{n-1}$ \prod\frac{n}{n-1}
$\textstyle \log n^2$ \log n^2
$\textstyle \ln e$ \ln e

Mods

Symbol Command
$9\equiv 3 \bmod{6}$ 9\equiv 3 \bmod{6}
$9\equiv 3 \pmod{6}$ 9\equiv 3 \pmod{6}
$9\equiv 3 \mod{6}$ 9\equiv 3 \mod{6}
$9\equiv 3\pod{6}$ 9\equiv 3 \pod{6}

Combinations

Symbol Command
$\scriptstyle\binom{1}{1}$ \binom{1}{1}
$\scriptstyle\binom{n-1}{r-1}$ \binom{n-1}{r-1}

These often look better in display mode:

Symbol Command
$\dbinom{9}{3}$ \dbinom{9}{3}
$\dbinom{n-1}{r-1}$ \dbinom{n-1}{r-1}

Trigonometric Functions

Most of these are just the abbreviation of the trigonometric function with simply a backslash added before the abbreviation.

Symbol Command Symbol Command Symbol Command
$\textstyle \cos$ \cos $\textstyle \sin$ \sin $\textstyle \tan$ \tan
$\sec$ \sec $\textstyle \textstyle \csc$ \csc $\textstyle \cot$ \cot
$\textstyle \arccos$ \arccos $\textstyle \arcsin$ \arcsin $\textstyle \arctan$ \arctan
$\textstyle \cosh$ \cosh $\textstyle \sinh$ \sinh $\textstyle \tanh$ \tanh
$\textstyle \coth$ \coth

Here are a couple examples:

Symbol Command
$\textstyle \cos^2 x +\sin^2 x = 1$ \cos^2 x +\sin^2 x = 1
$\cos 90^\circ = 0$ \cos 90^\circ = 0

Calculus

Below are examples of calculus expressions rendered in LaTeX. Most of these commands have been introduced before. Notice how definite integrals are rendered (and the difference between inline math and display mode for definite integrals). The \, in the integrals makes a small space before the dx.

Symbol Command
$\frac{d}{dx}\left(x^2\right) = 2x$ \frac{d}{dx}\left(x^2\right) = 2x
$\int 2x\,dx = x^2+C$ \int 2x\,dx = x^2+C
$\int^5_1 2x\,dx = 24$ \int^5_1 2x\,dx = 24
$\frac{\partial^2U}{\partial x^2} + \frac{\partial^2U}{\partial y^2}$ \frac{\partial^2U}{\partial x^2} + \frac{\partial^2U}{\partial y^2}
$\frac{1}{4\pi}\oint_\Sigma\frac{1}{r}\frac{\partial U}{\partial n} ds$ \frac{1}{4\pi}\oint_\Sigma\frac{1}{r}\frac{\partial U}{\partial n} ds

LaTeX

Other Functions

Symbol Command Symbol Command Symbol Command
$\arg$ \arg $\textstyle\deg$ \deg $\textstyle\det$ \det
$\dim$ \dim $\textstyle\exp$ \exp $\textstyle\gcd$ \gcd
$\hom$ \hom $\inf$ \inf $\ker$ \ker
$\textstyle\lg$ \lg $\liminf$ \liminf $\limsup$ \limsup
$\textstyle\max$ \max $\textstyle\min$ \min $\Pr$ \Pr
$\sup$ \sup $\smiley$ \smiley

Some of these commands take subscripts in the same way sums, products, and logarithms do. Some render differently in display mode and inline math mode.

Symbol Command Symbol Command Symbol Command
$\dim_x$ \dim_x $\textstyle\gcd_x$ \gcd_x $\inf_x$ \inf_x
$\liminf_x$ \liminf_x $\limsup_x$ \limsup_x $\textstyle\max_x$ \max_x
$\textstyle\min_x$ \min_x $\Pr_x$ \Pr_x $\sup_x$ \sup_x

Matrices and Arrays

We can typeset a matrix with the matrix, bmatrix, pmatrix, or vmatrix environments. The letters b, p, and v refer to the delimiters around the matrix (brackets, parentheses, and vertical bars, respectively). For example, the following code

\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}

produces the following $2 \times 3$ matrix: \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ \end{bmatrix}


We can also use the array environment to typeset arrays. For example, the following code

\begin{array}{ccc}
a & b & c \\
d & e & f \\
g & h & i 
\end{array}

produces the following $3 \times 3$ array:

$\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i  \end{array}$

Text Styles in Math Mode

You can render letters in various styles in math mode. Below are examples; you should be able to use these with any letters. The \mathbb requires the amsfonts package to be included in your document's preamble. Do not try to do \mathbb{year}. You'll get $\mathbb{year}$, and that looks nothing like it!

So
$$n^2 + 5 = 30\text{ so we have }n=\pm5$$

gives

Text1.gif

How to Build Your Own Commands

The command \newcommand is used to create your own commands. We'll start with an example:

\documentclass[11pt]{article}
\usepackage{amsmath}

\pdfpagewidth 8.5in
\pdfpageheight 11in
\newcommand{\reci}[1]{\frac{1}{#1}}
\newcommand{\hypot}[2]{\sqrt{#1^2+#2^2}}
\newcommand{\cbrt}[1]{\sqrt[3]{#1}}

\begin{document}

The reciprocal of 2 is $\reci{2}$.

The hypotenuse has length $\hypot{3}{4}$.

I'm sick of writing `$\backslash$sqrt[3]{2}$' all the time, just to get $\cbrt{2}$.

\end{document}

The \newcommand declarations are in the preamble. Each is of the form

\newcommand{name of new command}[number of arguments]{definition}

The name of the new command, which must begin with a \, is the name you'll use in the document to use the command. The number of arguments is how many inputs will be sent to the command. The definition is just normal LaTeX code, with #1, #2, #3, etc., placed where you want the inputs to go when the new command is called.

New commands can be used for all sorts of purposes, not just for making math commands you'll use a lot easier to call. For example, try this:

\documentclass[11pt]{article}
\usepackage{amsmath}

\pdfpagewidth 8.5in
\pdfpageheight 11in
\newcounter{prob_num}
\setcounter{prob_num}{1}
\newcommand{\prob}[5]{\bigskip \bigskip\arabic{prob_num}.\stepcounter{prob_num} #1
\par\nopagebreak[4]\medskip A.\ #2\hfill B.\ #3\hfill
C.\ #4\hfill D.\ #5\hfill E.\ NOTA}

\begin{document}

\prob{What is $2+2$?}{4}{5}{6}{7}

\prob{What is $\sqrt{100}$?}{81}{10}{9}{1}

\prob{Evaluate $\sum_{n=1}^\infty \frac{1}{n^2}$.}
{$\frac{1}{e}$} {$\frac{2}{\pi}$}
{$\frac{\pi^3}{8}$} {$\frac{\pi^2}{6}$}

\end{document}

In the example above, we create a new command called \prob. Each time we call \prob, we supply 5 arguments, one for the question and one for each of the multiple choices.

In the preamble and the definition of \prob, you'll see a few new LaTeX commands:

\newcounter{prob_num} creates a counter variable called prob_num

\setcounter{prob_num}{1} setsprob_num to equal 1.

In the definition of \prob, the \bigskip and \medskip commands create vertical space.

\arabic{prob_num} prints out the current value of the counter prob_num as an arabic numeral.

\stepcounter{prob_num} increments the counter prob_num by 1.

\nopagebreak[4] tells LaTeX not to break the page between the problem and the choices unless it really, really, really has to.

The \hfill commands put roughly equal space between the choices.

Once you build a body of custom commands that you will be using in many LaTeX documents, you should learn about creating your own package so you don't have to copy all your custom commands from document to document.

See Also

Symbol Command Symbol Command Symbol Command Symbol Command