Revision( • LaTeX(is(a(document(prepara4on(system( – Typesets'documents' • Commands( COMPSCI'111'/'111G' – Start'with'a'backslash'(\)' Mastering*Cyberspace:*** • Environments( An*introduc5on*to*prac5cal*compu5ng* – \begin{name} – \end{name} \documentclass[a4paper]{book} T X L A E \begin{document} ... \end{document} Text(Styles( \emph(versus(\tex4t( • \textbf {(Argument(will(be(bold(}( ( ( • \textit {( Argument*will*be*italic (}( \emph{I(want(to(\emph{emphasize(this}}( ( • \textsl {( Argument*will*be*slanted (}( I"want"to" emphasize(thi s" ( • \textsf {(Argument(will(be(sansAserif(}( ( • \textrm {( Argument will be serif (roman) (}( ( \tex4t{I(want(to(\tex4t{emphasize(this}}( • \texttt {( Argument will be monospace (}( ( I"want"to"emphasize"this" • \textsc {(A RGUMENT(WILL(BE(SMALL(CAPITALS (}(
Exercise( Font(Style( What(is(the(output(of(the(following(LaTeX(code?( • Forms( – DeclaraCve'form'(Set'style'from'this'point'forward)' ( – Environmental'form'(Create'an'environment'that'uses'this'style)' The \textbf{quick} \textit{brown} \textsl{fox} jumps \textsf{over} the \texttt{lazy} \textsc{Dog} 'Bold' – \bfseries ( 'Normal'weight'(i.e.'not'bold)' – \mdseries – \itshape 'Italic' – \slshape 'Slanted' – \upshape 'Upright'(opposite'of'slanted}' – \scshape 'Small'Capitals' – \rmfamily 'Serif'(roman)' – \sffamily 'SansMserif' – \ttfamily 'Monospace'(typewriter)' Example( Exercise( %Normal way to set italics What(would(the(output(of(the(following(code(be?( \textit{This text will be italic} ( %Environment form \begin{sffamily} \begin{itshape} The quick brown fox This text is also italic \end{sffamily} \end{itshape} jumps over \bfseries the lazy dog %Declarative form \itshape All text from this point forward will be italic This text will be italic This text is also italic All text from this point forward will be italic
Font(Size( SePng(the(scope(of(a(command( • New(way(to(apply(a(command( – Set'the'scope'of'the'command' – Command'only'applies'within'the'curly'braces' – Note:''this'works'with'the'declaraCve'forms'for'font'style'and'font'size' • Format:( {\command ... text goes here ... } Example( Aligning(paragraphs( • flushleft {\small This text is small} – Environment'that'aligns'a'paragraph'to'the'leP' {\Large\itshape This text is large and italic} { • flushright \tiny – Environment'that'aligns'a'paragraph'to'the'right' \textit{This text will be tiny and italic} This text will be tiny, but not italic. • center } – Environment'that'aligns'a'paragraph'to'the'centre' This text is small \begin{center} \begin{center} This text is large and italic furuike ya\\ Three things are certain:\\ kawazu tobikomu\\ Death, taxes, and lost data.\\ This text will be tiny and italic mizu no oto Guess which has occurred! This text will be tiny, but not italic. \end{center} \end{center}
Unordered(Lists( Ordered(Lists( • Unordered(Lists( • Ordered(Lists( – List'that'uses'bullet'points' – List'that'is'enumerated' – itemize 'environment' – enumerate 'environment' – \item 'used'to'idenCfy'each'item'in'the'list' – \item 'used'to'idenCfy'each'item'in'the'list' \begin{itemize} \begin{enumerate} \item Pears \item Pears \item Apples \item Apples \item Bananas \item Bananas \end{itemize} \end{enumerate} • Pears 1. Pears • Apples 2. Apples • Bananas 3. Bananas Descrip4on(Lists( Quotes(and(Quota4ons( • Descrip4on(Lists( • quote (environment( – List'that'is'used'to'define'terms' – Used'for'short'quotes' – description 'environment' – EnCre'environment'is'indented' – \item[ term ] 'used'to'idenCfy'each'term'in'the'list' – The'first'line'of'a'new'paragraph'inside' quote 'is'not'indented.' • quotation (environment( \begin{description} – Used'for'longer'quotes' \item[Pears] Say something really – EnCre'environment'is'indented' really really long about fruit – The'first'line'of'a'new'paragraph'inside' quotation 'is'indented' \item[Apples] More fruit \item[Bananas] Still more fruit This is a quote by Aristotle: \end{description} \begin{quote} There is only one way to avoid criticism: do nothing, say Pears Say something really really really long nothing, and be nothing. - Aristotle about fruit \end{quote} Apples More fruit Bananas Still more fruit
Quote(versus(Quota4on(Example( Verba4m( • verbatim (environment( – Reproduces'text'exactly'as'it'appears' – Uses'a'monospace'font'(courier)' This is a quote by Aristotle: – OPen'used'for'computer'code' – No'latex'commands'can'be'used'in' verbatim There is only one way to avoid criticism: do nothing, say nothing, and be nothing. - Aristotle The following commands are used in LaTeX \begin{verbatim} This is a quote by Aristotle: Use \\ to create a line break. Use \section{ name } to create a new section. There is only one way to avoid criticism: do nothing, say \end{verbatim} nothing, and be nothing. – Aristotle There is only one way to avoid criticism: do nothing, say nothing, and be nothing. - Aristotle There is only one way to avoid criticism: do nothing, say The following commands are used in LaTeX nothing, and be nothing. - Aristotle Use \\ to create a line break. Use \section{ name } to create a new section. Mathema4cs( Examples( • Three(ways(to(enter(mathema4cs(mode( The equation x = y is a The equation $x = y$ is a simple equation. simple equation. • Inline(text( – $ ... $ The equation: The equation: \begin{displaymath} • displaymath (environment( x = y x = y – Centres'the'maths'on'a'line'of'its'own' \end{displaymath} is a simple equation. is a simple equation. • equation (environment( The equation: – Centres'the'maths'on'a'line'of'its'own' The equation: \begin{equation} – Numbers'the'maths'with'an'equaCon'number' x = y x = y (1.1) \end{equation} is a simple equation. is a simple equation.
Laying(out(mathema4cs( Other(common(func4ons( • Too(many(commands(to(memorise( • Square(roots( – Look'up'the'commands'when'we'need'them' – \sqrt{ ... } – Any'symbol,'any'structure'exists'somewhere' – Example: \sqrt{ x^2 + y^2 } – We'will'look'at'the'most'common'commands' – To'apply'leYers'to'a'group,'we'put'curly'braces'around'them' • Frac4ons( – \frac{ numerator } { denominator } • Exponent( – Example:' ' ' 3\frac{ 1 }{ 2 } – Carat'(^)' – Example:' n^{th} • Sum( n th – \sum – Example:' ' ' \sum_{k=1}^{n} k • Subscripts( – Underscore'(_)' – Example:' s_0 s 0 Example( Exercise( If a quadratic equation is given by: \begin{displaymath} f(x) = ax^2 + bx + c \sum_{k=1}^{n} k = \frac{1}{2}n(n+1) = \frac{n(n+1)}{2} \end{displaymath} Then the formula for calculating the roots of a quadratic equation is: \begin{displaymath} x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \end{displaymath}
Exercise( Exercise( • Write(the(code(that(reproduces(the(following(LaTeX:( The sum of a geometric series is: \begin{displaymath} \sum_{k=0}^{n}ar^{k}=ar^{0}+ar^{1}+ar^{2}+ar^{3}+\ldots+ar^{n} \end{displaymath} We can rearrange the equation to produce the simple formula: \begin{displaymath} \sum_{k=0}^{n}ar^{k}=\frac{a(1-r^{n+1})}{1-r} \end{displaymath} Adding(func4onality( graphicx( • \usepackage{ packagename } • Package(that(allows(you(to(import(graphics( – A'library'that'adds'or'modifies'the'commands'available' – Graphics'must'be'in'.eps'format'(latex'compiler)'or'.jpg/.png'(pdflatex'compiler)' – Thousands'of'packages'available' – Can'set'width'and'height' – Some'are'very'useful' – Other'opCons'are'also'available' • \includegraphics[options]{Example.png} • Add(the(\usepackage(command(to(the(preamble( \documentclass[a4paper]{article} \usepackage{graphicx} \documentclass[a4paper]{article} \usepackage{graphicx} \begin{document} This is a simple picture \begin{document} ... \begin{center} \end{document} \includegraphics[width=10cm]{Example.png} \end{center} \end{document}
Summary( • LaTeX(is(a(very(good(typesePng(package( – Excellent'for'mathemaCcs' – Excellent'for'long'documents' – Excellent'for'people'who'really'care'about'presentaCon' – Very'configurable' – Steep'learning'curve'(but'worth'it'for'those'that'bother)' • Recommended(soXware(for(use(on(Windows( – MikTeX'(LaTeX'distribuCon)' – TeXWorks'(text'editor'with'built'in'LaTeX'compiler)'
Recommend
More recommend