Escolar Documentos
Profissional Documentos
Cultura Documentos
LaTeX/MathematicsWikibooks,openbooksforanopenworld
LaTeX/Mathematics
OneofthegreatestmotivatingforcesforDonaldKnuthwhenhebegandevelopingtheoriginalTeXsystemwastocreatesomethingthat
allowedsimpleconstructionofmathematicalformulae,whilelookingprofessionalwhenprinted.Thefactthathesucceededwasmost
probablywhyTeX(andlateron,LaTeX)becamesopopularwithinthescientificcommunity.TypesettingmathematicsisoneofLaTeX's
greateststrengths.Itisalsoalargetopicduetotheexistenceofsomuchmathematicalnotation.
Ifyourdocumentrequiresonlyafewsimplemathematicalformulas,plainLaTeXhasmostofthetoolsthatyouwillneed.Ifyouare
writingascientificdocumentthatcontainsnumerouscomplicatedformulas,theamsmathpackage[1]introducesseveralnewcommands
thataremorepowerfulandflexiblethantheonesprovidedbyLaTeX.Themathtoolspackagefixessomeamsmathquirksandaddssome
usefulsettings,symbols,andenvironmentstoamsmath.[2]Touseeitherpackage,include:
\usepackage{amsmath}
or
\usepackage{mathtools}
inthepreambleofthedocument.Themathtoolspackageloadstheamsmathpackageandhencethereisnoneedto\usepackage{amsmath}
inthepreambleifmathtoolsisused.
Contents
1Mathematicsenvironments
1.1Inserting"Displayed"mathsinsideblocksoftext
2Symbols
3Greekletters
4Operators
5Powersandindices
6FractionsandBinomials
6.1Continuedfractions
6.2Multiplicationoftwonumbers
7Roots
8Sumsandintegrals
9Brackets,bracesanddelimiters
9.1Automaticsizing
9.2Manualsizing
9.3Typesettingintervals
10Matricesandarrays
10.1Matricesinrunningtext
11Addingtexttoequations
11.1Formattedtext
12Formattingmathematicssymbols
12.1Accents
13Color
14Plusandminussigns
15Controllinghorizontalspacing
16ManuallySpecifyingFormulaStyle
17AdvancedMathematics:AMSMathpackage
17.1Introducingdotsinformulas
17.2Dots
17.3Writeanequationwiththealignenvironment
18ListofMathematicalSymbols
19Summary
20Notes
21Furtherreading
22Externallinks
https://en.wikibooks.org/wiki/LaTeX/Mathematics
1/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Mathematicsenvironments
LaTeXneedstoknowbeforehandthatthesubsequenttextdoesindeedcontainmathematicalelements.ThisisbecauseLaTeXtypesets
mathsnotationdifferentlyfromnormaltext.Therefore,specialenvironmentshavebeendeclaredforthispurpose.Theycanbe
distinguishedintotwocategoriesdependingonhowtheyarepresented:
texttextformulasaredisplayedinline,thatis,withinthebodyoftextwhereitisdeclared,forexample,Icansaythata+a=2a
withinthissentence.
displayeddisplayedformulasareseparatefromthemaintext.
Asmathsrequirespecialenvironments,therearenaturallytheappropriateenvironmentnamesyoucanuseinthestandardway.Unlike
mostotherenvironments,however,therearesomehandyshorthandstodeclaringyourformulas.Thefollowingtablesummarizesthem:
Type
Environment
Inline(withintext)
formulas
math
LaTeXshorthand \(...\)
TeXshorthand
$...$
Displayed
equations
displaymath
Displayedandautomaticallynumberedequations
equation
\[...\]
$$...$$
Comment
equation*(starredversion)suppressesnumbering,butrequires
amsmath
Suggestion:Usingthe$$...$$shouldbeavoided,asitmaycauseproblems,particularlywiththeAMSLaTeXmacros.Furthermore,
shouldaproblemoccur,theerrormessagesmaynotbehelpful.
Theequation*anddisplaymathenvironmentsarefunctionallyequivalent.
Ifyouaretypingtextnormally,youaresaidtobeintextmode,butwhileyouaretypingwithinoneofthosemathematicalenvironments,
youaresaidtobeinmathmode,thathassomedifferencescomparedtothetextmode:
1. Mostspacesandlinebreaksdonothaveanysignificance,asallspacesareeitherderivedlogicallyfromthemathematical
expressions,orhavetobespecifiedwithspecialcommandssuchas\quad
2. Emptylinesarenotallowed.Onlyoneparagraphperformula.
3. Eachletterisconsideredtobethenameofavariableandwillbetypesetassuch.Ifyouwanttotypesetnormaltextwithina
formula(normaluprightfontandnormalspacing)thenyouhavetoenterthetextusingdedicatedcommands.
Inserting"Displayed"mathsinsideblocksoftext
Inorderforsomeoperators,suchas\limor\sumtobedisplayedcorrectlyinsidesomemathenvironments(read$......$),itmightbe
convenienttowritethe\displaystyleclassinsidetheenvironment.Doingsomightcausethelinetobetaller,butwillcauseexponents
andindicestobedisplayedcorrectlyforsomemathoperators.Forexample,the$\sum$willprintasmallerand$\displaystyle\sum$
willprintabiggerone
,likeinequations(ThisonlyworkswithAMSMATHpackage).Itisalsopossibletoforcethisbehaviourfor
allmathenvironmentsbydeclaring\everymath{\displaystyle}attheverybeginning(i.e.before\begin{document}),whichisusefulin
longerdocuments.
Symbols
Mathematicshasmanysymbols!OneofthemostdifficultaspectsoflearningLaTeXisrememberinghowtoproducesymbols.Thereis
ofcourseasetofsymbolsthatcanbeaccesseddirectlyfromthekeyboard:
+=!/()[]<>|':
Beyondthoselistedabove,distinctcommandsmustbeissuedinordertodisplaythedesiredsymbols.Therearemanyexamplessuchas
Greekletters,setandrelationssymbols,arrows,binaryoperators,etc.
Forexample:
https://en.wikibooks.org/wiki/LaTeX/Mathematics
2/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\forallx\inX,\quad\existsy\leq\epsilon
Fortunately,there'satoolthatcangreatlysimplifythesearchforthecommandforaspecificsymbol.Lookfor"Detexify"intheexternal
linkssectionbelow.Anotheroptionwouldbetolookinthe"TheComprehensiveLaTeXSymbolList"intheexternallinkssection
below.
Greekletters
Greeklettersarecommonlyusedinmathematics,andtheyareveryeasytotypeinmathmode.Youjusthavetotypethenameofthe
letterafterabackslash:ifthefirstletterislowercase,youwillgetalowercaseGreekletter,ifthefirstletterisuppercase(andonlythe
firstletter),thenyouwillgetanuppercaseletter.NotethatsomeuppercaseGreekletterslooklikeLatinones,sotheyarenotprovidedby
LaTeX(e.g.uppercaseAlphaandBetaarejust"A"and"B"respectively).Lowercaseepsilon,theta,kappa,phi,pi,rho,andsigmaare
providedintwodifferentversions.Thealternate,orvariant,versioniscreatedbyadding"var"beforethenameoftheletter:
\alpha,\Alpha,\beta,\Beta,\gamma,\Gamma,\pi,\Pi,\phi,\varphi,\Phi
Scrolldownto#ListofMathematicalSymbolsforacompletelistofGreeksymbols.
Operators
Anoperatorisafunctionthatiswrittenasaword:e.g.trigonometricfunctions(sin,cos,tan),logarithmsandexponentials(log,exp),
limits(lim),aswellastraceanddeterminant(tr,det).LaTeXhasmanyofthesedefinedascommands:
\cos(2\theta)=\cos^2\theta\sin^2\theta
Forcertainoperatorssuchaslimits,thesubscriptisplacedunderneaththeoperator:
\lim_{x\to\infty}\exp(x)=0
Forthemodularoperatortherearetwocommands:\bmodand\pmod:
a\bmodb
x\equiva\pmodb
Touseoperatorsthatarenotpredefined,suchasargmax,seecustomoperators
Powersandindices
Powersandindicesareequivalenttosuperscriptsandsubscriptsinnormaltextmode.Thecaret(^alsoknownasthecircumflexaccent)
characterisusedtoraisesomething,andtheunderscore(_)isforlowering.Ifmorethanoneexpressionisraisedorlowered,theyshould
begroupedusingcurlybraces({and}).
https://en.wikibooks.org/wiki/LaTeX/Mathematics
3/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
k_{n+1}=n^2+k_n^2k_{n1}
Forpowerswithmorethanonedigit,surroundthepowerwith{}.
n^{22}
Anunderscore(_)canbeusedwithaverticalbar( )todenoteevaluationusingsubscriptnotationinmathematics:
f(n)=n^5+4n^2+2|_{n=17}
FractionsandBinomials
Afractioniscreatedusingthe\frac{numerator}{denominator}command.(forthosewhoneedtheirmemoriesrefreshed,that'sthetop
andbottomrespectively!).Likewise,thebinomialcoefficient(akatheChoosefunction)maybewrittenusingthe\binomcommand[3]:
\frac{n!}{k!(nk)!}=\binom{n}{k}
Itisalsopossibletousethe\choosecommandwithouttheamsmathpackage:
\frac{n!}{k!(nk)!}={n\choosek}
Youcanembedfractionswithinfractions:
\frac{\frac{1}{x}+\frac{1}{y}}{yz}
Notethatwhenappearinginsideanotherfraction,orininlinetext ,afractionisnoticeablysmallerthanindisplayedmathematics.The
\tfracand\dfraccommands[3]forcetheuseoftherespectivestyles,\textstyleand\displaystyle.Similarly,the\tbinomand\dbinom
commandstypesetthebinomialcoefficient.
Anotherwaytowritefractionsistousethe\overcommandwithouttheamsmathpackage:
{n!\overk!(nk)!}={n\choosek}
Forrelativelysimplefractions,especiallywithinthetext,itmaybemoreaestheticallypleasingtousepowersandindices:
https://en.wikibooks.org/wiki/LaTeX/Mathematics
4/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
^3/_7
Ifthislooksalittle"loose"(overspaced),atightenedversioncanbedefinedbyinsertingsomenegativespace
%runningfractionwithslashrequiresmathmode.
\newcommand*\rfrac[2]{{}^{#1}\!/_{#2}}
\rfrac{3}{7}
Ifyouusethemthroughoutthedocument,usageofxfracpackageisrecommended.Thispackageprovides\sfraccommandtocreate
slantedfractions.Usage:
Take$\sfrac{1}{2}$cupofsugar,\dots
3\times\sfrac{1}{2}=1\sfrac{1}{2}
Take${}^1/_2$cupofsugar,\dots
3\times{}^1/_2=1{}^1/_2
Iffractionsareusedasanexponentcurlybraceshavetobeusedaroundthe\sfraccommand:
$x^\frac{1}{2}$%noerror
$x^\sfrac{1}{2}$%error
$x^{\sfrac{1}{2}}$%noerror
$x^\frac{1}{2}$%noerror
Insomecases,usingthepackagealonewillresultinerrorsaboutcertainfontshapesnotbeingavailable.Inthatcase,thelmodernand
fixcmpackagesneedtobeaddedaswell.
Alternatively,thenicefracpackageprovidesthe\nicefraccommand,whoseusageissimilarto\sfrac.
Continuedfractions
Continuedfractionsshouldbewrittenusing\cfraccommand[3]:
\begin{equation}
x=a_0+\cfrac{1}{a_1
+\cfrac{1}{a_2
+\cfrac{1}{a_3+\cfrac{1}{a_4}}}}
\end{equation}
Multiplicationoftwonumbers
https://en.wikibooks.org/wiki/LaTeX/Mathematics
5/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Tomakemultiplicationvisuallysimilartoafraction,anestedarraycanbeused,forexamplemultiplicationofnumberswrittenonebelow
theother.
\begin{equation}
\frac{
\begin{array}[b]{r}
\left(x_1x_2\right)\\
\times\left(x'_1x'_2\right)
\end{array}
}{
\left(y_1y_2y_3y_4\right)
}
\end{equation}
Roots
The\sqrtcommandcreatesasquarerootsurroundinganexpression.Itacceptsanoptionalargumentspecifiedinsquarebrackets([and
])tochangemagnitude:
\sqrt{\frac{a}{b}}
\sqrt[n]{1+x+x^2+x^3+\ldots}
Somepeoplepreferwritingthesquareroot"closing"itoveritscontent.Thismethodarguablymakesitmoreclearwhatisinthescopeof
therootsign.Thishabitisnotnormallyusedwhilewritingwiththecomputer,butifyoustillwanttochangetheoutputofthesquareroot,
LaTeXgivesyouthispossibility.Justaddthefollowingcodeinthepreambleofyourdocument:
%Newdefinitionofsquareroot:
%itrenames\sqrtas\oldsqrt
\let\oldsqrt\sqrt
%itdefinesthenew\sqrtintermsoftheoldone
\def\sqrt{\mathpalette\DHLhksqrt}
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0
\advance\dimen00.2\ht0
\setbox2=\hbox{\vruleheight\ht0depth\dimen0}%
{\box0\lower0.4pt\box2}}
Thenewstyleisonleft,theoldoneon
right
ThisTeXcodefirstrenamesthe\sqrtcommandas\oldsqrt,thenredefines\sqrtintermsoftheoldone,addingsomethingmore.The
newsquarerootcanbeseeninthepictureontheleft,comparedtotheoldoneontheright.Unfortunatelythiscodewon'tworkifyou
wanttousemultipleroots:ifyoutrytowrite
as\sqrt[b]{a}afteryouusedthecodeabove,you'lljustgetawrongoutput.Inother
words,youcanredefinethesquarerootthiswayonlyifyouarenotgoingtousemultiplerootsinthewholedocument.
AnalternativepieceofTeXcodethatdoesallowmultiplerootsis
\usepackage{letltxmacro}
\makeatletter
\let\oldr@@t\r@@t
\def\r@@t#1#2{%
\setbox0=\hbox{$\oldr@@t#1{#2\,}$}\dimen0=\ht0
\advance\dimen00.2\ht0
\setbox2=\hbox{\vruleheight\ht0depth\dimen0}%
{\box0\lower0.4pt\box2}}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][\]{\oldsqrt[#1]{#2}}
https://en.wikibooks.org/wiki/LaTeX/Mathematics
6/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\makeatother
$\sqrt[a]{b}\quad\oldsqrt[a]{b}$
Howeverthisrequiresthe\usepackage{letltxmacro}package
Sumsandintegrals
The\sumand\intcommandsinsertthesumandintegralsymbolsrespectively,withlimitsspecifiedusingthecaret(^)andunderscore
(_).Thetypicalnotationforsumsis:
\sum_{i=1}^{10}t_i
or
\displaystyle\sum_{i=1}^{10}t_i
Thelimitsfortheintegralsfollowthesamenotation.It'salsoimportanttorepresenttheintegrationvariableswithanuprightd,whichin
mathmodeisobtainedthroughthe\mathrm{}command,andwithasmallspaceseparatingitfromtheintegrand,whichisattainedwith
the\,command.
\int_0^\infty\mathrm{e}^{x}\,\mathrm{d}x
Therearemanyother"big"commandswhichoperateinasimilarmanner:
\sum
\prod
\coprod
\bigoplus
\bigotimes
\bigodot
\bigcup
\bigcap
\biguplus
\bigsqcup
\bigvee
\bigwedge
\int
\oint
\iint[3]
\iiint[3]
\iiiint[3]
\idotsint[3]
Formoreintegralsymbols,includingthosenotincludedbydefaultintheComputerModernfont,trytheesintpackage.
The\substackcommand[3]allowstheuseof\\towritethelimitsovermultiplelines:
\sum_{\substack{
0<i<m\\
0<j<n
}}
P(i,j)
https://en.wikibooks.org/wiki/LaTeX/Mathematics
7/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Ifyouwantthelimitsofanintegraltobespecifiedaboveandbelowthesymbol(likethesum),usethe\limitscommand:
\int\limits_a^b
HoweverifyouwantthistoapplytoALLintegrals,itispreferabletospecifytheintlimitsoptionwhenloadingtheamsmathpackage:
\usepackage[intlimits]{amsmath}
SubscriptsandsuperscriptsinothercontextsaswellasotherparameterstoamsmathpackagerelatedtothemaredescribedinAdvanced
Mathematicschapter.
Forbiggerintegrals,youmayusepersonaldeclarations,orthebigintspackage[4].
Brackets,bracesanddelimiters
HowtousebracesinmultilineequationsisdescribedintheAdvancedMathematicschapter.
Theuseofdelimiterssuchasbracketssoonbecomesimportantwhendealingwithanythingbutthemosttrivialequations.Withoutthem,
formulascanbecomeambiguous.Also,specialtypesofmathematicalstructures,suchasmatrices,typicallyrelyondelimiterstoenclose
them.
ThereareavarietyofdelimitersavailableforuseinLaTeX:
(a),[b],\{c\},|d|,\|e\|,
\langlef\rangle,\lfloorg\rfloor,
\lceilh\rceil,\ulcorneri\urcorner
where\lbrackand\rbrackmaybeusedinplaceof[and].
Automaticsizing
Veryoftenmathematicalfeatureswilldifferinsize,inwhichcasethedelimiterssurroundingtheexpressionshouldvaryaccordingly.
Thiscanbedoneautomaticallyusingthe\left,\right,and\middlecommands.Anyofthepreviousdelimitersmaybeusedin
combinationwiththese:
\left(\frac{x^2}{y^3}\right)
P\left(A=2\middle|\frac{A^2}{B}>4\right)
Curlybracesaredefineddifferentlybyusing\left\{and\right\},
https://en.wikibooks.org/wiki/LaTeX/Mathematics
8/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\left\{\frac{x^2}{y^3}\right\}
Ifadelimiterononlyonesideofanexpressionisrequired,thenaninvisibledelimiterontheothersidemaybedenotedusingaperiod(.).
\left.\frac{x^3}{3}\right|_0^1
Manualsizing
Incertaincases,thesizingproducedbythe\leftand\rightcommandsmaynotbedesirable,oryoumaysimplywantfinercontrolover
thedelimitersizes.Inthiscase,the\big,\Big,\biggand\Biggmodifiercommandsmaybeused:
(\big(\Big(\bigg(\Bigg(
Thesecommandsareprimarilyusefulwhendealingwithnesteddelimiters.Forexample,whentypesetting
\frac{\mathrmd}{\mathrmdx}\left(kg(x)\right)
wenoticethatthe\leftand\rightcommandsproducethesamesizedelimitersasthosenestedwithinit.Thiscanbedifficulttoread.To
fixthis,wewrite
\frac{\mathrmd}{\mathrmdx}\big(kg(x)\big)
Manualsizingcanalsobeusefulwhenanequationistoolarge,trailsofftheendofthepage,andmustbeseparatedintotwolinesusing
analigncommand.Althoughthecommands\left.and\right.canbeusedtobalancethedelimitersoneachline,thismayleadto
wrongdelimitersizes.Furthermore,manualsizingcanbeusedtoavoidoverlylargedelimitersifan\underbraceorasimilarcommand
appearsbetweenthedelimiters.
Typesettingintervals
Todenoteopenandhalfopenintervals,thenotations]a,b[,(a,b),]a,b],(a,b],[a,b[and[a,b)areused.Ifthesquarebracketnotationis
used,thentheintervalmustbeputbetweencurlybraces({and})inordertohavecorrectspacing.Similarly,ifa(half)openinterval
startswithanegativenumber,thenthenumberincludingitsminussymbolmustalsobeputbetweencurlybrackets,sothatLaTeX
understandsthattheminussymbolistheunaryoperation.Compare:
x\in[1,1]
x\in{[1,1]}
https://en.wikibooks.org/wiki/LaTeX/Mathematics
9/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
x\in{[{1},1]}
Matricesandarrays
Abasicmatrixmaybecreatedusingthematrixenvironment[3]:incommonwithothertablelikestructures,entriesarespecifiedbyrow,
withcolumnsseparatedusinganampersand(&)andanewrowsseparatedwithadoublebackslash(\\)
\begin{matrix}
a&b&c\\
d&e&f\\
g&h&i
\end{matrix}
Tospecifyalignmentofcolumnsinthetable,usestarredversion[5]:
\begin{matrix}
1&3\\
2&4
\end{matrix}
=
\begin{matrix*}[r]
1&3\\
2&4
\end{matrix*}
Thealignmentbydefaultiscbutitcanbeanycolumntypevalidinarrayenvironment.
Howevermatricesareusuallyenclosedindelimitersofsomekind,andwhileitispossibletousethe\leftand\rightcommands,there
arevariousotherpredefinedenvironmentswhichautomaticallyincludedelimiters:
Environmentname Surroundingdelimiter
Notes
pmatrix[3]
centerscolumnsbydefault
pmatrix*[5]
allowstospecifyalignmentofcolumnsinoptionalparameter
bmatrix[3]
centerscolumnsbydefault
bmatrix*[5]
allowstospecifyalignmentofcolumnsinoptionalparameter
Bmatrix[3]
centerscolumnsbydefault
Bmatrix*[5]
allowstospecifyalignmentofcolumnsinoptionalparameter
vmatrix[3]
centerscolumnsbydefault
vmatrix*[5]
allowstospecifyalignmentofcolumnsinoptionalparameter
Vmatrix[3]
centerscolumnsbydefault
Vmatrix*[5]
allowstospecifyalignmentofcolumsinoptionalparameter
Whenwritingdownarbitrarysizedmatrices,itiscommontousehorizontal,verticalanddiagonaltripletsofdots(knownasellipses)to
fillincertaincolumnsandrows.Thesecanbespecifiedusingthe\cdots,\vdotsand\ddotsrespectively:
A_{m,n}=
https://en.wikibooks.org/wiki/LaTeX/Mathematics
10/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\begin{pmatrix}
a_{1,1}&a_{1,2}&\cdots&a_{1,n}\\
a_{2,1}&a_{2,2}&\cdots&a_{2,n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{m,1}&a_{m,2}&\cdots&a_{m,n}
\end{pmatrix}
Insomecasesyoumaywanttohavefinercontrolofthealignmentwithineachcolumn,orwanttoinsertlinesbetweencolumnsorrows.
Thiscanbeachievedusingthearrayenvironment,whichisessentiallyamathmodeversionofthetabularenvironment,whichrequires
thatthecolumnsbeprespecified:
\begin{array}{c|c}
1&2\\
\hline
3&4
\end{array}
YoumayseethattheAMSmatrixclassofenvironmentsdoesn'tleaveenoughspacewhenusedtogetherwithfractionsresultinginoutput
similartothis:
Tocounteractthisproblem,addadditionalleadingspacewiththeoptionalparametertothe\\command:
M=\begin{bmatrix}
\frac{5}{6}&\frac{1}{6}&0\\[0.3em]
\frac{5}{6}&0&\frac{1}{6}\\[0.3em]
0&\frac{5}{6}&\frac{1}{6}
\end{bmatrix}
Ifyouneed"border"or"indexes"onyourmatrix,plainTeXprovidesthemacro\bordermatrix
M=\bordermatrix{~&x&y\cr
A&1&0\cr
B&0&1\cr}
Matricesinrunningtext
Toinsertasmallmatrix,andnotincreaseleadinginthelinecontainingit,usesmallmatrixenvironment:
Amatrixintextmustbesetsmaller:
$\bigl(\begin{smallmatrix}
a&b\\c&d
\end{smallmatrix}\bigr)$
tonotincreaseleadinginaportionoftext.
https://en.wikibooks.org/wiki/LaTeX/Mathematics
11/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Addingtexttoequations
Themathenvironmentdiffersfromthetextenvironmentintherepresentationoftext.Hereisanexampleoftryingtorepresenttextwithin
themathenvironment:
50apples\times100apples=lotsofapples^2
Therearetwonoticeableproblems:therearenospacesbetweenwordsornumbers,andthelettersareitalicizedandmorespacedoutthan
normal.Bothissuesaresimplyartifactsofthemathsmode,inthatittreatsitasamathematicalexpression:spacesareignored(LaTeX
spacesmathematicsaccordingtoitsownrules),andeachcharacterisaseparateelement(soarenotpositionedascloselyasnormaltext).
Thereareanumberofwaysthattextcanbeaddedproperly.Thetypicalwayistowrapthetextwiththe\text{...}command[3](a
similarcommandis\mbox{...},thoughthiscausesproblemswithsubscripts,andhasalessdescriptivename).Let'sseewhathappens
whentheaboveequationcodeisadapted:
50\text{apples}\times100\text{apples}
=\text{lotsofapples}^2
Thetextlooksbetter.However,therearenogapsbetweenthenumbersandthewords.Unfortunately,youarerequiredtoexplicitlyadd
these.Therearemanywaystoaddspacesbetweenmathselements,butforthesakeofsimplicitywemaysimplyinsertspacecharacters
intothe\textcommands.
50\text{apples}\times100\text{apples}
=\text{lotsofapples}^2
Formattedtext
Usingthe\textisfineandgetsthebasicresult.Yet,thereisanalternativethatoffersalittlemoreflexibility.Youmayrecallthe
introductionoffontformattingcommands,suchas\textrm,\textit,\textbf,etc.Thesecommandsformattheargumentaccordingly,
e.g.,\textbf{boldtext}givesboldtext.Thesecommandsareequallyvalidwithinamathsenvironmenttoincludetext.Theadded
benefithereisthatyoucanhavebettercontroloverthefontformatting,ratherthanthestandardtextachievedwith\text.
50\textrm{apples}\times100
\textbf{apples}=\textit{lotsofapples}^2
Formattingmathematicssymbols
Seealso:w:MathematicalAlphanumericSymbols,w:Help:Displayingaformula#Alphabetsandtypefacesandw:Wikipedia:LaTeX
symbols#Fonts
Wecannowformattextwhataboutformattingmathematicalexpressions?Thereareasetofformattingcommandsverysimilartothe
fontformattingonesjustused,exceptthattheyarespecificallyaimedattextinmathmode(requiresamsfonts)
https://en.wikibooks.org/wiki/LaTeX/Mathematics
12/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
LaTeXcommand
Sample
Description
Commonuse
\mathnormal{}
(orsimplyomitany
command)
Thedefault
Mostmathematicalnotation
mathfont
\mathrm{}
Thisisthe
defaultor
Unitsofmeasurement,onewordfunctions
normalfont,
unitalicised
\mathit{}
Italicised
font
Multiletterfunctionorvariablenames.Comparedto
\mathnormal,wordsarespacedmorenaturallyand
numbersareitalicizedaswell.
\mathbf{}
Boldfont
Vectors
\mathsf{}
Sansserif
\mathtt{}
Monospace
(fixed
width)font
\mathfrak{}
Fraktur
\mathcal{}
Oftenusedforsheaves/schemesandcategories,used
todenotecryptologicalconceptslikeanalphabetof
Calligraphy
definition( ),messagespace( ),ciphertext
(uppercase
space( )andkeyspace( )Kleene's naming
only)
conventionindescriptionlogicLaplacetransform(
)andFouriertransform( )
\mathbb{}
(requirestheamsfonts
oramssymbpackage)
Blackboard
bold
Usedtodenotespecialsets(e.g.realnumbers)
(uppercase
only)
\mathscr{}
(requiresthemathrsfs
package)
Script
(uppercase
only)
AlmostcanonicalfontforLiealgebras,with
superscriptusedtodenoteNewTestamentpapyri,
idealsinringtheory
Analternativefontforcategoriesandsheaves.
Theseformattingcommandscanbewrappedaroundtheentireequation,andnotjustonthetextualelements:theyonlyformatletters,
numbers,anduppercaseGreek,andothermathcommandsareunaffected.
ToboldlowercaseGreekorothersymbolsusethe\boldsymbolcommand[3]thiswillonlyworkifthereexistsaboldversionofthe
symbolinthecurrentfont.Asalastresortthereisthe\pmbcommand[3](poormansbold):thisprintsmultipleversionsofthecharacter
slightlyoffsetagainsteachother.
\boldsymbol{\beta}=(\beta_1,\beta_2,\dotsc,\beta_n)
Tochangethesizeofthefontsinmathmode,seeChangingfontsize.
Accents
Sowhattodowhenyourunoutofsymbolsandfonts?Wellthenextstepistouseaccents:
a'ora^{\prime}
a''
\hat{a}
\bar{a}
\grave{a}
\acute{a}
\dot{a}
\ddot{a}
\not{a}
\mathring{a}
\overrightarrow{AB}
\overleftarrow{AB}
https://en.wikibooks.org/wiki/LaTeX/Mathematics
13/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
a'''
a''''
\overline{aaa}
\check{a}
\breve{a}
\vec{a}
\dddot{a}[3]
\ddddot{a}[3]
\widehat{AAA}
\widetilde{AAA}
\widehat{AAA}
\stackrel\frown{AAA}
\tilde{a}
\underline{a}
Color
Thepackagexcolor,describedinColors,allowsustoaddcolortoourequations.Forexample,
k={\color{red}x}\mathbin{\color{blue}}2
TheonlyproblemisthatthisdisruptsthedefaultLATEXformattingaroundtheoperator.Tofixthis,weencloseitina\mathbin
environment,sinceisabinaryoperator.Thisprocessisdescribedhere(http://tex.stackexchange.com/questions/21598/howtocolor
mathsymbols).
Plusandminussigns
Latexdealswiththe+andsignsintwopossibleways.Themostcommonisasabinaryoperator.Whentwomathselementsappearon
eithersideofthesign,itisassumedtobeabinaryoperator,andassuch,allocatessomespaceeithersideofthesign.Thealternativeway
isasigndesignation.Thisiswhenyoustatewhetheramathematicalquantityiseitherpositiveornegative.Thisiscommonforthelatter,
asinmaths,suchelementsareassumedtobepositiveunlessaisprefixedtoit.Inthisinstance,youwantthesigntoappearclosetothe
appropriateelementtoshowtheirassociation.Ifyouputa+orawithnothingbeforeitbutyouwantittobehandledlikeabinary
operatoryoucanaddaninvisiblecharacterbeforetheoperatorusing{}.Thiscanbeusefulifyouarewritingmultiplelineformulas,and
anewlinecouldstartwitha=ora+,forexample,thenyoucanfixsomestrangealignmentsaddingtheinvisiblecharacterwhere
necessary.
Aplusminussigniswrittenas:
\pm
Similarly,thereexistsalsoaminusplussign:
\mp
Controllinghorizontalspacing
LaTeXisobviouslyprettygoodattypesettingmathsitwasoneofthechiefaimsofthecoreTeXsystemthatLaTeXextends.However,
itcan'talwaysbereliedupontoaccuratelyinterpretformulasinthewayyoudid.Ithastomakecertainassumptionswhenthereare
ambiguousexpressions.Theresulttendstobeslightlyincorrecthorizontalspacing.Intheseevents,theoutputisstillsatisfactory,yetany
perfectionistswillnodoubtwishtofinetunetheirformulastoensurespacingiscorrect.Thesearegenerallyverysubtleadjustments.
ThereareotheroccasionswhereLaTeXhasdoneitsjobcorrectly,butyoujustwanttoaddsomespace,maybetoaddacommentofsome
kind.Forexample,inthefollowingequation,itispreferabletoensurethereisadecentamountofspacebetweenthemathsandthetext.
\[f(n)=
\begin{cases}
https://en.wikibooks.org/wiki/LaTeX/Mathematics
14/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
n/2&\quad\text{if}n\text{iseven}\\
(n+1)/2&\quad\text{if}n\text{isodd}\\
\end{cases}
\]
ThiscodeproduceserrorswithMiktex2.9anddoesnotyieldtheresultsseenontheright.Use\mathrminsteadofjust\text.
(Notethatthisparticularexamplecanbeexpressedinmoreelegantcodebythecasesconstructprovidedbytheamsmathpackage
describedinAdvancedMathematicschapter.)
LaTeXhasdefinedtwocommandsthatcanbeusedanywhereindocuments(notjustmaths)toinsertsomehorizontalspace.Theyare
\quadand\qquad
A\quadisaspaceequaltothecurrentfontsize.So,ifyouareusingan11ptfont,thenthespaceprovidedby\quadwillalsobe11pt
(horizontally,ofcourse.)The\qquadgivestwicethatamount.Asyoucanseefromthecodefromtheaboveexample,\quadswereusedto
addsomeseparationbetweenthemathsandthetext.
OK,sobacktothefinetuningasmentionedatthebeginningofthedocument.Agoodexamplewouldbedisplayingthesimpleequation
fortheindefiniteintegralofywithrespecttox:
Ifyouweretotrythis,youmaywrite:
\inty\mathrm{d}x
However,thisdoesn'tgivethecorrectresult.LaTeXdoesn'trespectthewhitespaceleftinthecodetosignifythattheyandthedxare
independententities.Instead,itlumpsthemaltogether.A\quadwouldclearlybeoverkillinthissituationwhatisneededaresomesmall
spacestobeutilizedinthistypeofinstance,andthat'swhatLaTeXprovides:
Command Description
Size
\,
smallspace
3/18ofaquad
\:
mediumspace 4/18ofaquad
\;
largespace
\!
negativespace 3/18ofaquad
5/18ofaquad
NByoucanusemorethanonecommandinasequencetoachieveagreaterspaceifnecessary.
So,torectifythecurrentproblem:
\inty\,\mathrm{d}x
\inty\:\mathrm{d}x
https://en.wikibooks.org/wiki/LaTeX/Mathematics
15/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\inty\;\mathrm{d}x
Thenegativespacemayseemlikeanoddthingtouse,however,itwouldn'tbethereifitdidn'thavesomeuse!Takethefollowing
example:
\left(
\begin{array}{c}
n\\
r
\end{array}
\right)=\frac{n!}{r!(nr)!}
Thematrixlikeexpressionforrepresentingbinomialcoefficientsistoopadded.Thereistoomuchspacebetweenthebracketsandthe
actualcontentswithin.Thiscaneasilybecorrectedbyaddingafewnegativespacesaftertheleftbracketandbeforetherightbracket.
\left(\!
\begin{array}{c}
n\\
r
\end{array}
\!\right)=\frac{n!}{r!(nr)!}
Inanycase,addingsomespacesmanuallyshouldbeavoidedwheneverpossible:itmakesthesourcecodemorecomplexandit'sagainst
thebasicprinciplesofaWhatYouSeeisWhatYouMeanapproach.Thebestthingtodoistodefinesomecommandsusingallthe
spacesyouwantandthen,whenyouuseyourcommand,youdon'thavetoaddanyotherspace.Later,ifyouchangeyourmindaboutthe
lengthofthehorizontalspace,youcaneasilychangeitmodifyingonlythecommandyoudefinedbefore.Letususeanexample:you
wantthedofadxinanintegraltobeinromanfontandasmallspaceawayfromtherest.Ifyouwanttotypeanintegrallike\intx\,
\mathrm{d}x,youcandefineacommandlikethis:
\newcommand{\dd}{\mathop{}\,\mathrm{d}}
inthepreambleofyourdocument.Wehavechosen\ddjustbecauseitremindsthe"d"itreplacesanditisfasttotype.Doingso,thecode
foryourintegralbecomes\intx\ddx.Now,wheneveryouwriteanintegral,youjusthavetousethe\ddinsteadofthe"d",andallyour
integralswillhavethesamestyle.Ifyouchangeyourmind,youjusthavetochangethedefinitioninthepreamble,andallyourintegrals
willbechangedaccordingly.
ManuallySpecifyingFormulaStyle
Tomanuallydisplayafragmentofaformulausingtextstyle,surroundthefragmentwithcurlybracesandprefixthefragmentwith
\textstyle.Thebracesarerequiredbecausethe\textstylemacrochangesthestateoftherenderer,renderingallsubsequent
mathematicsintextstyle.Thebraceslimitthischangeofstatetojustthefragmentenclosedwithin.Forexample,tousetextstyleforjust
thesummationsymbolinasum,onewouldenter
\begin{equation}
C^i_j={\textstyle\sum_k}A^i_kB^k_j
\end{equation}
Thesamethingasacommandwouldlooklikethis:
https://en.wikibooks.org/wiki/LaTeX/Mathematics
16/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
\newcommand{\tsum}[1]{{\textstyle\sum_{#1}}}
Notetheextrabraces.Justonesetaroundtheexpressionwon'tbeenough.Thatwouldcauseallmathafter\tsumktobedisplayedusing
textstyle.
Todisplaypartofaformulausingdisplaystyle,dothesamething,butuse\displaystyleinstead.
AdvancedMathematics:AMSMathpackage
TheAMS(AmericanMathematicalSociety)mathematicspackageisapowerfulpackagethatcreatesahigherlayerofabstractionover
mathematicalLaTeXlanguageifyouuseititwillmakeyourlifeeasier.Somecommandsamsmathintroduceswillmakeotherplain
LaTeXcommandsobsolete:inordertokeepconsistencyinthefinaloutputyou'dbetteruseamsmathcommandswheneverpossible.Ifyou
doso,youwillgetanelegantoutputwithoutworryingaboutalignmentandotherdetails,keepingyoursourcecodereadable.Ifyouwant
touseit,youhavetoaddthisinthepreamble:
\usepackage{amsmath}
Introducingdotsinformulas
amsmathdefinesalsothe\dotscommand,thatisageneralizationoftheexisting\ldots.Youcanuse\dotsinbothtextandmathmode
andLaTeXwillreplaceitwiththreedots""butitwilldecideaccordingtothecontextwhethertoputitonthebottom(like\ldots)or
centered(like\cdots).
Dots
LaTeXgivesyouseveralcommandstoinsertdots(ellipses)inyourformulae.Thiscanbeparticularlyusefulifyouhavetotypebig
matricesomittingelements.Firstofall,herearethemaindotsrelatedcommandsLaTeXprovides:
Code
Output
Comment
\dots
genericdots(ellipsis),tobeusedintext(outsideformulaeaswell).Itautomaticallymanageswhitespaces
beforeandafteritselfaccordingtothecontext,it'sahigherlevelcommand.
\ldots
theoutputissimilartothepreviousone,butthereisnoautomaticwhitespacemanagementitworksatalower
level.
\cdots
Thesedotsarecenteredrelativetotheheightofaletter.Thereisalsothebinarymultiplicationoperator,\cdot,
mentionedbelow.
\vdots
verticaldots
\ddots
diagonaldots
\iddots
inversediagonaldots(requiresthemathdotspackage)
\hdotsfor{n}
tobeusedinmatrices,itcreatesarowofdotsspanningncolumns.
Insteadofusing\ldotsand\cdots,youshouldusethesemanticallyorientedcommands.Itmakesitpossibletoadaptyourdocumentto
differentconventionsonthefly,incase(forexample)youhavetosubmitittoapublisherwhoinsistsonfollowinghousetraditioninthis
respect.ThedefaulttreatmentforthevariouskindsfollowsAmericanMathematicalSocietyconventions.
https://en.wikibooks.org/wiki/LaTeX/Mathematics
17/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Code
Output
Comment
A_1,A_2,\dotsc,
for"dotswithcommas"
A_1+\dotsb+A_N
for"dotswithbinaryoperators/relations"
A_1\dotsmA_N
for"multiplicationdots"
\int_a^b\dotsi
for"dotswithintegrals"
A_1\dotsoA_N
for"otherdots"(noneoftheabove)
Writeanequationwiththealignenvironment
HowtowriteanequationwiththealignenvironmentwiththeamsmathpackageisdescribedinAdvancedMathematics.
ListofMathematicalSymbols
Allthepredefinedmathematicalsymbolsfromthe\TeX\packagearelistedbelow.Moresymbolsareavailablefromextrapackages.
Symbol
Script
Symbol
RelationSymbols
Symbol Script Symbol
Script
Script
Symbol
Script
<
>
\parallel
\nparallel
\leq
\geq
\doteq
\asymp
\bowtie
\ll
\gg
\equiv
\vdash
\dashv
\subset
\subseteq
\supset
\supseteq
\approx
\cong
\in
\smile
\ni
\frown
\nsubseteq
\nsupseteq
\simeq
\models
\notin
\sqsubset
\sqsupset
\sim
\perp
\mid
\sqsubseteq
\sqsupseteq
\propto
\prec
\succ
\preceq
\succeq
\neq
\sphericalangle
\measuredangle
BinaryOperations
Symbol Script Symbol
Script
Symbol Script
Symbol
Script
\pm
\cap
\diamond
\oplus
\mp
\cup
\bigtriangleup
\ominus
\times
\uplus
\bigtriangledown
\otimes
\div
\sqcap
\triangleleft
\oslash
\ast
\sqcup
\triangleright
\odot
\star
\vee
\bigcirc
\circ
\dagger
\wedge
\bullet
\setminus
\ddagger
\cdot
\wr
\amalg
https://en.wikibooks.org/wiki/LaTeX/Mathematics
18/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
Setand/orLogicNotation
Symbol
Script
Symbol Script
\exists
\rightarrowor\to
\nexists
\leftarrowor\gets
\forall
\mapsto
\neg
\implies
\subset
\supset
\Rightarrowor\implies
\leftrightarrow
\in
\iff
\notin
\Leftrightarrow(preferredforequivalence(iff))
\ni
\top
\land
\bot
and
\lor
Symbol
Script
\emptysetand\varnothing
Delimiters
Script
Symbol Script
Symbol
\|
\{
Symbol
\}
Script
\backslash
\langle
\rangle
\uparrow
\Uparrow
\lceil
\rceil
\downarrow
\Downarrow
\lfloor
\rfloor
Note:TousetheGreekLettersinLaTeXthathavethesameappearanceastheirRomanequivalent,justusetheRomanform:e.g.,A
insteadofAlpha,BinsteadofBeta,etc.
Symbol
Script
GreekLetters
Symbol
Script
and
Aand\alpha
and
Nand\nu
and
Band\beta
and
\Xiand\xi
and
\Gammaand\gamma
and
Oando
and
\Deltaand\delta
, and
\Pi,\piand\varpi
, and
E,\epsilonand\varepsilon
, and
P,\rhoand\varrho
and
Zand\zeta
, and
\Sigma,\sigmaand\varsigma
and
Hand\eta
and
Tand\tau
, and
\Theta,\thetaand\vartheta
and
\Upsilonand\upsilon
Iand\iota
, ,and
\Phi,\phiand\varphi
, and
K,\kappaand\varkappa
and
Xand\chi
and
\Lambdaand\lambda
and
\Psiand\psi
Mand\mu
and
\Omegaand\omega
and
and
Symbol Script
\partial
\eth
\hbar
Othersymbols
Symbol Script
Symbol Script
\imath
\jmath
\ell
https://en.wikibooks.org/wiki/LaTeX/Mathematics
\Re
\Im
\wp
Symbol Script
\nabla
\Box
\infty
Symbol Script
\aleph
\beth
\gimel
19/20
11/1/2015
LaTeX/MathematicsWikibooks,openbooksforanopenworld
TrigonometricFunctions
Symbol Script Symbol Script
Symbol Script
\sin
\cos
\arcsin
\arccos
Symbol Script
\sinh
\cosh
\tan
\arctan
\tanh
\cot
\arccot
\coth
\sec
\csc
Summary
Asyoubegintosee,typesettingmathcanbetrickyattimes.However,becauseLaTeXprovidessomuchcontrol,youcangetprofessional
qualitymathematicstypesettingwithrelativelylittleeffort(onceyou'vehadabitofpractice,ofcourse!).Itwouldbepossibletokeep
goingandgoingwithmathtopicsbecauseitseemspotentiallylimitless.However,withthistutorial,youshouldbeabletogetalong
sufficiently.
Notes
1. http://www.ams.org/publications/authors/tex/amslatex
2. http://www.tex.ac.uk/ctan/macros/latex/contrib/mathtools/mathtools.pdf
3. requirestheamsmathpackage
4. http://hdl.handle.net/2268/6219
5. requiresthemathtoolspackage
Furtherreading
meta:Help:Displayingaformula:WikimediausesasubsetofLaTeXcommands.
Externallinks
LaTeXmathssymbols(http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:Symbols)
detexify(http://detexify.kirelabs.org):appletforlookingupLaTeXsymbolsbydrawingthem
amsmathdocumentation(ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf)
LaTeXTheStudentRoom(http://www.thestudentroom.co.uk/wiki/LaTeX)
TheComprehensiveLaTeXSymbolList(http://www.ctan.org/texarchive/info/symbols/comprehensive)
MathLexLaTeXmathtranslatorandequationbuilder(http://mathlex.org/latex)
Retrievedfrom"https://en.wikibooks.org/w/index.php?title=LaTeX/Mathematics&oldid=3008555"
Thispagewaslastmodifiedon21October2015,at01:56.
TextisavailableundertheCreativeCommonsAttributionShareAlikeLicense.additionaltermsmayapply.Byusingthissite,you
agreetotheTermsofUseandPrivacyPolicy.
https://en.wikibooks.org/wiki/LaTeX/Mathematics
20/20