LAT X maths and graphics E TimLove May26,2004 This handout assumes that you have already read the Advanced LaTeX1 document handout, so if you’re unsure about ‘environments’, readnofurther. Note that there’s an alternative way of producing maths in LATEX - A S-LATEX. Seetheonlinemanual2 fordetails. MIfyouwanttomoremoreaboutgraphics,seeUsingImportedGraph- icsinLaTeX2eDocuments3 byKeithReckdahl. CommentsandbugreportstoTimLove([email protected]). Contents 1 Maths 2 1.1 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 SpecialCharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2.1 Greek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2.2 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2.3 Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2.4 Calligraphic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2.5 CharacterModi(cid:2)ers . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2.6 Commonfunctions . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 Subscriptsandsuperscripts . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Overlining,underliningandboldcharacters . . . . . . . . . . . . . . 6 1.5 Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.6 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.7 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.8 Numberingandlabelling . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.9 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.10 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.11 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.12 Finetuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.13 MathsandPostscriptfonts . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.14 MatlabandLaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.15 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/latexadvanced/latexadvanced.html 2http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/amslatex.dvi 3http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/epslatex.ps Copyright c2004 by T.P.Love. This document may be copied freely for the pur- (cid:13) posesofeducationandnon-commercialresearch.CambridgeUniversityEngineer- ingDepartment,CambridgeCB21PZ,England. 1 2 Graphics 12 2.1 Postscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.1.1 psfrag: addingmathstopostscript(cid:2)les . . . . . . . . . . . . 13 2.1.2 PostscriptfromPCs/Macs . . . . . . . . . . . . . . . . . . . . . 14 2.2 Scaling,rotation,clipping,wrap-aroundandshadows . . . . . . . . . 14 2.3 GIFandjpeg(cid:2)les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1 Maths There’smoretomathstypesettingthanmeetstheeye. Manyconventionsusedin thetypesettingofplaintextareinappropriatetomaths. LATEXgoesalongwayto helpyoualongwiththestyle. Forexample,inaLATEXmathsenvironment,letters comeoutinitalics,‘-’as‘ ’(minus)insteadoftheusual‘-’(dash),‘*’becomes , (cid:0) (cid:3) ’becomes0andspacingischanged(lessaround‘/’,morearound‘+’). ManyoftheusualLATEXconstructionscanstillbeusedinmathsenvironments buttheireffectmaybeslightlydifferent;eg\textbf{ }onlyaffectslettersand numbers. ‘{’and‘}’arestillspecialcharacters;they’reusedtogroupcharacters. AsusualinLATEXyoucanoverridethedefaults,butthinkbeforedoingit:maths support in LATEX has been carefully thought out and is quite logical though the LATEXsourcetextmaynotbeveryreadable. It’sagoodideatowriteouttheformu- laeonpaperbeforeyoustartLATEXing,andtrynottooverdotheuseofthe‘\frac’ construction;use‘/’instead. 1.1 Environments Thereare2environmentstodisplayone-lineequations. equation:- Equationsinthisenvironmentarenumbered. \begin{equation} x + iy \end{equation} x+iy (1) displaymath:- These won’t be numbered. \[, \] can be used as abbreviations for\begin{displaymath}and\end{displaymath}. \begin{displaymath} x + iy \end{displaymath} x+iy Never leave a blank line before these equations; it starts a new paragraph and looksugly. ’\displaystyle’isthefonttypeusedtoprintmathsinthesedisplay environments. Otherrelevantenvironmentsare:- math:- Foruseintext. \(and\)canbeusedtodelimittheenvironment,ascan theTEXconstructions$and$. Forexample,$x=yˆ2$givesx=y2. eqnarray:- This is like a 3 column tabular environment. Each line by default is numbered. Youcanusetheeqnarray*varianttosuppressnumberingalto- gether. 2 \begin{eqnarray} a1 & = & b1 + c1\nonumber\\ a2 & = & b2 - c2 \end{eqnarray} a1 = b1+c1 a2 = b2 c2 (2) (cid:0) Maths in these 2 sorts of environments have different default sizes for some charactersandotherbehaviouraldifferencessothatalineofmathswon’timpinge ontextlinesbeloworabove. Ifyouwanttoputsomenon-mathstextinamongst mathsthenencloseitinan\mbox{...}. 1.2 SpecialCharacters The amssymb package offers more symbols if the following aren’t enough. The symbols4 document(apostscript(cid:2)le)hasabiggerlist. 1.2.1 Greek (cid:11) \alpha (cid:12) \beta (cid:13) \gamma (cid:14) \delta (cid:15) \epsilon (cid:16) \zeta (cid:17) \eta (cid:18) \theta (cid:19) \iota (cid:20) \kappa (cid:21) \lambda (cid:22) \mu (cid:23) \nu (cid:24) \xi o o (cid:25) \pi (cid:26) \rho (cid:27) \sigma (cid:28) \tau (cid:29) \upsilon (cid:30) \phi (cid:31) \chi \psi ! \omega (cid:0) \Gamma (cid:1) \Delta (cid:2) \Theta (cid:3) \Lambda (cid:4) \Xi (cid:5) \Pi (cid:6) \Sigma (cid:7) \Upsilon (cid:8) \Phi (cid:9) \Psi (cid:10) \Omega 1.2.2 Miscellaneous . . ::: \ldots \cdots . \vdots (cid:1)(cid:1)(cid:1) ... \ddots \pm \mp (cid:6) (cid:7) \times \div \ast (cid:2) (cid:4) (cid:3) ? \star \circ \bullet (cid:14) (cid:15) \cdot \cap \bigcap (cid:1) \ \cup \bigcup \uplus [ ]T \biguplus \sqcap \sqcup uS t \bigsqcup \vee \bigvee U _ \wedge \bigwedge \setminus F^ nW \wr \diamond \bigtriangleup o (cid:5)V 4 \bigtriangledown / \triangleleft . \triangleright 5 \oplus \bigoplus \ominus (cid:8) (cid:9) \otimes \bigotimes \oslash (cid:10) L (cid:11) \odot \bigodot \bigcirc (cid:12) N (cid:13) \amalg \leq \prec q (cid:20)J (cid:30) \preceq \ll \subset (cid:22) (cid:28) (cid:26) \subseteq \sqsubseteq \in (cid:18) v 2 \vdash \geq \succ ‘ (cid:21) (cid:31) \succeq \gg \supset (cid:23) (cid:29) (cid:27) 4http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/symbols.ps 3 \supseteq \sqsupseteq \ni (cid:19) w 3 \dashv \equiv \sim a (cid:17) (cid:24) \simeq \asymp \approx ’ (cid:16) (cid:25): = \cong = \neq = \doteq (cid:24) 6 \propto = \models \perp / j ? \mid \parallel ./ \bowtie j k ^ \smile _ \frown \aleph @ h(cid:22) \hbar { \imath | \jmath ‘ \ell } \wp \Re < \Im \prime \empty = 0 \nabla p \surd \top r > \bot \| 6 \angle ? k \forall \exists \neg 8 9 : [ \flat \ \natural ] \sharp \backslash @ \partial \infty n 1 \triangle \sum \prod 4 \coprod \int \oint P Q ‘ R H 1.2.3 Arrows \leftarrow \Leftarrow \rightarrow ( ! \Rightarrow \leftrightarrow \Leftrightarrow ) $ , \mapsto - \hookleftarrow ( \leftharpoonup 7! ) \leftharpoondown *) \rightleftharpoons \longleftarrow (cid:0) = \Longleftarrow \longrightarrow = \Longrightarrow ( (cid:0)! ) \longleftrightarrow \Longleftrightarrow \longmapsto ! () 7(cid:0)! , \hookrightarrow * \rightharpoonup + \rightharpoondown ! \uparrow \Uparrow " * \downarrow \Downarrow \updownarrow # + l \nearrow \searrow \swarrow % & . \nwarrow - 1.2.4 Calligraphic Thesecharactersareavailableifyouusethe\calcontrolsequence. ${\cal A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$ gives ABCDEFGHIJKLMNOPQRSTUVWXYZ 1.2.5 CharacterModi(cid:2)ers \hat{e} e^ \widehat{easy} easy \tilde{e} e~ \widetilde{easy} easy \check{e} e(cid:20) \breve{e} e(cid:21) d \acute{e} e(cid:19) \grave{e} e(cid:18) g \bar{e} e(cid:22) \vec{e} ~e \dot{e} e_ \ddot{e} e(cid:127) \not e e 6 Notethatthewideversionsofhatandtildecannotproduceverywidealterna- tives. The‘\not’operatorhasn’tproperlycutthefollowingletter. TheFineTuning 4 sectiononpage9describeshowtoadjustthis. If you want to place one character above another, you can use \stackrel, whichprintsits(cid:2)rstargumentinsmalltypeimmediatelyabovethesecond $ a \stackrel{def}{=} b + c $ def givesa = b+c SeetheMacrossectionforhowtostackcharactersusingatop. 1.2.6 Commonfunctions In a maths environment, LATEX assumes that variables will have single-character names. Functionnamesrequirespecialtreatment. Theadvantageofusingthefol- lowingcontrolsequencesforcommonfunctionsisthatthetextwillnotbeputin math italic and subscripts/superscripts will be made into limits where appropri- ate. \arccos \arcsin \arctan \arg \cos \cosh \cot \coth \csc \deg \det \dim \exp \gcd \hom \inf \ker \lg \lim \liminf \ln \log \max \min \Pr sec \sin \sinh \sup \tan \tanh 1.3 Subscriptsandsuperscripts Theseareintroducedbythe‘ˆ’and‘_’characters.Dependingonthebasecharacter and the current style, the sub- or superscripts may go to the right of or directly above/belowthemaincharacter. Withlettersitgoestotheright. $F_2ˆ3$ produces‘F3’. Notethatthesub-andsuperscriptsaren’tinline. Tomakethemso, 2 youcanaddaninvisiblecharacterafterthe‘F’.$F{}_2ˆ3$producesF3. 2 With thedefaultbehaviourisdifferentindisplayandtextstyles. $\sum_{Pi=0}ˆ2 $ 2 produces (textstyle)but i=0 \[\sum_{Pi=0}ˆ2 \] produces(indisplaystyle) 2 i=0 X Thisdefaultbehaviourcanbeoverridden,ifyoureallyneedto. Forexamplein textmode, $\sum\limits_{i=0}ˆ2$ 2 produces i=0 P 5 1.4 Overlining,underliningandboldcharacters $\underline{one} \overline{two}$ producesonetwo. Thisisnotausefulfacilityifit’susedmorethanonceonaline. Thelinesareproducedsothattheydon’tquiteoverlapthetext;linesoverorunder differentwordswon’tingeneralbeatthesameheight. Tobeabletoreproduceboldmaths,it’sbesttousethebmpackage.$E = \bm{mcˆ2}$ producesE =mc2. Alternatively,youcanuse\mathbf{}tocreateboldcharacters-$\mathbf{F}_2ˆ3$ producesF3. oryoucanusethefollowingidea 2 \usepackage{amsbsy} % This loads amstext too \begin{document} $\omega + \boldsymbol{\omega}$ % Use the following if whole expressions need to be in bold {\boldmath $\omega $} \end{document} 1.5 Roots $\sqrt{4} + \sqrt[3]{x + y}$ givesp4+p3x+y. 1.6 Fractions Threeconstructionsforputtingexpressionsaboveothersare frac:- $\frac{1}{(x + 3)}$produces 1 . (x+3) choose:- ${n + 1 \choose 3}$produces n+1 . 3 atop:- ${x \atop y}$produces x. (cid:0) (cid:1) y Theseconstructionscanbeusedwithonesdescribedearlier. E.g., \[ \sum_{-1\le i \le 1 \atop 0 < j < \infty} f(i,j)\] gives f(i;j) (cid:0)1(cid:20)i(cid:20)1 0<Xj<1 1.7 Delimiters these aremadebythese andthese aremadebythese ( ( ) ) [ [ ] ] \{ \} f g \lfloor \rfloor b c \lceil \rceil d e \langle \rangle h i = / \backslash n | \| j k \uparrow \Uparrow " * \downarrow \Downarrow # + \updownarrow \Updownarrow l m 6 Thistableshowsthestandardsizes. Togetbiggersizes,usethesepre(cid:2)ces (forleftdelimiters) (forrightdelimiters) magni(cid:2)cation \bigl \bigr abitbigger,butwon’toverlaplines \Bigl \Bigr 150%timesbig \biggl \biggr 200%timesbig \Biggl \Biggr 250%timesbig Forexample, $\Biggl\{2\Bigl(x(3+y)\Bigr)\Biggr\}$ gives 2 x(3+y) . If you’re not using the default text size these commands ( ) (cid:16) (cid:17) mightnotworkcorrectly. Inthatcasetrytheexscalepackage. It’s preferable to let LATEX choose the delimiter size for you by using \left and\right. Thesewillproducedelimitersjustbigenoughfortheformulaeinbe- tween. $\left( \frac{(x+iy)}{\{\int x\}} \right)$ gives (x+iy) f xg (cid:18) (cid:19) Theleftandrightdelimitersneedn’tbethesametype. It’ssometimesusefulto R makeoneoftheminvisible \[ z = \left\{ \begin{array}{ll} 1 & (x>0)\\ 0 & (x<0) \end{array} \right. \] produces 1 (x>0) z = 0 (x<0) (cid:26) Over-andunderbracingworkstoo. $\overbrace{\alpha \ldots \omega}ˆ{\mbox{greek}} \underbrace{a \ldots z}_{\mbox{english}}$ greek produces(cid:11):::! a:::z . Theuseof\mboxstopsthetextappearinginmathitalic. english z }| { | {z } 1.8 Numberingandlabelling Numbering happening automatically when you display equations. If you don’t wantanequationnumbered,use\nonumberbesidetheequation. Equationnum- bersappeartotherightofthemathsbydefault. Tomakethemappearontheleft usetheleqnoclassoption(i.e.,use\documentclass[leqno,....]{....}). Use\label{}tolabelanequation(or(cid:2)gure,sectionetc)inordertoreference fromelsewhere. 7 \begin{equation} W_{\bf S}(t,\omega) = \int\limits_{-\infty}ˆ{\infty} { {\cal R}_{\bf S}(t,\tau) eˆ{-j\omega\tau} \,d \tau } \label{LABELLING} \end{equation} 1 WS(t;!)= S(t;(cid:28))e(cid:0)j!(cid:28)d(cid:28) (3) R Z (cid:0)1 Nowthefollowingtext refers back to equation \ref{LABELLING} refersbacktoequation3bynumber,and refers back to the equation on page \pageref{LABELLING} refersbacktotheequationonpage8. A (cid:2)le will have to be LATEX’ed twice before the references, both forwards and backwards,willbecorrectlyproduced. 1.9 Matrices ThearrayenvironmentislikeLATEX’stabularenvironmentexceptthateachel- ement is in math mode. The number and alignment of columns is controlled by thearguments-usel, corrtorepresenteachcolumnwitheitherleft,centeror rightalignment. Thedefaultfontstyleusedis\textstylebutyoucanoverride thisbychangingthe\displaystyle. \begin{math} \begin{array}{clrr} % a+b+c & uv & x-y & 27 \\ x+y & w & +z & 363 \end{array} \end{math} a+b+c uv x y 27 produces (cid:0) x+y w +z 363 Therowsarearrangedsothattheircentresarealigned. Youcanaligntheirtops orbottomsinsteadbyusingafurtherargumentwhenyoucreatethearray. \begin{array}{clrr}[t] wouldproducetop-alignedlines,and‘[b]’wouldproducebottom-alignedones. TheDelimiterssectionofthisdocumentshowshowtobracketmatrices. TEXhasafewmathsfacilitiesnotmentionedintheLATEXbook. Thefollowing TEXconstructionmightbeuseful. \begin{math} \bordermatrix{&a_1&a_2&...&a_n\cr b_1 & 1.2 & 3.3 & 5.1 & 2.8 \cr c_1 & 4.7 & 7.8 & 2.4 & 1.9 \cr ... & ... & ... & ... & ... \cr z_1 & 8.0 & 9.9 & 0.9 & 9.99 \cr} \end{math} a a ::: a 1 2 n b 1:2 3:3 5:1 2:8 1 c 4:7 7:8 2:4 1:9 1 0 1 ::: ::: ::: ::: ::: z B8:0 9:9 0:9 9:99C 1B C @ A 8 1.10 Macros Theseaidreadability,saveonrepetitivetypingandofferwaysofproducingstylis- ticvariationsonstandardLATEXformats. \def\bydefn{\stackrel{def}{=}} \def\convf{\hbox{\space \raise-2mm\hbox{$\textstyle \bigotimes \atop \scriptstyle \omega$} \space}} def produce = and when$\bydefn$and$\convf$aretyped. ! N 1.11 Packages Thefollowingpackagesmaybeofhelp easybmat5 -easyblockmatrices (cid:15) easyeqn6 -easyequations. (cid:15) easymat7 -easymatrices (cid:15) easytable8 -easytables (cid:15) easyvector9 -easyvectors (cid:15) delarray10 -nestedarrays (cid:15) theorem11 -givesmorechoiceintheoremlayout (cid:15) subeqnarray-Renumberingofsub-arraysinmath-mode (cid:15) subeqn-Differentnumberingsub-arrays (cid:15) 1.12 Finetuning It’sgenerallyagoodideatokeeppunctuationoutsidemathmode;LATEX’snormal handling ofspacing around punctuation issuspended during maths. Sometimes you might want to adjust the spacing in a formula (e.g., you might want to add spacebeforedx). Usethesesymbols:- a\, b (ab)thinspace a\> b (ab)mediumspace a\; b (ab)thickspace a\! b (ab)negativethinspace Longmathexpressionsaren’tbrokenautomaticallyunlessyouusethebreqn12 package,whichisstillalittleexperimental.Inaneqnarrayenvironmentyoumay wanttobreakalonglinemanually. Youcandothisbyputting y & = & a + b \nonumber \\ & & + k 5http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/easybmat.dvi 6http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/easyeqn.dvi 7http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/easymat.dvi 8http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/easytable.dvi 9http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/easyvector.dvi 10http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/delarray.dvi 11http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/theorem.dvi 12http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/breqndoc.dvi 9 togive y = a+b +k (4) butthespacingaroundthe‘+’onthe2ndlineiswrongbecauseLATEXthinksit’sa unaryoperator. YoucanfoolLATEXintotreatingitasabinaryoperatorbyinserting ahiddencharacter. y & = & a + b \nonumber \\ & & \mbox{} + k gives y = a+b +k (5) Youcanusethe\lefteqnconstructiontoformatlongexpressionssothatcon- tinuationlinesaredifferentlyindented. \begin{eqnarray} \lefteqn{x+ iy=}\\ & & a + b + c + d + e + f + g + h + i + j + k +\nonumber\\ & & l + m \nonumber \end{eqnarray} x+iy = (6) a+b+c+d+e+f +g+h+i+j+k+ l+m If you want more vertical spacing around a line you can create an invisible vertical(cid:148)struct(cid:148)inLaTeX.\rule[-.3cm]{0cm}{1cm}createsaboxofwidth0, height1cmwhichstarts.3cmbelowtheusuallinebase. Byadjustingthesevalues you should be able to create as much extra space below/above the maths as you like. (cid:147)A and(cid:148)iscreatedby B $A \over B$ \rule[-.3cm]{0cm}{1cm}{and} 1.13 MathsandPostscriptfonts It’s easy to use a postscript font (like helvetica) for the text of a LATEX document. What’s harder is using the same font for maths. An easy, reasonable option is to usethemathptmxpackagetoputthemathsintothepostscriptTimesandsymbol fontswherepossible. Alternatively,use themathpazopackage(loadsPalatinoasthetextfontfamilyandamixture (cid:15) ofthePazoandCMfontsformath). themathpplepackage(loadsPalatinoasthetextfontfamilyandamixture (cid:15) ofarti(cid:2)ciallyobliquedEulerfontsandCMfontsformath). Commercialandfreealternativesareunderdevelopment. 1.14 MatlabandLaTeX Matlab13 hassomesupportforLaTeXproduction. Forexample 13http://www-h.eng.cam.ac.uk/help/tpl/programs/matlab.html 10