LATEX TYPESETTING SYSTEM. CAAM 519, CHAPTER 3 1. Latex installation and text editors 1.1. Installation. Install Latex in your virtual machine with the following command. sudo apt get install texlive Note that if you are using a CAAM department s computer, this software is already installed. 1.2. Text editor and pdf generation. It is advised to use one of the following text editors when writing a Latex document: Kile. Texmaker. They both allow you to directly compile your document without using a terminal. You can download them with the command sudo apt-get install. It is possible to compile a latex document (.tex), which generates a pdf, with the following terminal command: If your document contains a bibliography, run the following commands: bibtex example It is important to run pdflatex at least two times after compiling the bibliography with bibtex (if not some references may not appear in your pdf). 2. Document Structure The structure of a Latex document can be divided into four sections: class of the document (article, book, letter). packages used that gives access to various features or customized command. If needed information on the document title, author, date, abstract. Body of the document (introduction, sections, equations, figures, tables and bibliography). The following sections describes how to set up a Latex document s class, packages and body. Remark: Two examples are provided in CAAM519 webpage. All required files to compile the examples are contained in.tar.gz files. To uncompress (untar) these files, use the command: 1
2 tar xvf CAAM519 LATEX EXAMPLE 1.tar.gz tar xvf CAAM519 LATEX EXAMPLE 2.tar.gz It will create two directories called CAAM519 LATEX EXAMPLE 1 and CAAM519 LATEX EXAMPLE 2. 3. Document class To start writing a document with Latex, the first step is to decide what kind of document you are writing (book, article, oral presentation). This is done by using the following command: \ documentclass { class } where class has to be substituted with the kind of class you want to use. The following subsections gives details on which class you can use and their characteristics. Note that this command should always be the first line of a Latex document. 3.1. Scientific paper. There is four main class of writing documents offered by Latex: book. article. amsart (class of article). letter. In addition to the type of class, extra arguments can be given to documentclass command as follows: \ documentclass [11 pt ]{ article } where we set the font size of the article to 11. When writing a book or an article, the body of the document is divided into: chapter (only for book class). section. subsection. subsubsection. paragraph. For example to start a new section type the following command: \ section { name of my section } 3.2. Oral presentation. Latex also allows to write oral presentation. Such documents use the class beamer and can be generated as follows. \ documentclass [10 pt ]{ beamer } The body of the document is divided into frames (slides). \ begin { frame } content \ end { frame }
LATEX TYPESETTING SYSTEM. CAAM 519, CHAPTER 3 3 4. Loading packages Latex allow us to load package at the begining of a document. These package give access to various commands that allow to: change the pdf output format (document s margin, etc.). use mathematical formulae (integral, fraction, equation, etc.). include figures with caption. manage the bibliography. Here is a list of packages I recommend to use in any scientific article. \ usepackage { amsthm, amsmath, amssymb } % math packages ( always include ) \ usepackage { geometry } % can be used to modify page dimensions, etc. \ usepackage { graphicx } % figure \ usepackage { float } % figure position in pdf \ usepackage { multirow } % table with multirow \ usepackage [ labelfont = rm ]{ subcaption } % subcaption of figure \ usepackage [ numbers ]{ natbib } % management of bibliography \ usepackage { listings } % use to display a block of code Note that text following the symbols % are comments. We refer to the course and the example of CAAM 519 webpage for more details on Latex s packages. 5. Document body and command The body of the document is written between the following command: \ begin { document } document body ( sections, figures, equations, etc.). \ end { document } The following subsections provide information on how to insert text/mathematics formulae, figures, table and references. 5.1. Text and math modes. There is three ways of inserting content or instruction in a Latex document: use a Latex command. They all start with a backshlash: \. For example, we previously describe how to set up the class of the document or load packages. write plain text. This can only be done in the body of the document. Note that you can write comment anywhere in your file. To do so, use the symbol % then write your comments (on the same line after the symbol %). write mathematical formula. It can be done in three ways: Write a formula between two symbols $ to insert the mathematical content in a sentence. It gives: x 2 1 = x 2. Use one of the following commands to center formula: $$ x _1^2= x_2.$$ \[ x _1^2= x_2.\] It gives: x 2 1 = x 2. It is also possible to use Latex command to write equation or other mathematics content.
4 5.2. Figures. Here is a generic command used to insert figure in a Latex dociment. \ begin { figure }[ ht] \ includegraphics [ width =0.5\ textwidth ]{ rice _ caam. jpg } \ caption { Logo of CAAM dpt, Rice University.} \ end { figure } It displays the following figure. Figure 1. Logo of CAAM dpt, Rice University. It is possible to set different position of the figure by modifying the option [ht] (ht means here or top of next page). The figure size is set with width=0.5\textwidth (here I set half the vertical-size of the page). 5.3. Tables. Here is a generic command used to insert table in a Latex dociment. \ begin { table }[ ht] \ begin { tabular }{ c c r } \ hline First row & $\ cos ( e^x)$ & $x _1+ x _2$ \\ \ hline Second Row & a & b \\ \ hline \ end { tabular } \ caption { My first table } \ end { table } It displays the following table. First row cos(e x ) x 1 + x 2 Second Row a b Table 1. My first table The command hline draws a horizontal line while option can be given to the tabular command to create vertical line and align the text of each column (either left, center or right with l, c or r). 5.4. Labels and references. Latex allows to associate labels to figures, tables, equations and sections of your document. It is done by using the command label as follows: \ section { Name section 1} \ label { label _ name } or
LATEX TYPESETTING SYSTEM. CAAM 519, CHAPTER 3 5 \ begin { table } ( your tabular ) \ label { label _ name } \ end { table } You can refer to your label with the command ref. \ ref { label _ name } Remark: The text editors Kyle and Texmaker offer an auto completion feature when using the command ref. To gain time, I advise to use label names of the form sec:name for sections, fig:name for figures, eq:name for equations and tab:name for tables. 5.5. Display block of code. It is done with the package listings. First we define a style of code block. We need to choose the language, backgroundcolor, color of the keywords or commented words as follows: \ lstdefinestyle { TexStyle }{ language ={[ LaTeX ] TeX }, frame = single, backgroundcolor =\ color { white }, basicstyle =\ small \ ttfamily, morekeywords ={ maketitle, includegraphics }, keywordstyle =\ color { blue }, commentstyle =\ color { gray }, stringstyle =\ color { black } } The above definition has to be located before the beginning of document s body. After defining the above style, we can display a block of code with the following command: \ begin { lstlisting }[ style = TexStyle ] block of code to display. \ end { lstlisting } 5.6. Short list of Latex commands. Here is a short list of Latex commands. \\ to inser a line break. theorem. Write theorem. equation. Write an equation. multline. Write long equation (more than one line). align. Align multiple equation. minipage. Split the page in minipages (columns). We refer to the course and the example of CAAM 519 webpage for a description of these commands. 6. Bibliography The bibliography of your document should be saved in a file with the extension.bib, for example biblio.bib. You can add reference in this file using the website scholar.google.com as follows: Go to scholar.google.com Search for the article you want to cite (enter the article s name or author).
6 Once you see the article, click on cite then bibtex. Then just copy the bibtex quote in your file biblio.bib. Here is an example. @book { stroustrup 2013 c++, title ={ The C ++ programming language }, author ={ Stroustrup, Bjarne }, year ={2013}, publisher ={ Pearson Education } Then you can cite this book/article in your document using the command cite: \ cite { stroustrup 2013 c ++} The last step consists of telling Latex which bibliography style should be used and which bibliography file(s) should be read. It is done at the end of the body document with the following commands. \ bibliographystyle { abbrvnat } \ bibliography { biblio }