Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to LaTeX

Introduction to LaTeX

Gregory Ditzler

December 04, 2013
Tweet

More Decks by Gregory Ditzler

Other Decks in Education

Transcript

  1. An Introduction to Typesetting with L A TEX Sponsored by

    IGSA, DIG, and GSA Gregory Ditzler Drexel University PhD Candidate Vice President of DIG Dept. of Electrical & Computer Engineering Gregory Ditzler (Drexel University) L ATEXTutorial 1 / 20
  2. What is L A TEX? L A TEXand Typesetting According

    to Wikipedia, L A TEX is a “document preparation system and document markup language” extends the TEX typesetting system well-suited for the production of long articles, books and theses easy to learn, but there is a bit of a learning curve documents can be prepared with a simple text editor (e.g., Vim, Emacs) Central Idea: focus on the content of the document, not the presentation of the document central difference between typesetting and document processing! typesetting lets the user focus on the logical structure of their document rather than the initial presentation. Is L A TEX only for word-like documents? No. It can be used for presentations and posters too! Word Processor vs. L A TEX Word processors, such as Word and Pages, integrate all document processing operations into a single computer program. The formatting, display, and final output is all presented in the same program. By formatting we mean defining lines, sections, paragraphs, chapters, . . . Typesetting with L A TEX only focused on formatting the document. Content not presentation! input text into the document defining the structure compile the document view output (i.e., DVI, PDF, PS) Gregory Ditzler (Drexel University) L ATEXTutorial 2 / 20
  3. More L A TEX What type of tools do you

    recommend? Editors/GUIs: TeXShop (Mac), TeXworks (Linux/Windows), Texmaker (Mac/Linux/Windows) At the end of the day, all you really need is a simple text editor Bibliography: BibDesk (Mac), JabRef (Linux/Windows) BibDesk and JabRef can act as na¨ ıve reference managers. Other tools, such as Mendelay and Endnote, can export to the bibtex file format. Getting help: http://google.com Advantages / Disadvantages Pros: great for large documents (journals, theses, books), beautiful mathematics, consistent formatting, great figure generation tools Cons: learning curve, not for those work a nit-picky about the absolute appearance of their document, grammar/spell checker (?). Gregory Ditzler (Drexel University) L ATEXTutorial 3 / 20
  4. More L A TEX advantages auto title pages auto table

    of contents auto table of figures auto table of tables easy macros easy to customize write “sub”-documents easy to keep track of references light weight within document links superior quality cost (ugh, free!) Time Saver: Changing from one document format to another could be as simple as changing a few lines of code rather than the format to the entire document. Gregory Ditzler (Drexel University) L ATEXTutorial 5 / 20
  5. Making Documents With L A TEX Creating a Document Documents

    are written with a simple text editor. Therefore you need a way to view the “output” (e.g., pdf) of the final document. The general steps to viewing a document are: 1 write your document in a text editor and use a .tex extension 2 build using your GUI or pdflatex in a terminal to the .tex file 3 (optional) build the bibliography and run step (2) again 4 view document with a pdf viewer A Few Notes Before We Get Started Special characters: $ \ { } $ ^ _ % ~ # & \ is used to begin a control sequence \textbf{bold text} - { } are used for grouping $ is used for inline math mode ^ and _ produce super and subscripts in mathmode % produces comments in a document (like comments in a computer program) # is used to specify arguments in definitions of control sequence & is used to separate columns in a table Multiple spaces in the text document have no effect. E.g., “ hello world” and “hello world” produce the same output Gregory Ditzler (Drexel University) L ATEXTutorial 6 / 20
  6. Your First L A TEX document Basic Document Properties A

    basic document is easy to make and doesn’t require much work. From this basic code, we can begin to build upon it to create a larger document. \documentclass setups up the type of document we want an some of its properties everything between \begin{document} and \end{document} contains the main body of the text Defining Sections: \chapter{}, \section{}, \subsection{}, \subsubsection{} \documentclass[a4paper,12pt]{article} # letter, report, book, ... \begin{document} \title{Some Title} \author{Your name} \maketitle \section{Introduction} \label{sec:intro} # this is a comment an will not show up in the final doc. This is a boiler plate template for your first \LaTeX \textbf{document}. The Greek character alpha is $\alhpa$. \end{document} Gregory Ditzler (Drexel University) L ATEXTutorial 7 / 20
  7. Your First L A TEX document (example1.tex) \documentclass{article} \usepackage{amsmath,verbatim} %

    add packages to use - kind of like import with Python \usepackage{amssymb} \begin{document} \title{Our First Document} \author{You and I} \maketitle \section{Introduction} \label{sec:intro} This is the 1st paragraph and from what I can tell, it is a really great paragraph. I can do double ‘‘quotes’’ like that and single quotes like ‘this’. The quantity $\pi$ is approximately 3.14159 and boldface text can be entered like \textbf{this} or like {\bf this}. You can use special characters like ‘‘c{\oe}ur de pirate’’. The second paragraph is created by adding an extra space between the text. Notice that we are not working on how our document looks $\rightarrow$ only on how it is formatted. \section{More about \LaTeX} In section \ref{sec:intro} we talked about creating paragraphs, now we are referencing the first section with the \verb|\ref{sec:into}| command sequence. Equation \eqref{eq:expectation} contains the expectation of the random variable $X$. \begin{equation} \mathbb{E}[X] = \int_{-\infty}^{\infty}{ x p(x) \textrm{d}x } \label{eq:expectation} \end{equation} \end{document} Gregory Ditzler (Drexel University) L ATEXTutorial 8 / 20
  8. The Greek Alphabet Greek letters can be used in inline

    math and equations. All the commands are entered in an equation environment or $insert code here$. α \alpha µ \mu β \beta ν \nu γ \gamma ξ \xi \epsilon π \pi ζ \zeta ρ \rho η \eta σ \sigma θ \theta τ \tau ι \iota υ \upsilon κ \kappa φ \phi λ \lambda χ \chi ψ \psi ω \omega δ \delta Gregory Ditzler (Drexel University) L ATEXTutorial 10 / 20
  9. Mathematical Symbols I am a bit too lazy to type

    all these out http://www.matgs.tcd.ie/~dwilkins/LaTeXPrimer/MathSymb.html There are many builtin functions: \cos,\sin,\tan,\csc,\exp,\lim,\sup,\inf,\gcd,\lg,\log,\ln \min,\max,\dim,\tanh,\Pr,\deg,\limsup Accents: \underline{a},\overline{a},\hat{a},\check{a},\tilde{a} \acute{a},\grave{a},\dot{a},\ddot{a},\breve{a},\bar{a} There are a lot more! Gregory Ditzler (Drexel University) L ATEXTutorial 11 / 20
  10. List and Enumerations Itemized Lists All through out this presentation

    you have seen that I used bulleted, or itemized, lists a lot. How is it that I can do this in a simple text file? Itemized lists are called upon through the itemize environment. Example on the next slide. Lists can be placed into sublist, subsublists, . . . Enumerated Lists Other forms of lists exist too. Many times you need to number the “bullet” points. We call these enumerated lists. For example, 1 something happens 2 then another thing happens 3 then we are done 4 also this is a sublist! Gregory Ditzler (Drexel University) L ATEXTutorial 12 / 20
  11. List and Enumerations (the code) \begin{itemize} \item item 1 \item

    item 2 \item item 3 \end{itemize} \begin{enumerate} \item item 1 \item item 2 \item item 3 \end{enumerate} \begin{itemize} \item Other forms of lists exist too. Many times you need to number the ‘‘bullet’’ points. We call these enumerated lists. For example, \begin{enumerate} \item something happens \item then another thing happens \item then we are done \item also this is a sublist! \end{enumerate} \item here is another item, but it is not numbered \end{itemize} Gregory Ditzler (Drexel University) L ATEXTutorial 13 / 20
  12. Figures Using Figures in L A TEX Figures are a

    common component and there are a few very important differences between working with figures in L A TEX and a document processor 1 In L A TEX documents you cannot view the figure! Its only a text file. 2 Figures can be viewed after the document has been compiled 3 L A TEX determines the best location for the figure Some people hate that last bullet point because they do not have absolute control of the figure placement. (I happened to like it!) A graphics package must be included in the document to display figures. \usepackage{graphicx} There is a lot to graphics in L A TEX, but we will only go over basic examples. Figure: xkcd is one of my favorite comics Gregory Ditzler (Drexel University) L ATEXTutorial 14 / 20
  13. Figures (the code) \begin{figure} \centering \includegraphics[scale=.25]{compiling.png} \caption{\texttt{xkcd} is one of

    my favorite comics} \label{fig:xkcd} % this is the reference we use to call upon the figure \end{figure} Figure: xkcd is one of my favorite comics Gregory Ditzler (Drexel University) L ATEXTutorial 15 / 20
  14. Tables Tables in L A TEX The table and tabular

    environments are used to create tables in L A TEX. table environment goes outside of tabular and allows for the addition of referencing tables and adding captions. Captions and labels are used the same way that they are used in figures. tablular is used to typeset tables with optional horizontal and vertical lines. This is where we make use of the & symbol. Required to make a table L A TEX allows for multiple columns, multiple rows, vertical lines in the table, column alignment (center, right, left), . . . Table: This is a table caption col 1 col 2 col 3 something kinda cool this is easy Gregory Ditzler (Drexel University) L ATEXTutorial 16 / 20
  15. Tables (the code) \begin{table} \caption{This is a table caption} \label{table}

    \begin{center} \begin{tabular}{l || c c} \hline \bf col 1 & \bf col 2 & \bf col 3 \\ \hline \hline something & kinda & cool \\ this & is & easy \\ \hline \end{tabular} \end{center} \end{table} A Word of Advice Many times we write code in R, Python, Matlab or Perl that is used to generate data and analyze our results. Rather than manually creating the contents of the table you can write a script to create the table. Ex., Bash command to convert a CSV file to a L A TEX formated table cat ex1.csv | tr "," "&" | sed ’s/$/\\\\/g’ Gregory Ditzler (Drexel University) L ATEXTutorial 17 / 20
  16. Citations Using Citations BibTex is the easiest way to handle

    citations in your document. There are may reference managers freely available that handle the BibTex format without actually view the BibTex format. (I’ll show you a demo) A citation package must be added to the top of your document. I recommend using cite or natbib. Depending on the reference style would call for one of the packages over the other (i.e., APA, Chicago, IEEE, . . . ). Like other types of references, each citation has a label that is called when you want to make a citation. For example, if I wanted to cite my recent IEEE Transactions on Knowledge & Data Engineering article I would use something like \cite{Ditzler2013TKDE} Just add the following lines before \end{document} \bibliographystyle{ieeetr} \bibliography{myrefs} Gregory Ditzler (Drexel University) L ATEXTutorial 18 / 20
  17. Working with Large Documents Handling Multiple Files Working with very

    large documents is very difficult with programs such as Word. It becomes increasingly difficult as you add many figures into the document (such as a thesis). All chapters, sections, subsections, . . . are located in the same document. Recall that a L A TEX document is simply a text file. Doesn’t get too much more light weight than that! the logical structure of a document may contain several different sub-levels L A TEX allows authors to write their document with multiple files and combine them together. This keeps the user from ending up with 1000+ line text files. \documentclass{article} \begin{document} \title{Our First Document} \author{You and I} \maketitle \input{section1.tex} \input{section2.tex} \input{section3.tex} \end{document} Gregory Ditzler (Drexel University) L ATEXTutorial 19 / 20
  18. A Few Notes Before the Demo and Example Time New

    to L A TEX? Compile often! My best piece advice: practice! reading about it is not as helpful Other useful things \tableofcontents: generate a table of contents \listoffigures: generate a table of figures \def: create command definitions. e.g., \def\xbf{\mathbf{x}} allows use to use \xbf instead of \mathbf{x} to create a bold face x. Gregory Ditzler (Drexel University) L ATEXTutorial 20 / 20