Anda di halaman 1dari 5

12/27/12

LaTeX:Commands - AoPSWiki

Art of Problem Solving


LaTeX:Commands
LaTeX About - LaTeX on AoPS - Downloads - Basics - Math - Examples - Pictures - Layout - Symbols Commands - Packages - Help This page introduces various useful commands for rendering math in LaTeX, as well as instructions for building your own commands.

From AoPSWiki

Search Wiki Go Search

Page Tools
Page Discussion View source History

Contents
1 Math Commands 1.1 Exponents and Subscripts 1.2 Fractions 1.3 Radicals 1.4 Sums, Products, Limits and Logarithms 1.5 Mods 1.6 Combinations 1.7 Trigonometric Functions 1.8 Calculus 1.9 Overline and Underline 1.10 Other Functions 2 Matrices 3 Text Styles in Math Mode 4 How to Build Your Own Commands 5 See Also

Personal tools
Log in

Navigation
Main page C ommunity portal Recent changes Random page Help

Toolbox
What links here Related changes Special pages Printable version Permanent link

Math Commands
Here are some commonly used math commands in LaTeX.

Exponents and Subscripts


Make exponents in LaTeX with ^ and subscripts with _ as shown in the examples below. SymbolCommand SymbolCommand 2^2 a_i 2^{23} n_{i-1} a^{i+1}_3 x^{3^2} 2^{a_i} 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). 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 or when you really want or .

SymbolCommand \frac{1}{2}

Fractions

\frac{2}{x+2} \frac{1+\frac{1}{x}}{3x + 2} Most fractions look better in display mode (remember, you don't need the declaration if you are in \[...\] or $$...$$ mode.) You can use \dfrac as a shortcut: SymbolCommand \dfrac{1}{2} \dfrac{2}{x+2} \dfrac{1+\frac{1}{x}}{3x + 2}

Use \cfrac for continued fractions: Symbol Command \cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}}}

www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands

1/5

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

LaTeX:Commands - AoPSWiki

Radicals

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 calculus section.) Click here for a few other commands which take 'bottom' parts. Symbol Command \sum_{i=1}^{\infty}\frac{1}{i} \prod_{n=1}^5\frac{n}{n-1} \lim_{x\to\infty}\frac{1}{x} \log_n n^2 Some of these are prettier in display mode: Symbol Command \sum_{i=1}^{\infty}\frac{1}{i} \prod_{n=1}^5\frac{n}{n-1} \lim_{x\to\infty}\frac{1}{x} Note that we can use sums, products, and logarithms without _ or ^ modifiers. SymbolCommand \sum\frac{1}{i} \frac{n}{n-1} \log n^2 \ln e Symbol Command 9\equiv 3 9\equiv 3 9\equiv 3 9\equiv 3

Mods
\bmod{6} \pmod{6} \mod{6} \pod{6}

SymbolCommand \binom{9}{3} \binom{n-1}{r-1} These often look better in display mode: Symbol Command \dbinom{9}{3} \dbinom{n-1}{r-1}

Combinations

SymbolCommandSymbolCommandSymbolCommand \cos \sin \tan \sec \csc \cot \arccos \arcsin \arctan \cosh \sinh \tanh \coth Here are a couple examples: Symbol Command \cos^2 x +\sin^2 x = 1 \cos 90^\circ = 0

Trigonometric Functions

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. Symbol Command \frac{d}{dx}\left(x^2\right) = 2x \int 2x\,dx = x^2+C \int^5_1 2x\,dx = 24

www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands

2/5

12/27/12

LaTeX:Commands - AoPSWiki

\int^5_1 2x\,dx = 24 \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

SymbolCommand \overline{a+bi} \underline{431}

Overline and Underline Other Functions

SymbolCommandSymbolCommandSymbol Command \arg \deg \det \dim \exp \gcd \hom \inf \ker \lg \liminf \limsup \max \min \Pr \sup

Some of these functions take 'bottom' parts just like sums and limits. Some render differently in display mode and regular math mode. SymbolCommandSymbol CommandSymbolCommand \dim_x \gcd_x \inf_x \liminf_x \min_x \limsup_x \Pr_x \max_x \sup_x

Matrices
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:
Tecaatrsi plnma $(lmd) o te h hrceitc oyoil f\aba$ f h $ \ie 3 mti 3 tms $ arx \ [ \et lf( \ei{ra}cc bgnary{c} a&b&c\ \ d&e&f\ \ g&h&i\n{ra} edary \ih)] rgt\ i gvnb teeuto s ie y h qain \ f\aba [ (lmd) =\et lf| \ei{ra}cc bgnary{c} \aba-a&- &- \ lmd b c \ - &\aba-e&- \ d lmd f \ - &- &\aba-i\n{ra} g h lmd edary \ih|\ rgt.]

More simply, we can use the shortcut commands in the amsmath package:
Tecaatrsi plnma $(lmd) o te h hrceitc oyoil f\aba$ f h $ \ie 3 mti 3 tms $ arx \ [ \ei{mti} bgnparx a&b&c\ \ d&e&f\ \ g&h&i \n{mti}\ edparx ] i gvnb teeuto s ie y h qain \ f\aba [ (lmd) =\ei{mti} bgnvarx \aba-a&- &- \ lmd b c \ - &\aba-e&- \ d lmd f \ - &- &\aba-i g h lmd \n{mti}\ edvarx.]

You can read more about how the array command works here (it works the same as tabular). We can also use this environment to typeset any mathematics that calls for multiple columns, such as funky function definitions like this one:
\ fx =\et{\ei{ra}l} [ () lf\ bgnary{l

www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands

3/5

12/27/12
x7&\bxi $<x}\ + mo{f 5 $;\ x23&\bxi $3\ex\e5}\ ^mo{f l l $;\ - &\bxi $ <-$.edary \ih.\ x mo{f x 3}\n{ra} rgt ]

LaTeX:Commands - AoPSWiki

But it would be better to use the cases environment and \text command that the amsmath package provides:
\ [ fx =\ei{ae} () bgncss x7&\eti $<x} \ + tx{f 5 $; \ x23&\eti $3\ex\e5}\ ^tx{f l l $;\ - &\eti $ <-$. x tx{f x 3} \n{ae} edcss \ ]

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. SymbolCommand SymbolCommand SymbolCommand SymbolComand \mathbb{R} \mathbf{R} \mathcal{R} \mathfrak{R} \mathbb{Z} \mathbf{Z} \mathcal{Z} \mathfrak{Z} \mathbb{Q} \mathbf{Q} \mathcal{Q} \mathfrak{Q} If you're persistent, you can dig a few more out of this document. 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 $$...$$ or $...$ mode, where breaking up the math mode would force the output on to a new line entirely. So
$n2+5=3\et s w hv }=p5$ $^ 0tx{ o e ae n\m$

gives

How to Build Your Own Commands


The command \newcommand is used to create your own commands. We'll start with an example:
\ouetls[1t{ril} dcmncas1p]atce \spcaeasah ueakg{mmt} \dpgwdh85n pfaeit .i \dpghih 1i pfaeegt 1n \ecmad\ei[]\rc1{1} nwomn{rc}1{fa{}#} \ecmad\yo}2{sr{12#^} nwomn{hpt[]\qt#^+22} \ecmad\bt[]\qt3{1} nwomn{cr}1{sr[]#} \ei{ouet bgndcmn} Tercpoa o 2i $rc{}. h eircl f s \ei2$ Tehptns hslnt $hpt3{}. h yoeue a egh \yo{}4$ Imsc o wiig`\akls$qt3{} altetm,js t gt$cr{}. ' ik f rtn $bcsahsr[]2' l h ie ut o e \bt2$ \n{ouet eddcmn}

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:
\ouetls[1t{ril} dcmncas1p]atce \spcaeasah ueakg{mmt} \dpgwdh85n pfaeit .i \dpghih 1i pfaeegt 1n \ecutrpo_u} nwone{rbnm \ecutrpo_u}1 stone{rbnm{} \ecmad\rb[]\isi \isi\rbcpo_u}\tpone{rbnm # nwomn{po}5{bgkp bgkpaai{rbnm.secutrpo_u} 1 \a\oaera[]mdkpA\#\fl B\#\fl prnpgbek4\esi . 2hil . 3hil C\#\fl D\#\fl E\NT} . 4hil . 5hil . OA

www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands

4/5

12/27/12
\ei{ouet bgndcmn} \rbWa i $+$}4{}6{} po{ht s 22?{}5{}7 \rbWa i $sr{0}?{1{0{}1 po{ht s \qt10$}8}1}9{}

LaTeX:Commands - AoPSWiki

\rbEaut $dslytl\u_n1^ify\rc1{^}. po{vlae \ipasyesm{=}\nt fa{}n2$} {\ipasyefa{}e$ {\ipasyefa{}\i$ $dslytl\rc1{}} $dslytl\rc2{p}} {\ipasyefa{p^}8$ {\ipasyefa{p^}6$ $dslytl\rc\i3{}} $dslytl\rc\i2{}} \n{ouet eddcmn}

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
Next: Packages Previous: Symbols Retrieved from "http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands" Category: LaTeX This page was last modified on 25 July 2012, at 17:06. This page has been accessed 875,546 times. Privacy policy About AoPSWiki Disclaimers

www.artofproblemsolving.com/Wiki/index.php/LaTeX:Commands

5/5

Anda mungkin juga menyukai