diff options
author | Puneeth Chaganti | 2010-06-02 21:31:35 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-06-02 21:31:35 +0530 |
commit | a7f161325c26f51db24ab166eca7960418467aae (patch) | |
tree | dbe834167fa4d5280c10c765f96fed433334ba68 /latex | |
parent | 584df9693f6023e41d820345164dc653c6149a05 (diff) | |
download | sees-a7f161325c26f51db24ab166eca7960418467aae.tar.gz sees-a7f161325c26f51db24ab166eca7960418467aae.tar.bz2 sees-a7f161325c26f51db24ab166eca7960418467aae.zip |
Revised latex handout for new sees course; will drop this and make it more need based.
Diffstat (limited to 'latex')
-rw-r--r-- | latex/handout.rst | 646 |
1 files changed, 330 insertions, 316 deletions
diff --git a/latex/handout.rst b/latex/handout.rst index 7d68463..0847dac 100644 --- a/latex/handout.rst +++ b/latex/handout.rst @@ -3,60 +3,51 @@ LaTeX Introduction ------------ -LaTeX is a typesetting program used to produce excellently typeset documents. It is extensively used for producing high quality scientific and mathematical documents. It may also be used for producing other kinds of documents, ranging from simple one page articles or letters - - -TeX & LaTeX -~~~~~~~~~~~ +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. TeX -+++ +~~~ -TeX is a typesetting system designed by Donald Knuth, the renowned Computer Scientist and Emeritus professor at Stanford University. Typesetting is placing text onto a page with all the style formatting defined, so that content looks as intended. +TeX is a typesetting system designed and developed by Donald E. Knuth, the renowned Computer Scientist and Emeritus professor at Stanford University. It was designed with two goals in mind- 1. To allow anybody to produce high-quality books using a reasonable amount of effort. 2. To provide a system that would give the exact same results on all computers, now and in the future -TeX is well known for it's stability and portability. - -TeX is pronounced as "tech". +TeX is well known for it's stability and portability. TeX is known to be virtually bug free. The current version of TeX is 3.1415926 and is converging to π. LaTeX -+++++ +~~~~~ -LaTeX was originally written by Leslie Lamport in the early 1980s. It is an extension of TeX, consisting of TeX macros and a program to parse the LaTeX files. It is easier to use than TeX itself, at the same time producing the same quality of output. +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. LaTeX is pronounced either as "Lah-tech" or "Lay-tech" -WYSIWG vs. WYSIWM -~~~~~~~~~~~~~~~~~ - -WYSIWG is an acronym for "What You See Is What You Get". Word processors, are typically WYSIWG tools. LaTeX, TeX or other TeX based tools are not. They are typesetting or text formatting or document description programs. They can be called WYSIWM or "What You See Is What you Mean" systems, since you give a description of how things look, and LaTeX typesets the document for you. +Why should you use it? +~~~~~~~~~~~~~~~~~~~~~~ -Here are a few reasons, why you should use LaTeX - +A few reasons for using LaTeX - - * LaTeX produces documents with excellent visual quality, especially mathematical and scientific documents. - * It does the typesetting to you. Typically, when one works with a word-processor, the user is doing the text formatting or typesetting along with typing out the content. LaTeX allows the user to concentrate on the content leaving aside the typesetting to LaTeX. + * It produces documents with excellent visual quality. + * It does the typesetting for you, leaving you - the author - to focus on writing the content. + * It makes writing math just as easy as writing simple text. + * It's renowned for it's stability and a virtually bug free code base. * It is light on your resources as compared to most of the word processors available today. - * It is well known for it's stability and for it's virtually bug free code base. - * It encourages users to structure documents by meaning rather than appearance, thereby helping produce well structured documents. - * It uses plain text files as input, which have a lot of well known advantages over binary files. To state a few, they can be opened with any editor on any operating system, they are smaller in size compared to the binaries, can be version controlled and can be processed using widely used text processing utilities. - * The output can be generated in more than one formats. + * It uses plain text files as input and can give output in a variety of formats including PDFs and html making it platform independent. * It is free software (free as in freedom) and gratis too. - * It is widely used. + * It is widely used and has a large user community. -Hello World -~~~~~~~~~~~ +First Document +-------------- -OK, let's get started with our first LaTeX document. Open up your favorite editor and type in the following code. +Let's begin by writing a simple LaTeX, Hello World, document. The following code is typed out into a text editor. :: - %hello.tex - First LaTeX document + %hello.tex - The Hello World of LaTeX \documentclass{article} \begin{document} @@ -66,7 +57,7 @@ OK, let's get started with our first LaTeX document. Open up your favorite edito Save the file as ``hello.tex`` and open up a terminal to compile your ``tex`` file to get the output in a ``pdf`` format. Compiling & Output -++++++++++++++++++ +~~~~~~~~~~~~~~~~~~ :: @@ -77,25 +68,23 @@ Compiling & Output Open the ``hello.pdf`` to see the output as shown. -.. image:: examples/hello.jpg - Note: The command ``latex`` is often used to get the ``dvi`` output. But, throughout this course, we shall use pdflatex to compile our documents. -A peek at the source -++++++++++++++++++++ +What does it mean? - Understanding the source +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``%hello.tex - First LaTeX document`` - This line is a comment. LaTeX ignores this line and it is meant only for the human readers. LaTeX ignores anything after a ``%`` symbol to the end of the line. + 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. ``\documentclass{article}`` - 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. + 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. ``\begin{document}`` - This line informs LaTeX that this is the beginning of the content of the document. + 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. ``Hello, World!`` @@ -103,158 +92,153 @@ A peek at the source ``\end{document}`` - This line tells LaTeX that the document is complete and LaTeX will simply ignore anything written after this line. - -Where do we want to go -~~~~~~~~~~~~~~~~~~~~~~ - -During the course of this session we will learn how to do various things in LaTeX and try to produce the sample document provided. + 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. Some Basics ~~~~~~~~~~~ -Before we get started with creating the document, let's try to understand a few things that would be useful during the course of this session. - -Spaces -++++++ 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. -Line & Page Breaks -++++++++++++++++++ - -LaTeX usually does the job of breaking up your content into lines and pages, and does it well. But under some circumstances, you might want to instruct LaTeX to break line or start a new page at a particular point. +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. -``\\`` or ``\newline`` command is used to create a new line at the point where the command is issued. -Appending ``*`` to ``\\``, instructs LaTeX to create a new line, without creating a new page at that point. +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. -Paragraphs -++++++++++ - -As already mentioned, LaTeX considers an empty line between two lines of text as a new paragraph. ``\par`` command may also be used to start a newline. It is equivalent to the blank line. +:: -By default LaTeX indents new paragraphs. If you do not wish to have the paragraph indented, you can use the ``\nointend`` command at the beginning of the paragraph. + %hello.tex - First LaTeX document + \documentclass{article} + \begin{document} + Hello, World! + This will not start a new line. -Special Characters -++++++++++++++++++ + But, this will start a new paragraph. + Again no new line. \% what follows isn't a comment. + \end{document} + This is text that is ignored. -LaTeX associates special meaning to the characters ``~ # $ % ^ & _ { } \``. +Basic Structure +--------------- -To have these characters in the text of your document, you need to prefix a backslash to them. ``\~ \# \% \$ \^ \& \_ \{ \} \textbackslash`` +``\documentclass`` +~~~~~~~~~~~~~~~~~~ +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. +Some of the available LaTeX classes are, article, proc, report, book, slides, letter. -Commands -++++++++ +The ``documentclass`` command also accepts a few optional parameters. For example:: + \documentclass[12pt,a4paper,oneside,draft]{report} -* All LaTeX commands start with a backslash ``\``. -* Like the commands in Linux, they are case sensitive. -* They usually have a backslash followed by a consisting of letters only. Any character other than letters, like space, numbers or special characters terminate the command. -* The commands for producing special characters in the text, is an exception. They contain a backslash followed by a single special character. -* Commands may have parameters, which are supplied to them by enclosing them in curly braces ``{ }``. -* They may also have a few optional parameters which are added after the name in square brackets ``[ ]``. +``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. +``a4paper`` specifies the size of the paper to be used for the document. -Environments -++++++++++++ +``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``. -Environments are very similar to the commands, except that they effect larger parts of the document. For example, we used the ``document`` environment in our first LaTeX document. +``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. -* They begin with a ``\begin`` and end with a ``\end`` -* In general environments can be nested within each other. +Note: Everything written in between the ``\documentclass`` command and the ``\begin{document}`` command is called the Preamble. -Some Structural Elements ------------------------- -``\documentclass`` -~~~~~~~~~~~~~~~~~~ -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. We presently have it set to the article class. Let us try changing it to the report class. +Top Matter +~~~~~~~~~~ -Note that the top matter of the document appears in a different page for the report class. +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. -Some of the LaTeX classes that you may want to use are, article, proc, report, book, slides, letter. +Let us add top matter to our document, now. +:: -The ``documentclass`` command also accepts a few optional parameters. For example:: - \documentclass[12pt,a4paper,oneside,draft]{report} + \title{LaTeX - A How-to} + \author{The FOSSEE Team} + \date -``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. +The commands ``\title`` and ``\author`` are self explanatory. +The ``\date`` command automatically puts in today's date into the document. Now let us compile and look at the result. -``a4paper`` specifies the size of the paper to be used for the document. +To put a specific date, you can specify it as below -``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``. +:: -``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. + \date{June 1, 2010} -Note: Everything written in between the ``\documentclass`` command and the ``\begin{document}`` command is called the Preamble. +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. +Sectioning Commands +~~~~~~~~~~~~~~~~~~~ -Parts, Chapters and Sections -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Documents are often divided into parts, chapters, sections and subsections. LaTeX provides an intuitive mechanism to use them in your documents. -Often documents are divided into various parts, chapters, sections and subsections. LaTeX provides an intuitive mechanism to include this in your documents. It has various commands like ``part``, ``chapter``, ``section``, ``subsection``, ``subsubsection``, ``paragraph`` and ``subparagraph``. Note that all these commands are not available in all the document classes. The ``chapter`` command is available only in books and reports. Also, the ``letter`` document class does not have any of these commands. ++-------------------+-------+------------------------+ +| command | level | comments | ++-------------------+-------+------------------------+ +| ``part`` | -1 | not in letters | ++-------------------+-------+------------------------+ +| ``chapter`` | 0 | only books and reports | ++-------------------+-------+------------------------+ +| ``section`` | 1 | not in letters | ++-------------------+-------+------------------------+ +| ``subsection`` | 2 | not in letters | ++-------------------+-------+------------------------+ +| ``subsubsection`` | 3 | not in letters | ++-------------------+-------+------------------------+ +| ``paragraph`` | 4 | not in letters | ++-------------------+-------+------------------------+ +| ``subparagraph`` | 5 | not in letters | ++-------------------+-------+------------------------+ -Let us now give our document some structure, using these commands. +LaTeX has seven levels of sectioning commands, as shown above. -Note that you do not need to provide any numbers to the commands. LaTeX automatically takes care of the numbering. -Also, you do not need to enclose the text of a block within ``\begin`` and ``\end`` commands. LaTeX starts a new block each time it finds a sectioning command. +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. :: \section[Short Title]{This is a very long title and the Short Title will appear in the Table of Contents.} +The short title appears in the table of contents, if at all one is generated. Section Numbering +++++++++++++++++ -As already, you don't need to explicitly do any numbering in LaTeX. Parts are numbered using roman numerals; Chapters and sections are numbered using decimal numbers. When the table of contents is inserted into a document, all the numbered headings automatically appear in it. - -By default LaTeX has numbering up 2 levels, i.e, the parts, chapters, sections and subsections are numbered. You can change this by setting the ``secnumdepth`` counter using the ``\setcounter`` command. The following command removes numbering of the subsections. Only parts, chapters and sections are numbered. -:: - - \setcounter{secnumdepth}{1} +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. A sectioning command appended with an asterisk gives an unnumbered heading that is not included in the table of contents. :: \section*{Introduction} -Top Matter -~~~~~~~~~~ +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. +:: -The information about the document such as it's title, the date, the author(s) information etc, is collectively known as the topmatter. Though there is no command called ``topmatter``, the term topmatter is frequently used in LaTeX documentation. + \setcounter{secnumdepth}{1} -Let us input the top matter for our document now. -:: - \title{LaTeX - A How-to} - \author{The FOSSEE Team} - \date +Appendices +~~~~~~~~~~ -The commands ``\title`` and ``\author`` are self explanatory. -The ``\date`` command automatically puts in today's date into the document. Now let us compile and look at the result. +LaTeX allows for separate numbering for appendices. ``\appendix`` command indicates that the sections following it, are to be included in the appendix. +:: -You would observe that the details do not appear in the document after recompilation. This is because, LaTeX has not been instructed what to do with the top matter information that you have given it. Use the ``\maketitle`` command within the document environment to instruct LaTeX to place the top matter information into the document. + \appendix + \chapter{First Appendix} Abstract ~~~~~~~~ -Lets now place and abstract in the document using the ``abstract`` environment of LaTeX. The abstract appears in the document after the topmatter but before the main body of the document. +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. :: \begin{abstract} - The abstract abstract. + The abstract abstract. \end{abstract} +By default LaTeX uses the word "Abstract" as a title for the abstract. This can be changed using the ``\renewcommand``. +:: -Appendices -~~~~~~~~~~ + \renewcommand{\abstractname}{Summary} -LaTeX allows for separate numbering for appendices. ``\appendix`` command indicates that the sections following are to be included in the appendix. -:: - \appendix - \chapter{First Appendix} Table of Contents ~~~~~~~~~~~~~~~~~ -Parts, chapters or sections that have been auto numbered by LaTeX automatically appear in the Table of Contents (ToC). ``\tableofcontents`` command places a the ToC, where the command has been issued. +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. 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. :: @@ -264,31 +248,72 @@ The counter ``tocdepth`` specifies the depth up to which headings appear in the Unnumbered sections can be placed in the table of contents using the ``\addcontentsline`` command as shown below. :: - \section*{Introduction} - \addcontentsline{toc}{section}{Introduction} + \section*{Preface} + \addcontentsline{toc}{section}{Preface} 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. -Elementary Text Typesetting ---------------------------- +Typesetting Text +---------------- -Emphasizing -~~~~~~~~~~~ +Text formatting +~~~~~~~~~~~~~~~ -*Italic* font is generally used to emphasize text. The ``\emph`` command may be used to achieve this effect in LaTeX. -:: +Font Styles and Size +++++++++++++++++++++ + +LaTeX has three font families: + + 1. roman ``\textrm{your text here}`` + 2. serif ``\textsf{your text here}`` + 3. monospace ``\texttt{your text here}`` + +For emphasizing text, *italics* are generally used. The ``\emph`` command is used to emphasize text. +``\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. + +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. + ++-------------------+----------------+-------------+-------------+ +| size | 10pt (default) | 11pt option | 12pt option | ++===================+================+=============+=============+ +| ``\tiny`` | 5pt | 6pt | 6pt | ++-------------------+----------------+-------------+-------------+ +| ``\scriptsize`` | 7pt | 8pt | 8pt | ++-------------------+----------------+-------------+-------------+ +| ``\footnotesize`` | 8pt | 9pt | 10pt | ++-------------------+----------------+-------------+-------------+ +| ``\small`` | 9pt | 10pt | 11pt | ++-------------------+----------------+-------------+-------------+ +| ``\normalsize`` | 10pt | 11pt | 12pt | ++-------------------+----------------+-------------+-------------+ +| ``\large`` | 12pt | 12pt | 14pt | ++-------------------+----------------+-------------+-------------+ +| ``\Large`` | 14pt | 14pt | 17pt | ++-------------------+----------------+-------------+-------------+ +| ``\LARGE`` | 17pt | 17pt | 20pt | ++-------------------+----------------+-------------+-------------+ +| ``\huge`` | 20pt | 20pt | 25pt | ++-------------------+----------------+-------------+-------------+ +| ``\Huge`` | 25pt | 25pt | 25pt | ++-------------------+----------------+-------------+-------------+ - This is the \emph{emphasized text}. -If the ``\emph`` command is nested within another emphasize command, LaTeX emphasized that text using normal fonts. +Superscript and Subscript ++++++++++++++++++++++++++ + +For superscripting text in the text mode, LaTeX provides the ``\textsuperscript`` command. :: - \emph{Did you wonder what happens when we try \emph{emphasizing text} within \emph{emphasized text}}? + This is how you super\textsuperscript{script} text. + +LaTeX does not provide any command for subscripting text in the text mode. The math mode needs to be used to obtain subscripts. -*This is emphasized text, and* this is emphasized text with normal font *, within* emphasized text. +:: + + This is sub_{script} Quotation Marks -~~~~~~~~~~~~~~~ ++++++++++++++++ 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. :: @@ -296,7 +321,7 @@ When typing in LaTeX, the double quotation mark ``"`` character shouldn't be use `` Here is an example of putting `text' in quotes '' Dashes and Hyphens -~~~~~~~~~~~~~~~~~~ +++++++++++++++++++ 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. :: @@ -305,26 +330,8 @@ LaTeX has four dashes of different lengths. Three of them can be produces with d The names for these dashes are: ‘‐’ hyphen, ‘–’ en-dash, ‘—’ em-dash and ‘−’ minus sign. -Footnotes -~~~~~~~~~ - -With the command:: - - \footnote{footnote text} - -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. - -Note: Look at the ``\marginpar`` command to insert margin notes - -Flushleft, Flushright, and Center -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The environments ``flushleft`` and ``flushright`` generate paragraphs that are either left- or right-aligned. - -The ``center`` environment generates centered text. - -Itemize, Enumerate, and Description -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Lists - Itemize, Enumerate, and Description +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LaTeX has three different environments for producing lists. Itemize, Enumerate and Description allow you to produce lists of various types in LaTeX. 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. @@ -350,8 +357,20 @@ Itemize is used to produce unnumbered lists. The bullets of the list can be easi \item[Itemize] The list above this description list is an itemize list. \end{description} -Quote, Quotation, and Verse -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Special Paragraphs +~~~~~~~~~~~~~~~~~~ + +Footnotes ++++++++++ + +With the command:: + + \footnote{footnote text} + +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. + +Quotes +++++++ LaTeX provides a ``quote`` environment that can be used for quoting, highlighting important material, etc. :: @@ -383,12 +402,8 @@ LaTeX provides a ``quote`` environment that can be used for quoting, highlightin LaTeX provides two other similar environments, the quotation and the verse environments. -The quotation environment can be used for longer quotes which have several paragraphs, since it indents the first line of each paragraph. - -The verse environment may be used to quote verses or poems, since the line breaks are important in quoting them. The lines are separated using ``\\\\`` at the end of a line and an empty line after each verse. - Verbatim -~~~~~~~~ +++++++++ 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}``. :: @@ -407,18 +422,52 @@ To insert verbatim text in-line, the ``\verb`` command can be used. The | is just an example of a delimiter character. You can use any character except letters, * or space. -Tables, Figures and Captions ----------------------------- +Including Code +++++++++++++++ + +The ``listings`` package can be used to embed source code into your LaTeX document. We shall briefly explore inserting python code into our document. + +Obviously, you first need to tell LaTeX that you want it to use the ``listings`` package, using the ``\usepackage`` command. +:: + + \usepackage{listings} + +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. +:: + + \lstset{language=Python, + showstringspaces=false, + } + +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. + +You include a block of code into your document by enclosing it within the ``lstlisting`` environment. +:: + + \begin{lstlisting} + string="Hello, World! " + for i in range(10): + print string*i + \end{lstlisting} + +You can also include source code files directly into your latex document, using the ``lstinputlisting`` command. +:: -The ``\tabular`` environment -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + \lstinputlisting[lastline=20]{lstexample.py} -The ``tabular`` environment allows you to typeset tables in LaTeX. ``\begin{tabular}[pos]{col fmt}`` command can be used to specify the parameters of the table and start creating the table. +This command includes the first 20 lines of the file ``lstexample.py`` into out LaTeX document. -The ``pos`` argument specifies the vertical position of the table relative to the baseline of the surrounding text. It can take on the values ``t`` for top, ``b`` for bottom, or ``c`` for center. +Tables, Figures, Floats, & Referencing +--------------------------------------------- + +Tables +~~~~~~ +The ``tabular`` environment allows typesetting tables in LaTeX. Like any other environment it starts with ``\begin`` command and ends with ``\end``. -The ``col fmt`` argument specifies the formatting of the columns of the table. You need to explicitly specify the formatting for each of the columns in the table. The ``col fmt`` argument can take on the following values. +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. + +The ``col fmt`` argument specifies the formatting of the columns of the table. Following are the possible arguments to the tabular environment. +---------------+------------------------------------+ | ``l`` | left justified column content | @@ -434,7 +483,7 @@ The ``col fmt`` argument specifies the formatting of the columns of the table. Y | ``|`` | produces a vertical line. | +---------------+------------------------------------+ -Now we look at how to input the actual entries of the tables. Each horizontal row in a table is separated by ``\\``. Each column entry of a row is separated by ``&``. +Each row in a table is separated by ``\\`` command and each column entry of a row is separated by ``&``. 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,8 +505,9 @@ The ``\hline`` command allows you to draw horizontal lines between two rows of t \hline \end{tabular} -Importing Graphics -~~~~~~~~~~~~~~~~~~ + +Figures +~~~~~~~ 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. :: @@ -493,7 +543,7 @@ Floats 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. -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 images, respectively. +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. Anything enclosed within the table or figure environments will be treated as floats. :: @@ -528,11 +578,12 @@ Examples:: Captions -~~~~~~~~ +++++++++ -The ``\caption{text}`` command allows you to add captions to images or tables. LaTeX automatically numbers your tables and figures and you need not include numbers in the captions that you write. 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. +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. :: + \begin{figure}[h] \centering \includegraphics[scale=0.8]{lion_orig.png} @@ -542,9 +593,9 @@ The ``\caption{text}`` command allows you to add captions to images or tables. L 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. List of Figures, Tables -~~~~~~~~~~~~~~~~~~~~~~~ ++++++++++++++++++++++++ -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. This can be done using the ``\listoftables`` or ``listoffigures`` commands. +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. Note: Just like table of contents, these lists also require an extra compilation. @@ -553,106 +604,39 @@ Cross References LaTeX has a very efficient mechanism of inserting cross-references in documents. -The command ``\label{name}`` is used to label figures, tables or segments of text. ``\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``. +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``. Note: Cross referencing also requires an extra compilation, like table of contents. -Bibliography ------------- - -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. - -``thebibliography`` environment -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -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. - -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. -:: - - He used this lion in the illustrations for D Knuth's original TeXbook\cite{DKnuth}, for L Lamport's LaTeX book\cite{LLamport} - - \begin{thebibliography}{99} - \bibitem{DKnuth} Donald E. Knuth (1984). \emph{The TeXbook} (Computers and Typesetting, Volume A). Reading, Massachusetts: Addison-Wesley. ISBN 0-201-13448-9. - - \bibitem{LLamport} Lamport, Leslie (1994). \emph{LaTeX: A document preparation system: User's guide and reference}. - illustrations by Duane Bibby (2nd ed.). Reading, Mass: Addison-Wesley Professional. - \end{thebibliography} - -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``. - -BibTeX -~~~~~~ - -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. - -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. - -The BibTeX database is stored in a ``.bib`` file. The structure of the file is quite simple and an example is shown below. -:: - - @book{Lamport94, - author = "Leslie Lamport", - title = "A Document Preparation System: User's Guide and Reference", - publisher = "Addison-Wesley Professional", - year = "1994", - edition = "second", - note = "illustrations by Duane Bibby" - } - -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``. - -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}``. - -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. - -To get your LaTeX document to use the bibliography database, you just add the following lines to your LaTeX document. -:: - - \bibliographystyle{plain} - \bibliography{LaTeX} - -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. - -The ``bibliography`` command specifies the file that should be used as the database for references. The file used in this example is ``LaTeX.bib`` - -Compiling -+++++++++ - -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: - -1. Compile the ``.tex`` file using ``pdflatex`` - ``$pdflatex LaTeX(.tex)`` -2. Compile the ``.bib`` file using ``bibtex`` - ``$bibtex LaTeX(.bib)`` -3. Compile the ``.tex`` file again. -4. Compile the ``.tex`` file for one last time! - Typesetting Math ---------------- -It is advisable to use the AMS-LaTeX bundle to typeset mathematics in LaTeX. It is a collection of packages and classes for mathematical typesetting. +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. 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. -Math Mode -~~~~~~~~~ - -There are a few differences between the *math mode* and the *text mode*: +Styles or Modes +~~~~~~~~~~~~~~~ -1. Most spaces and line breaks do not have any significance, as all spaces are either derived logically from the mathematical expressions, or have to be specified with special commands such as ``\``, ``\quad`` or ``\qquad`` +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*). -2. Empty lines are not allowed. +Inline formulas are typeset by placing them in two ``$`` symbols or in between ``\(`` and ``\)``. -3. Each letter is considered to be the name of a variable and will be typeset as such. If you want to typeset normal text within a formula, then you have to enter the text using the \text{...} command +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. -Single Equations -~~~~~~~~~~~~~~~~ +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. -Mathematical equations can be inserted in-line within a paragraph (*text style*), or the paragraph can be broken to typeset it separately (*display style*). +``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. -A mathematical equation within a paragraph is entered between ``$`` and ``$``. Larger equations are set apart from the paragraph, by enclosing them within ``\begin{equation}`` and ``\end{equation}``. If you don't wish to number a particular equation, the starred version of equation can be used. ``\begin{equation*}`` and ``\end{equation*}`` +:: -The equation can also be cross referenced using the ``\label`` and ``\eqref`` commands. + \begin{align} + a^2 + b^2 &= c^2 \\ + a + b &> c \nonumber\\ + b + c &> a \nonumber\\ + c + a &> b \\ + \end{align} Basic Elements ~~~~~~~~~~~~~~ @@ -671,22 +655,6 @@ The integral operator is generated with ``\int``, the sum operator with ``\sum`` 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. -Multiple Equations -~~~~~~~~~~~~~~~~~~ - -Long formulae that run over several lines or equation systems, can be typeset using the ``align`` or ``align*`` environments. ``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. - -:: - - \begin{align} - \alpha^2 + \beta^2 &= \gamma^2 \\ - \sum_{i=1}^ni &= \frac{n(n+1)}{2}\\ - \sqrt{-1} &= \pm1 \nonumber - \end{align} - - Arrays and Matrices ~~~~~~~~~~~~~~~~~~~ @@ -729,76 +697,122 @@ Six different types of matrix environments are available in the ``amsmath`` pack \end{bmatrix} \end{equation*} -Miscellaneous Stuff -------------------- +Spacing +~~~~~~~ ++---------+----------------+---------+ +| Abbrev. | Spelled out | Example | ++---------+----------------+---------+ +| | no space | | ++---------+----------------+---------+ +| \, | \thinspace | | ++---------+----------------+---------+ +| \: | \medspace | | ++---------+----------------+---------+ +| \; | \thickspace | | ++---------+----------------+---------+ +| | \quad | | ++---------+----------------+---------+ +| | \qquad | | ++---------+----------------+---------+ +| \! | \negthinspace | | ++---------+----------------+---------+ +| | \negmedspace | | ++---------+----------------+---------+ +| | \negthickspace | | ++---------+----------------+---------+ + + + +Referencing +~~~~~~~~~~~ +Equations can also be cross referenced using the ``\label`` and ``\eqref`` commands. -Presentations -~~~~~~~~~~~~~ -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. +Bibliography +------------ -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. +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. -As you can see, the document begins with the ``documentclass`` being set to beamer. +``thebibliography`` environment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The ``\setbeamertemplate`` command sets the template for various parameters. The ``background canvas``, ``headline`` and ``footline`` are being set using the command. +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. -``\usetheme`` command sets the theme to be used in the presentation. +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. +:: -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. + He used this lion in the illustrations for D Knuth's original TeXbook\cite{DKnuth}, for L Lamport's LaTeX book\cite{LLamport} -To achieve more with beamer, it is highly recommended that you look at the ``beameruserguide``. + \begin{thebibliography}{99} + \bibitem{DKnuth} Donald E. Knuth (1984). \emph{The TeXbook} (Computers and Typesetting, Volume A). Reading, Massachusetts: Addison-Wesley. ISBN 0-201-13448-9. + + \bibitem{LLamport} Lamport, Leslie (1994). \emph{LaTeX: A document preparation system: User's guide and reference}. + illustrations by Duane Bibby (2nd ed.). Reading, Mass: Addison-Wesley Professional. + \end{thebibliography} -Including Code -~~~~~~~~~~~~~~ +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``. -The ``listings`` package can be used to embed source code into your LaTeX document. We shall briefly explore inserting python code into our document. +BibTeX +~~~~~~ -Obviously, you first need to tell LaTeX that you want it to use the ``listings`` package, using the ``\usepackage`` command. -:: +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. - \usepackage{listings} +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. -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. +The BibTeX database is stored in a ``.bib`` file. The structure of the file is quite simple and an example is shown below. :: - \lstset{language=Python, - showstringspaces=false, - } + @book{Lamport94, + author = "Leslie Lamport", + title = "A Document Preparation System: User's Guide and Reference", + publisher = "Addison-Wesley Professional", + year = "1994", + edition = "second", + note = "illustrations by Duane Bibby" + } -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. +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``. -You include a block of code into your document by enclosing it within the ``lstlisting`` environment. -:: +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}``. - \begin{lstlisting} - string="Hello, World! " - for i in range(10): - print string*i - \end{lstlisting} +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. -You can also include source code files directly into your latex document, using the ``lstinputlisting`` command. +To get your LaTeX document to use the bibliography database, you just add the following lines to your LaTeX document. :: - \lstinputlisting[lastline=20]{lstexample.py} + \bibliographystyle{plain} + \bibliography{LaTeX} -This command includes the first 20 lines of the file ``lstexample.py`` into out LaTeX document. +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. -Including files -~~~~~~~~~~~~~~~ -When working on a large document, it is convenient sometimes, to split the large file into smaller input files and club them together at the time of compiling. +The ``bibliography`` command specifies the file that should be used as the database for references. The file used in this example is ``LaTeX.bib`` -The ``\input`` or ``\include`` commands may be used to embed one LaTeX file into another. The ``\input`` command is equivalent to a copy and paste of the document, just before the compilation. The ``\include`` command is exactly similar, except for the fact that it creates a new page every time it is issued. +Compiling ++++++++++ -``\input{file}`` or ``\include{file}`` commands will include the file ``file1.tex`` with in the file where the command has been issued. Note that you do not need to specify the ``.tex`` extension of the file. +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: -The ``\includeonly`` is useful for debugging or testing the LaTeX document that you are creating, since it restricts the ``\include`` command. Only the files which are given as arguments to the ``\includeonly`` command will be included in the document (wherever a ``\include`` command for those files, has been issued). +1. Compile the ``.tex`` file using ``pdflatex`` - ``$pdflatex LaTeX(.tex)`` +2. Compile the ``.bib`` file using ``bibtex`` - ``$bibtex LaTeX(.bib)`` +3. Compile the ``.tex`` file again. +4. Compile the ``.tex`` file for one last time! -A note on filenames -+++++++++++++++++++ +Beamer +~~~~~~ -Never use filenames or directories that contain spaces. Make filenames as long or short as you would like, but strictly avoid spaces. Stick to upper or lower case letters (without accents), the digits, the hyphen and the full stop or period. +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. +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. + +As you can see, the document begins with the ``documentclass`` being set to beamer. + +The ``\setbeamertemplate`` command sets the template for various parameters. The ``background canvas``, ``headline`` and ``footline`` are being set using the command. + +``\usetheme`` command sets the theme to be used in the presentation. + +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. + +To achieve more with beamer, it is highly recommended that you look at the ``beameruserguide``. Recommended Reading |