Introduction to L A TEX

Similar documents
Guide to using L A TEX

Learning L A TEX. Patrick Lam

Student Learning Service: Introduction to Latex

What is LaTeX. Is a document markup language and document preparation system for the TeX typesetting program

Homework # You ll want to use some LaTeX editor to edit and compile your.tex files

LaTeX A Tutorial. Mohsen Alimomeni, 2010

An Interactive Introduction to L A TEX

Intro to LATEX I. Aaron Erlich POLS/CSSS 510, Why LATEX? Programming Document Structure Floats Tables Lists Math

1 Obtaining LyX and L A TEX

Outline. Installing LaTeX. Opening TeXShop. Intro to LaTeX. Intro to LaTeX interface Working with text Tabbing and tables Figures Math and equations

L A TEX for Psychological Researchers

L A TEX Tutorial. 1 Introduction. 2 Running L A TEX. J. E. Rice. May 2010

Homework # (Latex Handout) by Laura Parkinson

Introduction to L A TEX

COMP496/901: Academic Presentation and Writing Skills Using LaTeX

An Interactive Introduction to L A TEX. Part 1: The Basics. John Lees-Miller. writel A TEX

Math 235: Introduction to LaTeX

Lecture 1: Short summary of LaTeX basics

Researcher Development Unit: Introduction to Latex

Introduction to L A TEX for MCS-236

Introduction to L A TEX

Learning LaTeX: The Basics

NCSU Linguistics Eric Wilbanks & Jeff Mielke. November 21, An open-source typesetting language used for document mark-up

Title. Author 1 Author 2 Author 3. January 23, 2015

Introduction to L A TEX

Outline. A Sneak Peek

Introduction to LATEX

Latex Tutorial. CIS400 Senior Design 9/5/2013

The basics of LaTeX. Cédric Buron. April 25, 2016

Using L A TEX. A numbered list is just that a collection of items sorted and labeled by number.

L A TEX for Psychological Researchers

An Introduction to L A TEX

Workshop: A Simple Introduction to L A TEX

An introduction to L A TEX for students

1 Different Document Classes

Become a L A TEX Guru

Introduction to L A TEX

An Introduction to. Rado Ivanov CIS400 Senior Design Tutorial September 18, 2014

Effective Programming Practices for Economists

A Beginner s guide to L A TEX for CSCA67/MATA67. Kohilan Mohanarajan

An Interactive Introduction to L A TEX. Part 2: Structured Documents & More. Dr John D. Lees-Miller. writel A TEX.

Assessments for CS students:

LATEX Primer. 1 Introduction (Read Me)

LATEX TYPESETTING SYSTEM. CAAM 519, CHAPTER 3

An Introduction to LATEX

Introduction to Latex. A workshop by Dr. Ala Eshmawi

Introduction to Math in LaTeX

LearningLatex. % This file walks you through some basic things with LaTex % Thanks to Patrick Lam and Maya Sen for letting me borrow their materials

L A TEX Class Holiday Inn Fisherman s Wharf San Francisco, CA July Cheryl Ponchin Sue DeMerritt

Introduction to L A TEX

Formatting with LaTeX

Introduction to MCS 220 and L A TEX

PRISM Introduction to L A TEX

T E X and L A T E X Document preparation tools

An Introduction to L A T E X

L A TEX Primer. Randall R. Holmes. August 17, 2018

Excellent support for mathematical formatting. Automatically downloads/installs missing components as needed Updates somewhat frequently

An Introduction to LATEX

The Name of the Game. An Introduction to LATEX. Why L A TEX? The Name of the Game

Simple Math. Adam Dishaw 2011 September 21. Suppose you want to include some math in your documents. Just follow these basics steps:

Introduction to LaTeX. Paul Fodor Stony Brook University

Workshop on LATEX 2ε. Asst. Prof. Dr. Kemal Bagzibagli Department of Economics. 20 May 2015

L A TEX Overview. Jiayi Liu. January 31, Colorado School of Mines

How to get started in L A TEX

L A TEXInstallation and Introduction

L A T E X Workshop. Bijulal D & Anu Thomas Industrial Engineering and Operations Research Indian Institute of Technology

Pimp your thesis: a minimal introduction to L A T E X.

Absolute L A TEX Beginner

Introduction to LAT E X

1. Welcome. (1) Hello. My name is Dr. Christopher Raridan (Dr. R). (3) In this tutorial I will introduce you to the amsart documentclass.

VERY VERY SHORT GUIDE TO LATEX

Introduction to L A TEX beamer

Abstract A quick intro by examples to the document preparation language L A TEX.

OER Publishing with LaTeX and GitHub

Citation guide. Carleton College L A TEX workshop. You don t have to keep track of what sources you cite in your document.

Typesetting in wxmaxima

The L Y X Tutorial. by the L Y X Team 1. December 2, them to the LYX Documentation mailing list:

LaTeX is essentially a markup language

LaTeX. Information Literacy II EN(IL2) Course

L A TEX examples. a b c a b c b b a c b c c b a. This table was typeset with the following commands.

Introduction to LaTex 2ε. Based on The Not So Short Introduction to LaTeX 2ε by Tobias Oetiker et al., April 2001

A Very Brief Introduction to L A T E X MAT 3535

L A TEX minicourse. dstowell, mag, sar, scannell,... September Typeset by FoilTEX

An Introduction to. Andrew G. West, Jian Chang CIS400 Senior Design Tutorial September 15, 2009

LYX with Beamer and Sweave

L A TEX From The Ground Up

L A TEX. COMPSCI 111 / 111G Mastering Cyberspace: An introduction to practical computing. LaTeX. Development. Why?

Mikkel Madsen

LATEX Workshop. Yi Liu Chen SUNY Geneseo PRISM Math Club. February 6, Wordmark Reversed Geneseo Wordmark Style Guide 4

How to L A TEX. George Wong, David Mykytyn. 6 October 2016

How to Prepare Your Paper in L A T E X for IOE Graduate Conference 2017

Latex Tutorial 1 L A TEX. 1.1 Text

L A TEX for psychological researchers

Introduction to LAT E X

Math 395 Homework #1 Due Wednesday, April 12

Course A, Part 1 Basic Formatting in L A TEX

L A T E X FOSSEE. Department of Aerospace Engineering IIT Bombay. FOSSEE (IIT Bombay) LAT E X 1 / 58

Meeting One. Aaron Ecay. February 2, 2011

David Helmbold, October 2005, Revised October 2007

Introduzione a LaTex. Fabrizio Messina

Transcription:

Introduction to L A TEX Guillermo Toral & Weihuang Wong MIT September 15, 2017 These slides build on materials from previous years by Dan de Kadt and Elizabeth Keysner, and on The Not So Short Introduction to LATEX. 1 / 40

What we ll cover today 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 2 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 3 / 40

What s L A TEX? L A TEXis a typesetting system that produces high-quality documents anything from letters, papers, dissertations, posters, slides (like these ones), resumes, etc. L A TEX, unlike Word or other normal word processor, is not a WYSIWYG ( what you see is what you get ) system. So using it requires a bit of a change of mindset. In L A TEX, you write the code, and then the software compiles or creates the document as a PDF file. Like R, there are hundreds of add-ons available that you can use. 4 / 40

Why use L A TEX? L A TEX makes math much easier to write and to display well: f (y) = Y i = α + X i β + ε i 1 ( [ y!γ(α)β α µ y+α 1 exp µ 1 + 1 ]) β L A TEXworks well with R: you can easily input plots and tables from R, and you can even write LaTeX documents directly from R, through R Markdown L A TEXmakes it easy to manage large documents, with references and bibliography, cross-references and links inside the document, etc. L A TEXis used widely in the scientific community, and some people see it as a signal of credibility. 5 / 40

Things to keep in mind about L A TEX L A TEXis a skill that takes some effort and patience to build. Grad school gives you the time and incentives to do so invest some effort, and it ll pay off. L A TEXis a good tool for some purposes once you master it, it becomes very easy to use, and it allows you to do cool things that would be harder to do without L A TEX. L A TEXis not so good for other purposes, like spellchecks or review tools, although you can also do those in L A TEX. L A TEXis a tool the more you have, the better. 6 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 7 / 40

Commands & spaces Commands: L A TEX commands start with \ and continue with letters or with one non-letter. Many commands have a starred version, where the name of the command is followed by *, and usually tells L A TEX to omit numbering (e.g. do not number this equation, or this section). White spaces: Whitespace characters (whether one space, one tab, or several spaces / tabs) are all treated as one space. An empty line or multiple empty lines are all treated as an empty line (which ends a paragraph). Spaces after commands are ignored, so it s good to write { } after them: L A TEX{ }. You can insert a line break with \\ or \newline. For a page break, use \newpage. 8 / 40

Reserved characters There are some reserved characters in L A TEX: \ says: read text following this as an operation. $ says: open an inline math environment. Put another to close it. % says: ignore text that follows allows you to comment your code. & says: position this to line up with other position indicators. {} says: group these items. _ says: write what follows as underscript. ˆ says: write what follows as upperscript. If you actually want to print these characters, you need to use \ before them (e.g. \&), or textbacklash for the backslash. 9 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 10 / 40

Key components of a L A TEX document L A TEX documents have several key components: Preamble: declares the type of the document, gives its parameters, and loads packages Titling: declares the document s title, author(s), and date. Document itself, which may include a title page, sections, subsections, bibliography, etc. A minimal L A TEX document includes the following code: \documentclass[options]{class} \usepackage[options]{packages} \begin{document} Your document. \end{document} 11 / 40

L A TEX mechanics Here are the steps you usually take for creating a document with L A TEX: Write in your.tex file, and save it. Compile the L A TEX file into a PDF by pressing the corresponding button in the TeX software you use. Sometimes you need to do this several times, especially if you have sections or bibliography in the document. A new PDF file (and a number of auxiliary files terminating in.aux,.out,.toc, etc.) appear in the same folder where your.tex file is. It is useful to compile your PDF from time to time as you write, to make sure it s compiling correctly. You can use your Tex and your PDF reader side by side, and have the PDF refresh automatically each time you compile, so you can see in real time how your output looks like (this is what TexMaker does). 12 / 40

Let s practice! Let s start by building a minimum article document. Open the template.tex file and fill it up: give it a document class, fill in the titling information, and add some text in the document. Try structuring your text with sections, by using \section{section name}. You can also use \subsection{} and \subsubsection{}. You can also add some \footnote{}. When you re ready, save the file and compile it. Open the resulting PDF file. 13 / 40

An empty template for a.tex file 14 / 40

A simple.tex file 15 / 40

The resulting PDF file 16 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 17 / 40

What s an environment? L A TEX uses environments to format content: When you \begin{environment} a set of rules is applied to the content that appears within that environment. When you \end{environment} those rules no longer apply. Environments can be embedded within environments. The biggest environment is the document environment, which bounds the entire document you make. Within the document environment you might use a bullet-point environment ( itemize ), and within those bullet points you might you a picture environment ( figure ). Environments can be used for including equations, tables, plots, text in different sizes or alignments, abstracts, long quotes, etc. 18 / 40

Using an environment: Here s how you can use a basic text environment, itemize : \begin{itemize} \item Math camp. \item \LaTeX {} workshop. \item Quant I. \end{itemize} Which produces the following: Math camp. L A TEX workshop. Quant I. If we substituted enumerate for itemize (make sure to use the enumitem package!) we d get a numbered list. 19 / 40

Let s practice! Now practice creating and filling an enumerate environment within your practice.tex file: Load the enumitem package in the file s preamble. Begin an enumerate environment. It takes some options: E.g., [label = (\arabic*)] or [label = \alph*.] Create items End the enumerate environment. Optional: Wrap the whole enumerate environment in a center environment. 20 / 40

Math Environments Let s now add math to our document: 1 Load the amsmath and amssymb packages in your document s preamble. 2 Begin an align* environment 3 Type in some math: Y_i &= \alpha + \beta x_i + \varepsilon_i 4 And a second line: Y_i - \varepsilon_i &= \alpha + \beta x_i 5 End the align* environment. This will produce a set of aligned equations: Y i = α + βx i + ε i Y i ε i = α + βx i 21 / 40

Math environments We can also create a non-aligned math environment using $ and $$. $ creates in-line math, $$ creates a new line. You must begin and end with the same symbol ($ or $$). Example of in-line math with $: writing $1+1=2$ will produce 1 + 1 = 4. Example of new-line math with $$: writing $$1+1=2$$ will produce 1 + 1 = 2 If you want new-line, numbered equations, but you don t want to align them, or you re writing only one equation, you can use the environment equation. 22 / 40

Some Math Symbology L A TEX code Output What to use it for y_x y x subscript y_{xxx} y xxx multiple-letter subscript y^x y x superscript y^{xxx} y xxx multiple-letter superscript \sqrt{x} x square root \sqrt[y]{x} y x y-th root y^{xxx} y xxx multiple-letter superscript x \frac{x}{y} y fraction \alpha α Greek letters n 1 \sum_{k=0}^{n-1}a r^k k=0 ar k sums \int_0^{\infty} integrals 0 \lim_{n \to \infty} lim n limits \hat{x}, \widehat{xy} ˆX, XY hats \mathcal{r} R math font 23 / 40

Figure & table environments: Floats The positioning of floats can be frustrating if you don t know how they work or don t use the tools you have to control them. Every float has an optional positionning parameter: \begin{figure}[placement specifier]. The default placement specificier, the one L A TEX uses if we don t specify anything, is tbp, which stands for at the top of the page, at the bottom of the page, and at a special page containing only floats. When L A TEX encounters a float, it tries to place it in the current place and if it can t, it puts it in a figures queue or in a tables queue, and every time it starts a new page, it tries to fill a special float page with floats from the queues. If it can t, it tries to place the first float in the queue. L A TEX maintains the order in the queue. You can use other placement specificers, like h (for here), or! (which basically says override other parameters ). To avoid floats appearing outside the section where they belong (or say beyond a certain paragraph), you can use \FloatBarrier. 24 / 40

L A TEX Commands Commands are another way of taking in content and create output: No need to use \begin and \end with commands. Instead you simply use \COMMAND{YOUR INPUT}. We ve already used a couple, like \section or \item. Some commands take options in square brackets: \COMMAND[OPTIONS]{YOUR INPUT} We can use commands to include graphics in our document: 1 Load the graphicx package. 2 Begin a center environment so the graph shows centered. 3 Use the includegraphics command. It takes some options and some arguments: 4 Options in square brackets: [scale =.5] 5 A filename in curly braces: {graph.pdf} 6 End the center environment. 25 / 40

Some useful commands 26 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 27 / 40

Working with L A TEX and R: Tables R code: mod1<-lm(y~x1+x2) mod2<-lm(y~x1*x2) xtable(mod1,mod2) OR stargazer(mod1,mod2) Note: xtable is a more generic function, will turn any matrix or data frame into a table. Stargazer is very flexible, and highly recommended. Output from L A TEX: Model 1 Model 2 (Intercept) 2.94 0.24 (0.40) (0.36) x1 5.54 5.03 (0.06) (0.06) x2 6.32 1.50 (0.32) (0.49) x1:x2 0.95 (0.09) N 100 100 Standard errors in parentheses indicates significance at p < 0.05 28 / 40

Working with L A TEX and R: Graphics Normally you want to export R plots as PDF files, not JPEG or PNG (unless you re dealing with a very large file like a map): Plot produced by R: R code: pdf(file="filename.pdf") plot(rnorm, ylab= Personal happiness, xlab= LaTeX ability, lwd=3, col= blue ) grid(lty= dotted ) dev.off() Personal happiness 2 1 0 1 2 3 0.0 0.2 0.4 0.6 0.8 1.0 LaTeX ability 29 / 40

Working with L A TEX and R: Verbatim When you want to import R-Code into your L A TEX document, you have to use a special environment that allows the code to appear as is, with lines and special symbols intact. The best use for this is verbatim. To use, simply type: \ begin{verbatim} Paste your R-Code, then... \ end{verbatim} 30 / 40

Exercise: Export a graph and regression table into L A TEX 1 Open the R code file we sent you 2 Change filename, then using the pdf wrapper, run the graphing code 3 Run the R code to create data 4 Run the R code that estimates models 1 and 2 5 Using one of the table commands, export a regression table for both models 6 Import the graph and the table into your L A TEX document 31 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 32 / 40

Labels & references Whenever you create a graph, table, or equation, you should label it Equations: Before you end your equation environment, include \label{eq_key} Figures: You must wrap your figure in a figure environment, then include \label{fig_key} before you end your figure environment Tables: You must use a table environment, then include \label{tab_key} before you end the table environment Now, whenever you reference the equation, graph, or table in line, call the relevant label with \ref{type_key} L A TEX will automatically order the objects of each type, giving you nicely numbered labels Figure \ref{fig_treateffect} shows blah blah blah Figure 7 shows blah blah blah These will also sync with the captions you give to tables or graphs, which are also automatically numbered 33 / 40

Exercise: Label and reference your graph and table Make sure you use the right wrapper environments Use the \label command Give appropriate labels to both objects Call the objects in-line 34 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 35 / 40

What is BibTeX and how does it work? BibTeX, which is included in most TeX distributions, allows you to compile references throughout your.tex file, and to produce bibliographies automatically with pretty much any style you want. BibTeX is a compilation procedure for your L A TEX code. You run it in concert with the regular L A TEX compiler. Two runs of L A TEX then BibTeX then L A TEX again... (1)L A TEX (2)L A TEX (3)BibTeX (4)L A TEX Voila! To use BibTex, we need to create a.bib file with our references in the correct format. Then we can "call" that file when compiling our.tex file. 36 / 40

The.bib file @article{lipset1959, title={some social requisites of democracy: Economic development and political legitimacy}, author={lipset, Seymour Martin}, journal={american political science review}, volume={53}, number={1}, pages={69--105}, year={1959} } @book{dahl1973, title={polyarchy: Participation and opposition}, author={dahl, Robert Alan}, year={1973}, publisher={yale University Press} } Note that lipset1959, dahl1973 are the (unique) keys, which we will use to cite it in our.tex file. You can directly get the formatted code for BibTeX references from Google Scholar, Zotero, etc. 37 / 40

Let s practice using BibTeX Add a new article to a.bib file: Open practice.bib in your TEX editor Search for the article you want to include in Google scholar (or similar) Export the citation in format (click cite...) Copy the format citation into practice.bib Change the key to authoryear (or similar) Cite your new article and make a bibliography: Use the natbib package (Mac users may need package cite too) Create an inline citation using \citet{key} Then a parenthetical citation with \citep{key} Finally, include \bibliography{practice.bib}{} and \bibliographystyle{chicago} at the bottom of your document Compile: L A TEX (2)L A TEX (3) BibTeX (4)L A TEX (or simply do "Quick build" in TeXMaker after you ve configured it to do include BibTex compilation in Quick build going to texmaker > preferences > quick build). 38 / 40

Where we are 1 Introduction 2 L A TEX Language 3 Setting up a L A TEX document 4 L A TEX environments & commands 5 L A TEX and R 6 Referencing objects 7 Reference management in L A TEX using BibTeX 8 Troubleshooting 39 / 40

What to do when things aren t working Sometimes L A TEX just won t compile, or compile and then delete the PDF file. Delete auxiliary files and compile again Think of what you edited since last time you successfully compiled your.tex file, and look at the code you added / edited the error must be there. Try googling your problem Check the.tex Stack exchange forum, and post a minimum working example if you can t find anything. Practice! Use L A TEX to complete your problem sets for Quant I. Reach out to Quant I TAs for help Feel free to post L A TEX questions on Piazza, or raise them at recitation and/or office hours. 40 / 40