latex/handout.rst
changeset 104 828c65311bdf
parent 103 313bebeb7862
child 157 3174d4803cd5
equal deleted inserted replaced
103:313bebeb7862 104:828c65311bdf
     1 LaTeX
     1 LaTeX
     2 =====
     2 =====
     3 
     3 
     4 Introduction
     4 Introduction
     5 ------------
     5 ------------
     6 LaTeX is a typesetting program that produces excellently typeset documents. Typesetting is placing text onto a page with all the style formatting defined, so that content looks as intended. It is extensively used for producing high quality scientific and mathematical documents. It is also used for producing other kinds of documents, ranging from simple one page articles or letters to books. LaTeX is based on the TeX typesetting language. 
     6 
     7 
     7 LaTeX is a typesetting program that produces excellently typeset
     8 TeX
     8 documents. Typesetting is placing text onto a page with all the style
     9 ~~~
     9 formatting defined, so that content looks as intended. It is
    10 
    10 extensively used for producing high quality scientific and
    11 TeX is a typesetting system designed and developed by Donald E. Knuth, the renowned Computer Scientist and Emeritus professor at Stanford University.
    11 mathematical documents. It is also used for producing other kinds of
    12 
    12 documents, ranging from simple one page articles or letters to
    13 It was designed with two goals in mind-
    13 books. LaTeX is based on the TeX typesetting language.
    14 
       
    15 1. To allow anybody to produce high-quality books using a reasonable amount of effort. 
       
    16 2. To provide a system that would give the exact same results on all computers, now and in the future
       
    17 
       
    18 TeX is well known for it's stability and portability. TeX is known to be virtually bug free. 
       
    19 
       
    20 The current version of TeX is 3.1415926 and is converging to π.
       
    21 
       
    22 LaTeX
       
    23 ~~~~~
       
    24 
       
    25 LaTeX is an extension of TeX, consisting of TeX macros and a program to parse the LaTeX files. It is supposed to be an easier to use language than TeX, but producing the same quality of output. It was developed by Leslie Lamport in the early 1980s and is now being maintained and developed by the LaTeX3 Project.
       
    26 
    14 
    27 LaTeX is pronounced either as "Lah-tech" or "Lay-tech"
    15 LaTeX is pronounced either as "Lah-tech" or "Lay-tech"
       
    16 
       
    17 In this course, we shall use the sample document, ``sample.pdf``, as a
       
    18 tool to learn various commands of LaTeX. By the end of the sessions on
       
    19 LaTeX, we will have produced a copy of that document, starting from
       
    20 scratch.
       
    21 
       
    22 A Look at the Sample Document
       
    23 -----------------------------
       
    24 
       
    25 Let's first look at the basic structure of the sample document.
       
    26 
       
    27 Slides with screen shots of
       
    28 
       
    29   * Title, Author, Date
       
    30   * Abstract
       
    31   * Sections
       
    32   * Subsections
       
    33   * Appendix
       
    34   * References/Bibliography
       
    35   * Tables
       
    36   * Figures
       
    37   * Math
       
    38 
       
    39 Writing the source & compiling it
       
    40 ---------------------------------
       
    41 
       
    42 Let's begin with a simple hello world, to see how to write a LaTeX
       
    43 document and compile it.  Write the following code into the file
       
    44 ``draft.tex``.  ::
       
    45 
       
    46   \documentclass{article}
       
    47   \begin{document}
       
    48   SciPy is open-source software for mathematics, science, and engineering.   
       
    49   \end{document}
       
    50 
       
    51 To compile the document, do the following in your terminal::
       
    52 
       
    53   $ pdfLaTeX draft.tex
       
    54 
       
    55 This produces the output file ``draft.pdf``
       
    56 
       
    57 Note: The ``LaTeX`` command is often used, instead of ``pdfLaTeX`` to
       
    58 get the ``dvi`` output. But, throughout this course, we shall use
       
    59 pdfLaTeX to compile our documents.
       
    60 
       
    61 ``\documentclass``
       
    62 ------------------
       
    63 
       
    64 The documentclass command, defines the structure and formatting of our
       
    65 document. LaTeX typsets the document, based on the documentclass.
       
    66 
       
    67 LaTeX is a document based markup language. 
       
    68 
       
    69 First of all, a markup language is a system of annotating text or
       
    70 adding in extra information to the text that specifies it's structure
       
    71 or presentation.
       
    72 
       
    73 LaTeX is a document based markup and not an element based one. You
       
    74 generally don't have to worry about typesetting each of the elements
       
    75 of your document. Choosing an appropriate documentclass, gives you a
       
    76 suitable typesetting. You as an author can worry about the content of
       
    77 the document, rather than the appearance or presentation of the
       
    78 document.
    28 
    79 
    29 Why should you use it?
    80 Why should you use it?
    30 ~~~~~~~~~~~~~~~~~~~~~~
    81 ~~~~~~~~~~~~~~~~~~~~~~
    31 
    82 
    32 A few reasons for using LaTeX - 
    83 A few reasons for using LaTeX - 
    33 
    84 
    34   * It produces documents with excellent visual quality. 
    85   * It produces documents with excellent visual quality.
    35   * It does the typesetting for you, leaving you - the author - to focus on writing the content.
    86   * It does the typesetting for you, leaving you - the author - to
       
    87     focus on writing the content.
    36   * It makes writing math just as easy as writing simple text.
    88   * It makes writing math just as easy as writing simple text.
    37   * It's renowned for it's stability and a virtually bug free code base. 
    89   * It's renowned for it's stability and a virtually bug free code
    38   * It is light on your resources as compared to most of the word processors available today. 
    90     base.
    39   * It uses plain text files as input and can give output in a variety of formats including PDFs and html making it platform independent.
    91   * It is light on your resources as compared to most of the word
       
    92     processors available today.
       
    93   * It uses plain text files as input and can give output in a variety
       
    94     of formats including PDFs and html making it platform independent.
    40   * It is free software (free as in freedom) and gratis too.
    95   * It is free software (free as in freedom) and gratis too.
    41   * It is widely used and has a large user community. 
    96   * It is widely used and has a large user community. 
    42 
    97 
    43 First Document
    98 
    44 --------------
    99 ``\begin`` and ``\end`` commands define environments. In our document,
    45 
   100 we have the document environment, which defines the beginning and end
    46 Let's begin by writing a simple LaTeX, Hello World, document. The following code is typed out into a text editor. 
   101 of the content of the document. We place all the content of the
       
   102 document within this environment.
       
   103 
       
   104 Also, as you may have noticed, all the commands in LaTeX begin with a
       
   105 ``\``. Note that they are case sensitive. Command names in LaTeX
       
   106 usually have only alpha characters. Any characters other than alpha
       
   107 characters, terminate the command name. Parameters to commands are
       
   108 passed in ``{ }``.
       
   109 
       
   110 
       
   111 Top Matter
       
   112 ----------
       
   113 
       
   114 Let us begin with adding the Title, Author's name and the date to the
       
   115 document.
    47 
   116 
    48 ::
   117 ::
    49 
   118 
    50   %hello.tex - The Hello World of LaTeX
       
    51   \documentclass{article}
   119   \documentclass{article}
    52 
   120   \title{A Glimpse at Scipy}
       
   121   \author{FOSSEE}
       
   122   \date{June 2010}
    53   \begin{document}
   123   \begin{document}
    54     Hello, World!
   124   \maketitle
       
   125   SciPy is open-source software for mathematics, science, and engineering.   
    55   \end{document}
   126   \end{document}
    56 
   127 
    57 Save the file as ``hello.tex`` and open up a terminal to compile your ``tex`` file to get the output in a ``pdf`` format. 
   128 We add the title, the author and the date to the document before the
    58 
   129 ``\begin{document}`` directive. We compile the document to see if the
    59 Compiling & Output
   130 details appear in the document, but they donot. These details do not
    60 ~~~~~~~~~~~~~~~~~~
   131 appear in the document until we use the ``\maketitle`` command with
       
   132 the document environment to instruct LaTeX to place the top matter
       
   133 information into the document. Now the document has these details, on
       
   134 compiling again.
       
   135 
       
   136 If no date is specified, LaTeX automatically inserts the current date.
       
   137 
       
   138 Abstract
       
   139 --------
       
   140 
       
   141 Next we shall add an abstract to our document. LaTeX provides an
       
   142 environment, for adding an abstract to the document.  ::
       
   143 
       
   144   \documentclass{article}
       
   145 
       
   146   \title{A Glimpse at Scipy}
       
   147   \author{FOSSEE}
       
   148   \date{June 2010}
       
   149 
       
   150   \begin{document}
       
   151 
       
   152   \maketitle
       
   153 
       
   154   \begin{abstract}
       
   155   This document shows a glimpse of the features of Scipy that will be explored during this course.
       
   156   \end{abstract}
       
   157 
       
   158   SciPy is open-source software for mathematics, science, and engineering.   
       
   159   \end{document}
       
   160 
       
   161 The abstract environment is placed at the location where we wish it to
       
   162 appear in the document.
       
   163 
       
   164 Sections
       
   165 --------
       
   166 
       
   167 Now let's look at how to add (chapters,) sections and sub-sections to
       
   168 our document. Let's add the section headings and sub headings present
       
   169 in our sample document to the working copy of our document.
       
   170 
       
   171 ``\section``, ``\subsection``, ``\subsubsection``
       
   172 
       
   173 On compiling, we can see that the headings of the sections and the
       
   174 sub-sections appear in the document.
       
   175 
       
   176 You may have noticed that LaTeX automatically numbers the sections. To
       
   177 prevent a section from getting numbered, an asterix is appended to the
       
   178 corresponding sectioning command.
       
   179 
       
   180 If the document was a longer document, we could have used a report or
       
   181 a book class. (Note: Books donot have the abstract environment.) Let's
       
   182 look at what happens to the document, when we change it to the report
       
   183 class.
       
   184 
       
   185 The numbering strangely begins from zero, now. This is because,
       
   186 chapters have an additional sectioning command called
       
   187 ``\chapter``. The chapter is one level above a section and since, our
       
   188 document does not have a ``\chapter`` command, the sections are
       
   189 numbered from 0. To change this, we add a chapter command before the
       
   190 first section. We say::
       
   191 
       
   192   \chapter{One}
       
   193 
       
   194 Now, observe that we now have a chapter title appearing and the
       
   195 numbering starting from 1.
       
   196 
       
   197 Also, note that the subsubsections donot get a numbering now. This is
       
   198 controlled by a variable called the secnumdepth. By default it is set
       
   199 to 2. We can now, change it to 3 and get numbering for subsubsections
       
   200 also.  ::
       
   201 
       
   202   \setcounter{secnumdepth}{3}
       
   203 
       
   204 What do you expect to happen if we changed the secnumdepth to 1? What
       
   205 if it is 0? -1? {Lab excercise}
       
   206 
       
   207 
       
   208 Appendix
       
   209 --------
       
   210 
       
   211 Notice that our document also has an appendix. Let's add an appendix
       
   212 to our document.
    61 
   213 
    62 ::
   214 ::
    63 
   215 
    64   $pdflatex hello.tex
   216   \appendix
    65 
   217   \section{Plotting using Pylab}
    66   Output written on hello.pdf (1 page, 5733 bytes).
   218 
    67   Transcript written on hello.log.
   219 Table of Contents
    68 
   220 -----------------
    69 Open the ``hello.pdf`` to see the output as shown. 
   221 
    70 
   222 Our sample document is not long enough to warrant a table of contents,
    71 Note: The command ``latex`` is often used to get the ``dvi`` output. But, throughout this course, we shall use pdflatex to compile our documents. 
   223 but let us learn to add a table of contents to a LaTeX document. If
    72 
   224 you ever tried adding a table of contents, to a document in a
    73 What does it mean? - Understanding the source
   225 wordprocessor, you would know how much of a trouble it is. In LaTeX,
    74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   226 it is a matter of just one command and placing the command at the
    75 
   227 location where you would want to have the table of contents. Let's now
    76 ``%hello.tex - First LaTeX document``
   228 add a table of contents to our draft. Now, compile the document and
    77 
   229 look at the output document. It does not have the table of contents!
    78   The first line is a comment. It is meant only for human readers and LaTeX simply ignores that line. Anything following a ``%`` symbol, until the end of the line, is ignored by LaTeX. 
   230 
    79 
   231 On the first compilation only the "Contents" heading appears in the
    80 ``\documentclass{article}``
   232 document, but the actual table does not appear. You will need to
    81 
   233 compile your document once more, for the actual table to appear in
    82   This line is a command and sets the ``documentclass`` of the document to ``article``. LaTeX has other classes like ``report``, ``book``, ``letter``, etc. The typesetting of the document varies, depending on the ``documentclass`` of the document. 
   234 your document. On the first run, LaTeX has gone through your document
    83 
   235 and generated a temporary file (``.toc``), with the entries that
    84 
   236 should go into the table of contents. These entries are made, when you
    85 ``\begin{document}``
   237 compile your document for the second time.
    86 
   238 
    87   This line informs LaTeX that this is the beginning of the content of the document. The command, technically speaking, marks the beginning of the ``document`` environment. 
   239 Note that any section/block that has been numbered automatically
    88 
   240 appears in the table of contents. It is possible to get un-numbered
    89 ``Hello, World!``
   241 sections, for instance a Preface or a Foreword section to appear in
    90 
   242 the Table of Contents.
    91   This is the actual text displayed in the document. 
   243 
    92 
   244 Let's change our Introduction section to be an un-numbered one and try
    93 ``\end{document}``
   245 to make it appear in the table-of-contents.  ::
    94 
       
    95   The end command marks the end of the ``document`` environment. It tells LaTeX that the document is complete and LaTeX will simply ignore anything written after this line.
       
    96 
       
    97 Some Basics
       
    98 ~~~~~~~~~~~
       
    99 
       
   100 LaTeX treats multiple empty spaces (or lines) as a single space (or line). An empty line between two lines of text is considered as a change of paragraphs. 
       
   101 
       
   102 In order to explicitly instruct LaTeX to start a new-line, ``\\`` or ``\newline`` command is used. Appending ``*`` to ``\\``,  instructs LaTeX to create a new line, without creating a new page at that point. 
       
   103 
       
   104 As already mentioned, ``%`` symbol marks the beginning of a comment. How would we then use it in our document's text? ``%`` is one of the many special characters and is used by escaping it with a backslash, as shown. Other special characters are  ``~ # $ ^ & _ { } \``. All of them, except the backslash character, can be inserted in the document by escaping them with a ``\`` character. To insert the ``\`` character, ``\textbackslash`` must be used. 
       
   105 
       
   106 ::
       
   107 
       
   108   %hello.tex - First LaTeX document
       
   109   \documentclass{article}
       
   110   \begin{document}
       
   111   Hello,       World!
       
   112   This will not start a new line. 
       
   113 
       
   114   But, this will start a new paragraph. 
       
   115   Again no new line. \% what follows isn't a comment. 
       
   116   \end{document}
       
   117   This is text that is ignored. 
       
   118 
       
   119 Basic Structure
       
   120 ---------------
       
   121 
       
   122 ``\documentclass``
       
   123 ~~~~~~~~~~~~~~~~~~
       
   124 As already stated, the ``documentclass`` command tells LaTeX, the type of the document that you intend to create. Each class has a few differences in how the content of the document is typeset. 
       
   125 
       
   126 Some of the available LaTeX classes are, article, proc, report, book, slides, letter. 
       
   127 
       
   128 The ``documentclass`` command also accepts a few optional parameters. For example::
       
   129   \documentclass[12pt,a4paper,oneside,draft]{report}
       
   130 
       
   131 ``12pt`` specifies the size of the main font in the document. The relative sizes of the various fonts is maintained, when the font size is changed. If no size is specified, ``10pt`` is assumed by default. 
       
   132 
       
   133 ``a4paper`` specifies the size of the paper to be used for the document. 
       
   134 
       
   135 ``oneside`` specifies that the document will be printed only on one side of the paper. The ``article`` and ``report`` classes are ``oneside`` by default and the ``book`` class is ``twoside``.
       
   136 
       
   137 ``draft`` marks the hyphenation and justification problems in the document with a small square in the right hand margin of the document, so that they can be easily spotted. 
       
   138 
       
   139 Note: Everything written in between the ``\documentclass`` command and the ``\begin{document}`` command is called the Preamble. 
       
   140 
       
   141 
       
   142 Top Matter
       
   143 ~~~~~~~~~~
       
   144 
       
   145 The information about the document such as it's title, the date, the author(s) information etc, is collectively known as the topmatter. The term topmatter is frequently used in LaTeX documentation. 
       
   146 
       
   147 Let us add top matter to our document, now. 
       
   148 ::
       
   149 
       
   150   \title{LaTeX - A How-to}
       
   151   \author{The FOSSEE Team}
       
   152   \date
       
   153 
       
   154 The  commands ``\title`` and  ``\author`` are self explanatory. 
       
   155 The ``\date`` command automatically puts in today's date into the document. Now let us compile and look at the result. 
       
   156 
       
   157 To put a specific date, you can specify it as below
       
   158 
       
   159 :: 
       
   160 
       
   161   \date{June 1, 2010}
       
   162 
       
   163 These details do not appear in the document until we use the ``\maketitle`` command with the document environment to instruct LaTeX to place the top matter information into the document. 
       
   164 
       
   165 Sectioning Commands
       
   166 ~~~~~~~~~~~~~~~~~~~
       
   167 
       
   168 Documents are often divided into parts, chapters, sections and subsections. LaTeX provides an intuitive mechanism to use them in your documents. 
       
   169 
       
   170 +-------------------+-------+------------------------+
       
   171 | command           | level | comments               |
       
   172 +-------------------+-------+------------------------+
       
   173 | ``part``          |    -1 | not in letters         |
       
   174 +-------------------+-------+------------------------+
       
   175 | ``chapter``       |     0 | only books and reports |
       
   176 +-------------------+-------+------------------------+
       
   177 | ``section``       |     1 | not in letters         |
       
   178 +-------------------+-------+------------------------+
       
   179 | ``subsection``    |     2 | not in letters         |
       
   180 +-------------------+-------+------------------------+
       
   181 | ``subsubsection`` |     3 | not in letters         |
       
   182 +-------------------+-------+------------------------+
       
   183 | ``paragraph``     |     4 | not in letters         |
       
   184 +-------------------+-------+------------------------+
       
   185 | ``subparagraph``  |     5 | not in letters         |
       
   186 +-------------------+-------+------------------------+
       
   187 
       
   188 LaTeX has seven levels of sectioning commands, as shown above. 
       
   189 
       
   190 Text of a block or a section of the document need not be enclosed within ``\begin`` and ``\end`` commands. LaTeX starts a new block each time it finds a sectioning command. 
       
   191 ::
       
   192 
       
   193   \section[Short Title]{This is a very long title and the Short Title will appear in the Table of Contents.}
       
   194 
       
   195 The short title appears in the table of contents, if at all one is generated. 
       
   196 
       
   197 Section Numbering
       
   198 +++++++++++++++++
       
   199 
       
   200 As you may have observed, numbering is done automatically in LaTeX. Parts are numbered using roman numerals; Chapters and sections are numbered using decimal numbers. When a table of contents is inserted into the document, all the numbered headings automatically appear in it.
       
   201 
       
   202 A sectioning command appended with an asterisk gives an unnumbered heading that is not included in the table of contents.
       
   203 ::
       
   204 
   246 
   205   \section*{Introduction}
   247   \section*{Introduction}
   206 
   248   \addcontentsline{toc}{section}{Intro}
   207 By default, levels up to 2, are numbered, i.e, parts, chapters, sections and subsections. This can be changed by setting the ``secnumdepth`` counter using the ``\setcounter`` command. The following command removes numbering of the subsections. Only parts, chapters and sections will be numbered. 
   249 
   208 ::
   250 We shall talk about adding and managing bibliographies, later in the
   209 
   251 course.
   210   \setcounter{secnumdepth}{1}
   252 
   211 
   253 Now, that we have the basic structure of the document, let's get into
   212 
   254 the content and the details of it.
   213 Appendices
       
   214 ~~~~~~~~~~
       
   215 
       
   216 LaTeX allows for separate numbering for appendices. ``\appendix`` command indicates that the sections following it, are to be included in the appendix. 
       
   217 ::
       
   218 
       
   219   \appendix
       
   220   \chapter{First Appendix}
       
   221 
       
   222 Abstract
       
   223 ~~~~~~~~
       
   224 LaTeX provides an ``abstract`` environment, to place an abstract in a document. The abstract appears in the document after the topmatter but before the main body of the document. 
       
   225 ::
       
   226 
       
   227   \begin{abstract}
       
   228     The abstract abstract.
       
   229   \end{abstract}
       
   230 
       
   231 By default LaTeX uses the word "Abstract" as a title for the abstract. This can be changed using the ``\renewcommand``. 
       
   232 ::
       
   233 
       
   234   \renewcommand{\abstractname}{Summary}
       
   235 
       
   236 
       
   237 
       
   238 Table of Contents
       
   239 ~~~~~~~~~~~~~~~~~
       
   240 
       
   241 Parts, chapters or sections that have been auto numbered by LaTeX automatically appear in the Table of Contents (ToC). ``\tableofcontents`` command places the ToC at the location, where the command has been issued. 
       
   242 
       
   243 The counter ``tocdepth`` specifies the depth up to which headings appear in the ToC. It can be set using the ``\setcounter`` command as shown below. 
       
   244 ::
       
   245 
       
   246   \setcounter{tocdepth}{3}
       
   247 
       
   248 Unnumbered sections can be placed in the table of contents using the ``\addcontentsline`` command as shown below.
       
   249 ::
       
   250 
       
   251   \section*{Preface}
       
   252   \addcontentsline{toc}{section}{Preface}
       
   253 
       
   254 Note: To get the correct entries in your table of contents, you will need to run one extra compilation, each time. This is because, the entries of the table of contents are collected during each compilation of the document and utilized during the next compilation. 
       
   255 
   255 
   256 Typesetting Text
   256 Typesetting Text
   257 ----------------
   257 ----------------
   258 
   258 
   259 Text formatting
   259 Let's begin with adding the second paragraph to the introduction
   260 ~~~~~~~~~~~~~~~
   260 section. Let's place the text of the second para, after the first
   261 
   261 line, that we already have. Now, compile the document. 
   262 Font Styles and Size
   262 
   263 ++++++++++++++++++++
   263 Notice, that the second para appears in continuation with the previous
   264 
   264 line. To start a new paragraph in LaTeX, we need to insert an empty
   265 LaTeX has three font families:
   265 line. Multiple empty lines are considered as a single empty line. To
   266 
   266 start a new line, use the ``\newline`` or ``\\`` command. Notice the
   267  1. roman ``\textrm{your text here}``
   267 difference (in the output), in starting a new paragraph and starting a
   268  2. serif ``\textsf{your text here}``
   268 newline. A new paragraph is indented.
   269  3. monospace ``\texttt{your text here}``
       
   270 
       
   271 For emphasizing text, *italics* are generally used. The ``\emph`` command is used to emphasize text. 
       
   272 ``\textbf`` gives  **bold face** text. Underlines can be made using the ``\uline`` command and ``\sout`` strikes out text. For small caps, ``\textsc`` command is to be used. 
       
   273 
       
   274 LaTeX provides a series of commands to change the size of text. The table below shows the commands and the size of text, they produce. 
       
   275 
       
   276 +-------------------+----------------+-------------+-------------+
       
   277 | size              | 10pt (default) | 11pt option | 12pt option |
       
   278 +===================+================+=============+=============+
       
   279 | ``\tiny``         | 5pt            | 6pt         | 6pt         |
       
   280 +-------------------+----------------+-------------+-------------+
       
   281 | ``\scriptsize``   | 7pt            | 8pt         | 8pt         |
       
   282 +-------------------+----------------+-------------+-------------+
       
   283 | ``\footnotesize`` | 8pt            | 9pt         | 10pt        |
       
   284 +-------------------+----------------+-------------+-------------+
       
   285 | ``\small``        | 9pt            | 10pt        | 11pt        |
       
   286 +-------------------+----------------+-------------+-------------+
       
   287 | ``\normalsize``   | 10pt           | 11pt        | 12pt        |
       
   288 +-------------------+----------------+-------------+-------------+
       
   289 | ``\large``        | 12pt           | 12pt        | 14pt        |
       
   290 +-------------------+----------------+-------------+-------------+
       
   291 | ``\Large``        | 14pt           | 14pt        | 17pt        |
       
   292 +-------------------+----------------+-------------+-------------+
       
   293 | ``\LARGE``        | 17pt           | 17pt        | 20pt        |
       
   294 +-------------------+----------------+-------------+-------------+
       
   295 | ``\huge``         | 20pt           | 20pt        | 25pt        |
       
   296 +-------------------+----------------+-------------+-------------+
       
   297 | ``\Huge``         | 25pt           | 25pt        | 25pt        |
       
   298 +-------------------+----------------+-------------+-------------+
       
   299 
       
   300 
       
   301 Superscript and Subscript
       
   302 +++++++++++++++++++++++++
       
   303 
       
   304 For superscripting text in the text mode, LaTeX provides the ``\textsuperscript`` command. 
       
   305 ::
       
   306 
       
   307   This is how you super\textsuperscript{script} text. 
       
   308 
       
   309 LaTeX does not provide any command for subscripting text in the text mode. The math mode needs to be used to obtain subscripts. 
       
   310 
       
   311 ::
       
   312 
       
   313   This is sub_{script}
       
   314 
   269 
   315 Quotation Marks
   270 Quotation Marks
   316 +++++++++++++++
   271 ---------------
   317 
   272 
   318 When typing in LaTeX, the double quotation mark ``"`` character shouldn't be used. The grave accent ````` character produces the left quote and the apostrophe ``'`` character produces the right quote. To obtain double quotes they are, each, used twice. 
   273 Look at the quotation marks around the text, Sigh Pie. They are not
   319 ::
   274 formatted properly. To place quotation marks in LaTeX, you should use
   320 
   275 ````` character for the left quote & ``'`` character for the right
   321   `` Here is an example of putting `text' in quotes ''
   276 quote. For double quotes, they should be used twice.
   322 
   277 
   323 Dashes and Hyphens
   278 Fonts
   324 ++++++++++++++++++
   279 -----
   325 
   280 
   326 LaTeX has four dashes of different lengths. Three of them can be produces with different number of consecutive dashes. The short dashes are used for hyphens, slightly longer ones for number ranges and the longest ones for comments. The fourth one is a mathematical symbol, the minus sign. 
   281 The names of the software tools, Scilab, Matlab, etc. appear in
   327 ::
   282 italics or emphasized as it is called in LaTeX. To emphasize text, the
   328 
   283 ``\emph`` command is used.
   329   The names of these dashes are: `-' hyphen, `--' en-dash, `---' em-dash and `$-$' minus sign.
   284 
   330 
   285 Let's also add the contents of the subsection "Sub-packages of
   331 The names for these dashes are: ‘‐’ hyphen, ‘–’ en-dash, ‘—’ em-dash and ‘−’ minus sign.
   286 Scipy". We shall add the table as plain text, until we learn how to
   332 
   287 edit tables.
   333 Lists - Itemize, Enumerate, and Description
   288 
   334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   289 Let's try and form a tabular structure by separating the left and
   335 LaTeX has three different environments for producing lists. Itemize, Enumerate and Description allow you to produce lists of various types in LaTeX. 
   290 right columns using spaces. On compiling we find that LaTeX doesn't
   336 
   291 add multiple spaces between words. Just like multiple empty lines,
   337 Itemize is used to produce unnumbered lists. The bullets of the list can be easily changed to use any character. Enumerate environment allows you to produce auto-numbered lists. The description environment, allows you to produce a list of definitions. These environments can be nested within each other, easily. 
   292 multiple spaces are considered as a single space.
   338 
   293 
   339 ::
   294 The names of the sub-packages appear in a fixed width font in the
   340 
   295 sample document provided to us. The headings of the columns appear in
   341   \begin{itemize}
   296 bold-face. Let's make changes to this effect.
   342     \item Now we move onto some elementary \emph{Text Typesetting}.
   297 
   343     \item How do we get \emph{emphasized or italic text}?
   298 ``\textbf`` is used to change text to bold face and ``\texttt`` is
   344     \item \emph{Did you wonder what happens when we try \emph{emphasizing text} within \emph{emphasized text}}?
   299 used to change text to fixed width font.
   345     \item ``Beautiful is better than ugly.''
   300 
   346   \end{itemize}
   301 We could also change the separating - (hyphen) to an em-dash (or
   347   
   302 en-dash) -- is em-dash and --- is an em-dash, to improve the
   348   \begin{description}
   303 appearance of the document.
   349     \item[Description] This list is a description list. 
   304 
   350     \item[Enumerate] Numbered lists are often useful.
   305 Lists
   351       \begin{enumerate}
   306 -----
   352       \item First
   307 
   353       \item Second
   308 The section on Use of Scipy in this course, contains lists. Let's now
   354       \item Third
   309 add lists to our document. The ``enumerate`` environment adds numbered
   355       \item \ldots
   310 lists to our document and the ``itemize`` environment adds un-numbered
   356       \end{enumerate}
   311 lists. ``\item`` command adds a new entry to a list. Note, that LaTeX
   357     \item[Itemize] The list above this description list is an itemize list.
   312 can easily handle nested lists. In fact most environments can be
   358   \end{description}
   313 embedded within other environments, without any problems.
   359   
   314 
   360 Special Paragraphs
   315 LaTeX also has a description list, which shall be looked at, during
   361 ~~~~~~~~~~~~~~~~~~
   316 the lab sessions.
   362 
   317 
   363 Footnotes
   318 Footnotes, Labels and References
   364 +++++++++
   319 --------------------------------
   365 
   320 
   366 With the command::
   321 Let's now add the footnote to pylab. LaTeX provides a footnote command
   367 
   322 to add a footnote.
   368   \footnote{footnote text}
   323 
   369 
   324 We added the footnote with Appendix A, as plain text. But, in case we
   370 a footnote is printed at the foot of the current page. Footnotes should always be put after the word or sentence they refer to. Footnotes referring to a sentence or part of it should therefore be put after the comma or period.
   325 added another Appendix before the section on using ``pylab``, the
   371 
   326 footnote will have to be edited. To avoid this, LaTeX provides a handy
   372 Quotes
   327 system of labels and referencing.
   373 ++++++
   328 
   374 
   329 We first add a label to the section that we want to refer in this
   375 LaTeX provides a ``quote`` environment that can be used for quoting, highlighting important material, etc. 
   330 footnote. Then, we change the footnote, and add the reference to this
   376 ::
   331 label instead of the character A. If you look at the output after
   377 
   332 compiling the document once, you will see that the footnote has
   378   The Zen of Python
   333 question marks instead of the section number.  You will have to
   379   \begin{quote}
   334 compile once again, for the section number to appear in the footnote.
   380     The Zen of Python, by Tim Peters
   335 
   381     
   336 
   382     Beautiful is better than ugly.
   337 Including code
   383     Explicit is better than implicit.
   338 --------------
   384     Simple is better than complex.
   339 
   385     Complex is better than complicated.
   340 In the footnote above, and in the table for the sub-packages list, we
   386     Flat is better than nested.
   341 used the ``\texttt`` command to get a fixed width font. But we could
   387     Sparse is better than dense.
   342 instead use an environment provided by LaTeX to include pre-formatted
   388     Readability counts.
   343 text or code. LaTeX by default provides the verbatim environment to
   389     Special cases aren't special enough to break the rules.
   344 include pre-formatted text. You can try that out during the lab
   390     Although practicality beats purity.
   345 session. We shall look at using the listings package, specifically
   391     Errors should never pass silently.
   346 meant for including code in our document.
   392     Unless explicitly silenced.
   347 
   393     In the face of ambiguity, refuse the temptation to guess.
   348 First of all you need to tell LaTeX, that you want to use the listings
   394     There should be one-- and preferably only one --obvious way to do it.
   349 package in your document. We add the directive
   395     Although that way may not be obvious at first unless you're Dutch.
   350 ``\usepackage{listings}`` to the preamble of our document.
   396     Now is better than never.
   351 
   397     Although never is often better than *right* now.
   352 Then we set the language of the code that we are going to embed into
   398     If the implementation is hard to explain, it's a bad idea.
   353 our document. For this we use the lstset command.  ::
   399     If the implementation is easy to explain, it may be a good idea.
   354  
   400     Namespaces are one honking great idea -- let's do more of those!
       
   401   \end{quote}
       
   402 
       
   403 LaTeX provides two other similar environments, the quotation and the verse environments. 
       
   404 
       
   405 Verbatim
       
   406 ++++++++
       
   407 The verbatim environment allows us to insert pre-formatted text in a LaTeX document. It is useful for inserting code samples within the document. The verbatim text needs to be enclosed between ``\begin{verbatim}`` and ``\end{verbatim}``. 
       
   408 ::
       
   409 
       
   410   \begin{verbatim}
       
   411   from numpy import *
       
   412   a = linspace(0, 5, 50, endpoint = False)
       
   413   \end{verbatim}
       
   414 
       
   415   from numpy import *
       
   416   a = linspace(0, 5, 50, endpoint = False)
       
   417 
       
   418 To insert verbatim text in-line, the ``\verb`` command can be used. 
       
   419 ::
       
   420   
       
   421  The verb command allows placing \verb|verbatim text| in-line. 
       
   422 
       
   423 The | is just an example of a delimiter character. You can use any character except letters, * or space.
       
   424 
       
   425 Including Code
       
   426 ++++++++++++++
       
   427 
       
   428 The ``listings`` package can be used to embed source code into your LaTeX document. We shall briefly explore inserting python code into our document. 
       
   429 
       
   430 Obviously, you first need to tell LaTeX that you want it to use the ``listings`` package, using the ``\usepackage`` command. 
       
   431 ::
       
   432 
       
   433   \usepackage{listings}
       
   434 
       
   435 Then, we tell LaTeX that we are going to embed Python code into this document. A simple code highlighting for Python code can be achieved using this. 
       
   436 ::
       
   437 
       
   438   \lstset{language=Python,
   355   \lstset{language=Python,
   439           showstringspaces=false,
   356           showstringspaces=false,}
   440          }
   357 
   441 
   358 The listings package allows you to use color and do a lot of things
   442 You might want to customize the code highlighting further using other variables like ``basicstyle``, ``commentstyle``, ``stringstyle``, ``keywordstyle`` etc. For detailed information on all this, you should look at the ``listings`` package documentation. 
   359 with your embedded code, but all that during a lab exercise.
   443 
   360 
   444 You include a block of code into your document by enclosing it within the ``lstlisting`` environment. 
   361 Now, to put a line of code, inline and not as a separate block, we use
   445 ::
   362 the ``\lstinline`` command. We change the name pylab in the footnote
   446 
   363 to use lstinline instead of the texttt. To embed a block of code, we
   447   \begin{lstlisting}
   364 use the lstlisting environment (``\begin{lstlisting}`` and
   448   string="Hello, World! "
   365 ``\end{lstlisting}``). For example, let's add the code to the Appendix
   449   for i in range(10):
   366 of our document.
   450       print string*i
   367 
   451   \end{lstlisting} 
   368 Figures, Tables and Floats
   452 
   369 --------------------------
   453 You can also include source code files directly into your latex document, using the ``lstinputlisting`` command. 
   370 
   454 ::
   371 Let's now add the figure, to the appendix.
   455 
   372 
   456   \lstinputlisting[lastline=20]{lstexample.py}
   373 To include graphics in a LaTeX document, we need to use the graphicx
   457 
   374 package. Add the ``\usepackage{graphicx}`` directive to the preamble
   458 This command includes the first 20 lines of the file ``lstexample.py`` into out LaTeX document. 
   375 of the document.
   459 
   376 
   460 Tables, Figures, Floats, & Referencing
   377 To add the graphic, use the ``includegraphics`` command. The relative
   461 --------------------------------------
   378 path of the image that we wish to include is passed as an argument to
       
   379 includegraphics. It takes an optional argument of scaling the
       
   380 image. We use a scale of 0.4 to scale our image.
       
   381 
       
   382 It takes other optional arguments. 
       
   383 
       
   384   ``width=x``, ``height=x`` 
       
   385     If only the height or width is specified,
       
   386     the image is scaled, maintaining the aspect ratio.
       
   387 
       
   388   ``keepaspectratio``
       
   389     This parameter can either be set to true or false. When set to
       
   390     true, the image is scaled according to both width and height,
       
   391     without changing the aspect ratio, so that it does not exceed both
       
   392     the width and the height dimensions.
       
   393 
       
   394   ``angle=x``
       
   395     This option can be used to rotate the image by ``x`` degrees,
       
   396     counter-clockwise.
       
   397 
       
   398 Figures (and tables) are treated specially because, they cannot be
       
   399 broken across pages. They are "floated" across to the next page, if
       
   400 they donot fit on the current page, filling the current page with
       
   401 text.
       
   402 
       
   403 To make our graphic into a float, we should enlose it within a figure
       
   404 environment. For a table, the table environment should be used. We now
       
   405 move our graphic into a figure environment. The figure environment
       
   406 takes an additional parameter for the location of the
       
   407 float. ``\begin{figure}[hbtp!]``. The specifiers ``htbp`` are
       
   408 permissions to place the float at various locations. ``t`` for top of
       
   409 page, ``b`` for bottom of page, ``p`` for a separate page for floats
       
   410 and ``h`` for here, as in the same place where the command appears in
       
   411 the source. ``!`` mark overrides a few of LaTeX's internal parameters
       
   412 for good position of floats.
       
   413 
       
   414 The figure environment also, allows us to add a caption to the graphic
       
   415 using the ``\caption`` command.
       
   416 
       
   417 To place the graphic in the center aligned in the page, we use the
       
   418 center environment.
       
   419 
       
   420 To label a figure, we just add a label with in the figure
       
   421 environment. Note, that the label to a figure should be added after
       
   422 the caption command. Also, note that tables are auto-numbered.
       
   423 
       
   424 Let us finish the appendix, by adding the content present at the
       
   425 beginning of the appendix. The bibliographic citations will be dealt
       
   426 with later.
   462 
   427 
   463 Tables
   428 Tables
   464 ~~~~~~
   429 ~~~~~~
   465 
   430 
   466 The ``tabular`` environment allows typesetting tables in LaTeX. Like any other environment it starts with ``\begin`` command and ends with ``\end``. 
   431 Now, let us look at the other kind of floats - Tables. We shall
   467 
   432 convert the list of sub-packages in the sub-packages section to a
   468 It takes an optional argument, ``pos`` that specifies the vertical position of the table relative to the baseline of the surroundging text. It takes values of ``t`` for top, ``b`` for bottom, or ``c`` for center. 
   433 table.
   469 
   434 
   470 The ``col fmt`` argument specifies the formatting of the columns of the table. Following are the possible arguments to the tabular environment. 
   435 To begin a table, we use the tabular environment. And to make this a
       
   436 float, it is enclosed in the table environment. The table environment
       
   437 also allows us to add captions to the table and Tables are also auto
       
   438 numbered.
       
   439 
       
   440 The tabular environment takes as arguments the columns and the
       
   441 formatting of each column. The possible arguments to the tabular
       
   442 environment are
   471 
   443 
   472 +---------------+------------------------------------+
   444 +---------------+------------------------------------+
   473 | ``l``         | left justified column content      |
   445 | ``l``         | left justified column content      |
   474 +---------------+------------------------------------+
   446 +---------------+------------------------------------+
   475 | ``r``         | right justified column content     |
   447 | ``r``         | right justified column content     |
   476 +---------------+------------------------------------+
   448 +---------------+------------------------------------+
   477 | ``c``         | centered column content            |
   449 | ``c``         | centered column content            |
   478 +---------------+------------------------------------+
   450 +---------------+------------------------------------+
   479 | ``*{n}{col}`` | produces ``n`` columns with the    |
       
   480 |               | ``col`` type of formatting         |
       
   481 |               | ``*{3}{c}`` is the same as {c c c} |
       
   482 +---------------+------------------------------------+
       
   483 | ``|``         | produces a vertical line.          |
   451 | ``|``         | produces a vertical line.          |
   484 +---------------+------------------------------------+
   452 +---------------+------------------------------------+
   485 
   453 
   486 Each row in a table is separated by ``\\`` command and each column entry of a row is separated by ``&``. 
   454 It also takes an optional parameter that specifies the position of the
   487 
   455 table; ``t`` for top, ``b`` for bottom, or ``c`` for center.
   488 The ``\hline`` command allows you to draw horizontal lines between two rows of the table. But it does not allow you do draw partial lines. ``\cline{a-b}`` draws a horizontal line from column ``a`` to column ``b``.
   456 
   489 ::
   457 Each column of a table is separated by an ``&`` symbol and each row is
   490 
   458 separated by a new line. The ``\hline`` command allows you to draw
   491   \begin{tabular}{|c|c|}
   459 horizontal lines between two rows of the table. But it does not allow
   492     \hline
   460 you do draw partial lines. ``\cline{a-b}`` draws a horizontal line
   493     \verb+l+ & left justified column content\\ 
   461 from column ``a`` to column ``b``.
   494     \hline
   462 
   495     \verb+r+ & right justified column content\\ 
   463 We also add a label to the table and refer to it in the first line of
   496     \hline
   464 the section.
   497     \verb+c+ & centered column content\\ 
   465 
   498     \hline
   466 You could also add a listoftables or listoffigures to the document,
   499     \verb+*{n}{col}+ & produces \verb+n+ columns with the\\
   467 similar to the way we added table of contents.
   500                    & \verb+col+ type of formatting\\
       
   501     \cline{2-2}
       
   502                    &\verb+*{3}{c}+ is the same as \verb+{c c c}+ \\
       
   503     \hline
       
   504     \verb+|+ & produces a vertical line\\ 
       
   505     \hline
       
   506   \end{tabular}
       
   507 
       
   508 
       
   509 Figures
       
   510 ~~~~~~~
       
   511 
       
   512 To include images in LaTeX, we require to use an additional package known as ``graphicx``.  To load a package, we use the ``\usepackage`` directive in the preamble of the document.
       
   513 ::
       
   514 
       
   515   \usepackage{graphicx}
       
   516 
       
   517 When compiling with ``pdflatex`` command,  **jpg**, **png**, **gif** and **pdf** images can be inserted. 
       
   518 
       
   519 ::
       
   520 
       
   521   \includegraphics[optional arguments]{imagename}
       
   522 
       
   523 A few ``optional arguments``:
       
   524 
       
   525   ``width=x``, ``height=x``
       
   526     If only the height or width is specified, the image is scaled, maintaining the aspect ratio.
       
   527 
       
   528   ``keepaspectratio``
       
   529     This parameter can either be set to true or false. When set to true, the image is scaled according to both width and height, without changing the aspect ratio, so that it does not exceed both the width and the height dimensions. 
       
   530 
       
   531   ``scale=x``
       
   532     Scale the image by a factor of ``x``. For example, ``scale=2``, will double the image size. 
       
   533 
       
   534   ``angle=x``
       
   535     This option can be used to rotate the image by ``x`` degrees, counter-clockwise. 
       
   536 
       
   537 ::
       
   538 
       
   539   \includegraphics[scale=0.8, angle=30]{lion_orig.png}
       
   540 
       
   541 
       
   542 Floats
       
   543 ~~~~~~
       
   544 
       
   545 Tables and Figures need to be treated in a special manner, since they cannot be split over pages, and they are referred to as floats in LaTeX. 
       
   546 
       
   547 When there is not enough space on a page, to fit in a table or figure, it is floated over to the next page filling up the current page with text. LaTeX has float environments called ``table`` and ``figure`` for tables and figures, respectively.
       
   548 
       
   549 Anything enclosed within the table or figure environments will be treated as floats.
       
   550 ::
       
   551 
       
   552   \begin{figure}[pos] or 
       
   553   \begin{table}[pos]
       
   554 
       
   555 The ``pos`` parameter specifies the placement of the float. The possible values it can take are as follows. 
       
   556 
       
   557 +-----------+-------------------------------------------------------------------+
       
   558 | Specifier | Permission                                                        |
       
   559 +===========+===================================================================+
       
   560 |   h       |  at approximately the same place where it occurs in the source    |
       
   561 +-----------+-------------------------------------------------------------------+
       
   562 |   t       |  at the top of the page.                                          |
       
   563 +-----------+-------------------------------------------------------------------+
       
   564 |   b       |  at the bottom of the page.                                       |
       
   565 +-----------+-------------------------------------------------------------------+
       
   566 |   p       |  on a special page for floats only.                               |
       
   567 +-----------+-------------------------------------------------------------------+
       
   568 |   !       |  Override LaTeX's internal parameters for good positions          |
       
   569 +-----------+-------------------------------------------------------------------+
       
   570 |   H       |  nearly equivalent to h!                                          |
       
   571 +-----------+-------------------------------------------------------------------+
       
   572 
       
   573 Examples::
       
   574 
       
   575   \begin{figure}[h]
       
   576   \centering
       
   577   \includegraphics[scale=0.8, angle=30]{lion_orig.png}
       
   578   \end{figure}
       
   579 
       
   580 
       
   581 Captions
       
   582 ++++++++
       
   583 
       
   584 The ``\caption{text}`` command allows you to add captions to floats. Similar to section numbering, LaTeX automatically numbers floats too. The caption appears below or on top of the image (or table), depending on whether you place it after or before the ``importgraphics`` (or ``tabular``) command. 
       
   585 
       
   586 ::
       
   587 
       
   588   \begin{figure}[h]
       
   589   \centering
       
   590   \includegraphics[scale=0.8]{lion_orig.png}
       
   591   \caption{CTAN lion drawing by Duane Bibby; thanks to www.ctan.org}
       
   592   \end{figure}
       
   593 
       
   594 The caption command also, like the section command, has the short caption optional parameter. The short caption will appear in the list of tables or figures. 
       
   595 
       
   596 List of Figures, Tables
       
   597 +++++++++++++++++++++++
       
   598 
       
   599 LaTeX can automatically generate a List of Tables or Figures, with the table or figure numbers, the captions and page numbers on which they appear. They can be added to the document using the ``\listoftables`` or ``\listoffigures`` commands. 
       
   600 
       
   601 Note: Just like table of contents, these lists also require an extra compilation. 
       
   602 
       
   603 Cross References
       
   604 ~~~~~~~~~~~~~~~~
       
   605 
       
   606 LaTeX has a very efficient mechanism of inserting cross-references in documents. 
       
   607 
       
   608 The command ``\label{name}`` is used to label figures, tables or blocks of text, like chapters, sections etc. ``\ref{name}`` refers to the object marked by the ``name`` by it's numbering (figure, table, section etc.) ``\pageref{name}`` gives the page number of the object which has been labeled with ``name``. 
       
   609 
       
   610 Note: Cross referencing also requires an extra compilation, like table of contents. 
       
   611 
   468 
   612 Typesetting Math
   469 Typesetting Math
   613 ----------------
   470 ----------------
   614 
   471 
   615 In general, it is advised to use the AMS-LaTeX bundle to typeset mathematics in LaTeX. AMS-LaTeX is a collection of packages and classes for mathematical typesetting. 
   472 Now we shall move to typesetting the Math in the sample document given
   616 
   473 to us. We shall start with the Matrices subsection.
   617 We load ``amsmath`` by issuing the ``\usepackage{amsmath}`` in the preamble. Through out this section, it is assumed that the ``amsmath`` package has been loaded. 
   474 
   618 
   475 In general, it is advised to use the AMS-LaTeX bundle to typeset
   619 
   476 mathematics in LaTeX. AMS-LaTeX is a collection of packages and
   620 Styles or Modes
   477 classes for mathematical typesetting.
   621 ~~~~~~~~~~~~~~~
   478 
   622 
   479 We load ``amsmath`` by issuing the ``\usepackage{amsmath}`` in the
   623 LaTeX has two styles of inserting mathematical equations. They can either be inserted in-line within a paragraph (*text style*), or the paragraph can be broken to typeset them separately (*display style*). 
   480 preamble. Through out this section, it is assumed that the ``amsmath``
   624 
   481 package has been loaded.
   625 Inline formulas are typeset by placing them in two ``$`` symbols or in between ``\(`` and ``\)``. 
   482 
   626 
   483 Let's now typeset the matrix A.
   627 Displayed equations or equations that are set apart from the paragraph text are typeset by using ``\[`` and ``\]`` or ``\begin{equation*}`` and ``\end{equation*}`` for unnumbered equations or ``\begin{equation}`` and ``\end{equation}`` for numbered equations. 
   484 
   628 
   485 To typeset math, we just have to enclose it within ``\(`` and ``\)``
   629 LaTeX provides several environments for handling equation groups and multi-line equations. ``multiline``, ``gather`` and ``align`` are a few. We shall look at ``align`` environment here. You could try out the others, in the lab. 
   486 or a pair of ``$`` signs.
   630 
   487 
   631 ``align`` numbers each of the lines in the environment, and ``align*`` as expected, does not number any of them.  The ``&`` is used to align the equations vertically and the ``\\`` command is used to break the lines. Line numbering can be skipped for a particular line in the ``align`` environment by placing a ``\nonumber`` before the line break.
   488 To typeset the matrix A, we use the ``bmatrix`` environment. It works
   632 
   489 similar to a tabular environment - ``&`` is used to demarcate columns
   633 ::
   490 and ``\\`` is used to add a new row. ``bmatrix`` environment gives the
   634 
   491 ``[`` ``]`` as delimiters. There are 5 other matrix environments
   635   \begin{align}
   492 giving matrices with other delimiters - ``matrix`` (none), ``pmatrix``
   636   a^2 + b^2 &= c^2 \\
   493 ``(``, ``Bmatrix`` ``{``, ``vmatrix`` ``|`` and ``Vmatrix`` ``||``.
   637   a + b &> c \nonumber\\
   494 
   638   b + c &> a \nonumber\\
   495 To write the name of the matrix A, a bold-faced A is used. This is
   639   c + a &> b \\
   496 obtained by using the ``\mathbf`` command.
   640   \end{align}
   497 
   641 
   498 This subsection doesn't have much more math. The next section on
   642 Basic Elements
   499 inverse doesn't have anything new except for writing inverse of A.
   643 ~~~~~~~~~~~~~~
   500 
   644 
   501 To typeset superscripts in LaTeX, the ``^`` character is used. The
   645 Greek Letters can are entered as ``\alpha, \beta, \gamma, \delta, ...`` for lowercase letters and ``\Alpha, \Beta, \Gamma, ...`` for uppercase ones. 
   502 carat operator just acts on the next character. To have multiple
   646 
   503 characters as superscript they must be enclosed in ``{ }``. Similarly
   647 Exponents and subscripts can be typeset using the carat ``^`` and the underscore ``_`` respectively. Most of the math mode commands act only on the next character. If you want a command to affect several characters, they need to be enclosed in curly braces. 
   504 for typesetting text as subscripts the ``_`` character is used.
   648 
   505 
   649 The ``\sqrt`` command is used to typeset the square root symbol. LaTeX of the root sign is determined automatically. The nth root is generated with ``\sqrt[n]``. 
   506 To typeset the summation symbol, use the command ``\sum.`` The upper
   650 
   507 and lower limits are specified using the ``^`` and ``_``
   651 To explicitly show a multiplication a dot may be shown. ``\cdot`` could be used, which typesets the dot to the center. ``\cdots`` is three centered dots while ``\ldots`` sets the dots on the baseline. Besides that ``\vdots`` for vertical and ``\ddots`` can be used for diagonal dots.
   508 characters. Similarly, the integral symbol is obtained using the
   652 
   509 ``\int`` command.
   653 A fraction can be typeset with the command ``\frac{..}{..}``
   510 
   654 
   511 Next, let us type in the equation present in the section on
   655 The integral operator is generated with ``\int``, the sum operator with ``\sum``, and the product operator with ``\prod``. The upper and lower limits are specified with ``^`` and ``_`` like subscripts and superscripts.
   512 Determinants. Note that it is different from all the math we've typed
   656 
   513 until now, since it is not inline and is "displayed", in the LaTeX
   657 LaTeX provides all kinds of braces as delimiters. The round and square brackets can be produces using the keys on the keyboard and appending a backslash. Other delimiters can be produced using special commands of LaTeX. Placing ``\left`` in front of an opening delimiter and ``\right`` in front of a closing delimiter, instructs LaTeX to automatically take care of the sizes of the delimiters. 
   514 lingo. LaTeX has a number of environments for displaying equations,
   658 
   515 with minor subtle differences. In general use ``\[`` ``\]`` to typeset
   659 Arrays and Matrices
   516 displayed equations without numbering them. ``\begin{equation*}`` is
   660 ~~~~~~~~~~~~~~~~~~~
   517 equivalent to it.  To obtain numbered equations use
   661 
   518 ``\begin{equation}``.
   662 To typeset arrays, use the ``array`` environment. It works similar to the ``tabular`` environment. The ``\\`` command is used to break the lines. 
   519 
   663 ::
   520 Next we wish to typeset a group of equations. The equation environment
   664 
   521 does not accept ``\\`` to get a new line. For multiple equations
   665   \begin{equation*}
   522 amsmath has a handful of environments with subtle differences. We
   666   \mathbf{X} = \left(
   523 shall use the ``eqnarray`` environment. ``eqnarray*`` environment
   667    \begin{array}{ccc}
   524 gives unnumbered equations, as expected. The ``eqnarray`` environment
   668    a_1 & a_2 & \ldots \\
   525 works similar to a table environment. The parts of the equation that
   669    b_1 & b_2 & \ldots \\
   526 need to be aligned are indicated using an ``&`` symbol. The
   670    \vdots & \vdots & \ddots
   527 ``newline`` command is used to enter a every new equation after the
   671    \end{array} \right)
   528 first one. We now typeset the equations in the section on linear
   672   \end{equation*}
   529 equations using the ``eqnarray`` environment. (The equations in the
   673 
   530 determinants section use ``eqnarray*``)
   674 The ``array`` environment can also be used to typeset piecewise functions by using a “.” as an invisible ``\right`` delimiter
   531 
   675 ::
   532 We next typeset the math in the section on polynomials. To typeset
   676 
   533 fractions use the ``\frac`` command. To typeset surds, we use the
   677   \begin{equation*}
   534 ``\sqrt`` command with the optional paramter of ``[n]``.
   678   f(x) = \left\{
   535 
   679    \begin{array}{rl}
   536 Inserting Greek letters into LaTeX is simple. ``\alpha``, ``\beta``,
   680      0 & \text{if } x \le 0\\
   537 ``\gamma``, ... on for small letters and ``\Alpha``, ``\Beta``,
   681      1 & \text{if } x > 0
   538 ``\Gamma``, ... for capital.
   682    \end{array} \right.
   539 
   683    \end{equation*}
   540 Also, math environments do not give extra spaces using the space or
   684 
   541 tab characters. The following commands are available to specify the
   685 Six different types of matrix environments are available in the ``amsmath`` package for typesetting matrices.  They essentially have different delimiters: ``matrix`` (none), ``pmatrix`` (, ``bmatrix`` [, ``Bmatrix`` {, ``vmatrix`` | and ``Vmatrix`` ‖. In these matrix environments, the number of columns need not be specified, unlike the ``array`` environment.
   542 spacing required.
   686 ::
   543 
   687 
   544 +---------+--------------------+---------+
   688   \begin{equation*}
   545 | Abbrev. | Spelled out        | Example |
   689     \begin{matrix}
   546 +---------+--------------------+---------+
   690     1 & 2 \\
   547 | ``\,``  | ``\thinspace``     |         |
   691     3 & 4
   548 +---------+--------------------+---------+
   692     \end{matrix} \qquad
   549 | ``\:``  | ``\medspace``      |         |
   693  
   550 +---------+--------------------+---------+
   694     \begin{bmatrix}
   551 | ``\;``  | ``\thickspace``    |         |
   695     1 & 2 & 3 \\
   552 +---------+--------------------+---------+
   696     4 & 5 & 6 \\
   553 |         | ``\quad``          |         |
   697     7 & 8 & 9
   554 +---------+--------------------+---------+
   698     \end{bmatrix}
   555 |         | ``\qquad``         |         |
   699   \end{equation*}
   556 +---------+--------------------+---------+
   700 
   557 | ``\!``  | ``\negthinspace``  |         |
   701 Spacing
   558 +---------+--------------------+---------+
   702 ~~~~~~~
   559 |         | ``\negmedspace``   |         |
   703 +---------+----------------+---------+
   560 +---------+--------------------+---------+
   704 | Abbrev. | Spelled out    | Example |
   561 |         | ``\negthickspace`` |         |
   705 +---------+----------------+---------+
   562 +---------+--------------------+---------+
   706 |         | no space       |         |
       
   707 +---------+----------------+---------+
       
   708 | \,      | \thinspace     |         |
       
   709 +---------+----------------+---------+
       
   710 | \:      | \medspace      |         |
       
   711 +---------+----------------+---------+
       
   712 | \;      | \thickspace    |         |
       
   713 +---------+----------------+---------+
       
   714 |         | \quad          |         |
       
   715 +---------+----------------+---------+
       
   716 |         | \qquad         |         |
       
   717 +---------+----------------+---------+
       
   718 | \!      | \negthinspace  |         |
       
   719 +---------+----------------+---------+
       
   720 |         | \negmedspace   |         |
       
   721 +---------+----------------+---------+
       
   722 |         | \negthickspace |         |
       
   723 +---------+----------------+---------+
       
   724 
       
   725 
       
   726 
       
   727 Referencing
       
   728 ~~~~~~~~~~~
       
   729 Equations can also be cross referenced using the ``\label`` and ``\eqref`` commands. 
       
   730 
       
   731 
   563 
   732 Bibliography
   564 Bibliography
   733 ------------
   565 ------------
   734 
   566 
   735 Bibliography or references can be added to LaTeX documents in two ways - using the ``thebibliography`` environment, or using BibTeX. Let's first look at using the ``\thebibliography`` environment and then move on to BibTeX.
   567 Let's now look at how to write bibliography and cite references.
   736 
   568 
   737 ``thebibliography`` environment
   569 Writing bibliographies in LaTeX using the ``thebibliography``
   738 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   570 environment is pretty easy. You simply have to list down all the
   739 
   571 bibliography items within the bibliography environment.
   740 Writing bibliographies in LaTeX using the ``thebibliography`` environment is pretty easy. You simply have to list down all the bibliography items within the bibliography environment. 
   572 
   741 
   573 Each entry of the bibliography begins with the command
   742 Each entry of the bibliography begins with the command ``\bibitem[label]{name}``. The name is used to cite the bibliography item within the document using  ``\cite{name}``. The label option replaces the numbers from the auto enumeration with the labels given. 
   574 ``\bibitem[label]{name}``. The name is used to cite the bibliography
   743 ::
   575 item within the document using ``\cite{name}``. The label option
   744 
   576 replaces the numbers from the auto enumeration with the labels given.
   745   He used this lion in the illustrations for D Knuth's original TeXbook\cite{DKnuth}, for L Lamport's LaTeX book\cite{LLamport}
   577 
   746 
   578 The ``9`` passed as an argument to ``thebibliography`` command
   747   \begin{thebibliography}{99}
   579 indicates the maximum width of the label that the references will
   748     \bibitem{DKnuth} Donald E. Knuth (1984). \emph{The TeXbook} (Computers and Typesetting, Volume A). Reading, Massachusetts: Addison-Wesley. ISBN 0-201-13448-9.
   580 have. In our sample document, we have less than 10 items in the
   749   
   581 Bibliography and therefore we use 9.
   750     \bibitem{LLamport} Lamport, Leslie (1994). \emph{LaTeX: A document preparation system: User's guide and reference}.
   582 
   751      illustrations by Duane Bibby (2nd ed.). Reading, Mass: Addison-Wesley Professional. 
   583 Presentations with Beamer
   752   \end{thebibliography}
   584 -------------------------
   753 
   585 
   754 The ``99`` in the example above indicates the maximum width of the label that the references may get. We here assume that the number of Bibliography items will be less than 100. If your document has less than 10 references, you may want to replace ``99`` with ``9``. 
   586 Using beamer for you presentations is a good idea, since you can use
   755 
   587 the LaTeX that you have used for the report/document for the
   756 BibTeX
   588 presentation as well.
   757 ~~~~~~
   589 
   758 
   590 To write a ``beamer`` presentation, it is recommended that we use one
   759 The previous section explained the process of listing references at the end of a document and embedding cross references. In this section let us explore the BibTeX environment for keeping track of references.
   591 of the templates that beamer provides. We shall use the
   760 
   592 ``speaker_introduction`` template to get started with beamer.
   761 Using BibTeX is a very convenient method to use, when writing multiple documents in a single area or field. BibTeX allows you to create a database of all your references and use them as and when required. 
   593 
   762 
   594 As you can see, the document begins with the ``documentclass`` being
   763 The BibTeX database is stored in a ``.bib`` file. The structure of the file is quite simple and an example is shown below. 
   595 set to beamer.
   764 ::
   596 
   765 
   597 ``\usetheme`` command sets the theme to be used in the presentation.
   766   @book{Lamport94,
   598 
   767   author    = "Leslie Lamport",
   599 ``\usecolortheme`` command sets the color theme of the presentation.
   768   title     = "A Document Preparation System: User's Guide and Reference",
   600 
   769   publisher = "Addison-Wesley Professional",
   601 Notice that each slide is enclosed within ``\begin{frame}`` and
   770   year      = "1994",
   602 ``\end{frame}`` commands. The ``\begin{frame}`` command can be passed
   771   edition    = "second",
   603 the Title and Subtitle of the slide as parameters.
   772   note      = "illustrations by Duane Bibby"
   604 
   773   }
   605 The title page of the presentation can be set like any other LaTeX
   774 
   606 document.
   775 Each bibliography entry starts with a declaration of the type of the reference being mentioned. The reference is in the above example is of the book type. BibTeX has a wide range of reference types, for example, ``article, book, conference, manual, proceedings, unpublished``.
   607 
   776 
   608 To do overlays, use the ``\pause`` command. It does sequential
   777 The type of reference is followed by a left curly brace, and immediately followed by the citation key. The citation key, ``Lamport94`` in the example above is used to cite this reference using the command ``\cite{Lamport94}``. 
   609 overlays. Non sequential overlays can also be done. (Lab exercise.)
   778 
   610 
   779 This is followed by the relevant fields and their values, listed one by one. Each entry must be followed by a comma to delimit one field from the other. 
   611 If you have fragile environments like ``verbatim`` or ``lstlisting``,
   780 
   612 you need to give the frame an optional parameter ``[fragile]``.
   781 To get your LaTeX document to use the bibliography database, you just add the following lines to your LaTeX document. 
   613 
   782 ::
   614 To achieve more with beamer, it is highly recommended that you look at
   783 
   615 the ``beameruserguide``.
   784   \bibliographystyle{plain}
   616 
   785   \bibliography{LaTeX}
       
   786 
       
   787 Bibliography styles are files that tell BibTeX how to format the information stored in the ``.bib`` database file. The style file for this example is ``plain.bst``. Note that you do not need to add the ``.bst`` extension to the filename.  If you wish to achieve a particular style of listing the bibliography items and citing them, you should use an appropriate style file. 
       
   788 
       
   789 The ``bibliography`` command specifies the file that should be used as the database for references. The file used in this example is ``LaTeX.bib``
       
   790 
       
   791 Compiling
       
   792 +++++++++
       
   793 
       
   794 Adding BibTeX based references, slightly complicates the process of compiling the document to obtain the desired output. The exact workings of LaTeX and BibTeX will not be explained here. The procedure for obtaining the output (without any explanations) is as follows:
       
   795 
       
   796 1. Compile the ``.tex`` file using ``pdflatex`` - ``$pdflatex LaTeX(.tex)``
       
   797 2. Compile the ``.bib`` file using ``bibtex`` -  ``$bibtex LaTeX(.bib)``
       
   798 3. Compile the ``.tex`` file again. 
       
   799 4. Compile the ``.tex`` file for one last time!
       
   800 
       
   801 Beamer
       
   802 ~~~~~~
       
   803 
       
   804 LaTeX has quite a few options to produce presentation slides. We shall look at the ``beamer`` class, which is well developed and easy to use. We shall only briefly look at some of the features of beamer. For the best documentation, look at the beamer user guide.
       
   805 
       
   806 To write a ``beamer`` presentation, it is recommended that you use one of the templates that beamer provides. We shall use the ``speaker_introduction`` template to get started with beamer. 
       
   807 
       
   808 As you can see, the document begins with the ``documentclass`` being set to beamer. 
       
   809 
       
   810 The ``\setbeamertemplate`` command sets the template for various parameters. The ``background canvas``, ``headline`` and ``footline`` are being set using the command.
       
   811 
       
   812 ``\usetheme`` command sets the theme to be used in the presentation. 
       
   813 
       
   814 Notice that each slide is enclosed within ``\begin{frame}`` and ``\end{frame}`` commands. The ``\begin{frame}`` command can be passed the Title and Subtitle of the slide as parameters. 
       
   815 
       
   816 To achieve more with beamer, it is highly recommended that you look at the ``beameruserguide``.
       
   817 
       
   818 
       
   819 Recommended Reading
       
   820 -------------------
       
   821 
       
   822 1. *LaTeX Wikibook*
       
   823 
       
   824 2. *The Not So Short Introduction to LaTeX2e* by Tobias Oetikar et al.. 
       
   825 
       
   826