Help Desk

Computing & Information Services

Introduction to LaTeX

• The Syntax of LaTeX
• Ten Strange Things You Need To Know About LaTeX
• Text Formatting
• Type Size and Style Commands
• Paragraph Formatting
• Commonly Needed Formatting Environments for Paragraphs
• Special Characters and Symbols Charts

As you may have guessed, LaTeX is not a What You See Is What You Get word processor like Microsoft Word. Instead, LaTeX is a markup language like HTML. To force a new page, you don't press a button or go to Insert->Pagebreak, you just write \newpage. To make a word italic, you surround the word in a command like \textit{ wordhere}. This may seem like a lot of work, but it becomes second nature fairly quickly. The benefit to all this markup is that your documents look like you want them to look, not how MS Word decides is the best way. This is especially true for tables, lists and paragraph formatting. The resulting file (extension .tex) is also a lot smaller than a Word file, which means that your thesis backups are lightning-quick.

The Syntax of LaTeX

The basic language of LaTeX is broken up into environments and commands. Both begin with a backslash (\) and have required arguments (such as the text you want to modify or the name of the environment) in {curly braces} and optional arguments (such as the scale of a graphic are in [square braces]. (Not all commands have arguments, especially optional arguments. As you will see, the required argument of an environment is usually the name of the environment itself.)

Environments need to be opened and closed, because you will be putting a large block of text or other formatting inside the environment. You write tables in the tabular environment, put long quotes in the quote environment, put math in an equation environment and add images or figures inside a figure environment. (Actually, for short usage of math mode, you bracket text and commands with $dollar signs$, which is easier than beginning and ending a figure environment. Even the document itself should be packaged inside the document environment. Obviously, you can nest environments, but make sure you close them in a nested manner as well.

To begin an environment, write \begin{ environment name here}, then when you want it to end, write \end{ environment name here}, of course replacing "environment name here" with the name of the environment.

\begin{document} %the document environment is begun
\begin{quote} %starts a long quote using the quote environment
A trait that is associated with such an explosion of species is possibly a key innovation. A key innovation opens up or allows access to an ecological niche that enables the organism to take advantage of unused resources. Exploitation of new habitats can separate a previously cohesive population through migration and then further increase physical distance between the diverging populations. The new niche (in this case, different pollinators) can result in speciation.
\end{quote}
%ends the quote environment ( note: before ending the document environment!)
\end{document} %the document environment is ended

Commands do not need to be closed, for they are just short instructions to LaTeX. You use commands to type special symbols like angstroms ( \AA gets Å) and tildes ( \~{n} gets Ñ). Commands are also used to force line breaks (\\), new pages ( \newpage), insert today's date ( \today) and make a title page using information previously defined. (More about the title page later.) A list of common special symbols are here, and you can find more about commands used in formatting here.

A Very Basic Document

There are three commands you must include in every LaTeX document. Each should be on its own line. They are:

\documentclass[ options]{ class} % very first line of the entire document
\begin{document} %Begins document environment
\end{document} %Ends the document environment

The document class command sets the formatting for things like the title page and margins. You can define a number of things within the [square brackets], such as text size: 11pt or 12pt (the default text size is 10pt and too small for most professors), and page layout: twoside (doublesided printing) or twocolumn (common in physics lab reports and journal articles) and many others.

Within the {curly braces} you put the name of the document class. Your choices are article, letter, report, book, or a custom document class you have downloaded. If you are using LaTeX for a normal paper, you should use the article class. If you are writing your thesis, you should use the thesis template.

The document class command marks the beginning of the preamble, which ends with the \begin{document}. Inside the preamble you can specify packages, custom commands or spacing to use. You will want to include a few packages so that you can add graphics (graphicx), use custom spacing (setspace), rotate pages (portland or lscape) or use another language (see the languages section) or font (here). Many of these packages are already installed, so all you need to do is write \usepackage{package name} in the preamble, obviously replacing "package name" with the name of the package to be used. Each \usepackage should be on its own line, but you can easily refer to more than one package inside one set of curly braces; just separate the names with a comma.

\documentclass[12pt,fullpage]{article}
\usepackage{graphicx,latexsym}
\usepackage{longtable}
\usepackage{fullpage, setspace}
%an example of how to specify two packages at once.
\begin{document}
\maketitle
%this command makes a title page using the \title and \author information in the preamble.
\end{document}

Now you need to typeset your file, which translates the markup into something pretty and readable, similar to opening your .html file in a web browser. Press the Typeset button, first making sure that LaTeX is selected next to it. Wait for the computer to finish processing the file and your PDF will pop up. Voila! Your first LaTeX document is complete.

The Typeset button will automatically save your document, but it never hurts to save at the end of every paragraph by selecting Save under the File menu. To print your document, go to the File menu and select Print... while the PDF file is entirely visible and at the front of the screen.

If you want to comment out a line so it will not appear in your completed document, place a % at the start of the line.

Ten Strange Things You Need To Know About LaTeX

1. You should not use the " for quotation marks as you would on a typewriter.
In publishing there are special opening and closing quotation marks. In LaTeX, use two ‘s (grave accent, above the tab key) for opening quotation marks and two ’s (vertical quote) for closing quotation marks. For single quotes you use just one of each.
2. It does not matter whether you enter one or several spaces after a word. LaTeX ignores all extra whitespaces.
3. An empty line starts a new paragraph, or you can use two backslashes (\\) and no empty line. Two empty lines, on the other hand, do not make an extra large break. See this section for ways to make large breaks.
4. The following symbols (# $% ^ & _ { } ~ \ ) are reserved characters that either have a special meaning under LaTeX or are not available in all the fonts. If you enter them directly in your text, they will normally not print, but rather coerce LaTeX to do things you did not intend. As you will see, these characters can be used in your documents all the same by adding a prefix backslash: \# \$ \% \^{} \& \_ \{ \} \~{} ( more special symbols are available here)
5. When LaTeX encounters a % character while processing an input file, it ignores the rest of the present line, the line break, and all whitespace at the beginning of the next line. Placing a % before a line or line fragment is called "commenting out" or " commenting." This is useful when you want to make a note to yourself or want to temporarily remove text, an environment or commands from the typeset version.
6. You can only make LaTeX go to the next line using \\ or \linebreak. Otherwise, LaTeX decides where to begin and end lines to make your document as typographically beautiful as possible.
7. LaTeX will always force a slightly larger space after a period, but with abbreviations like etc., an extra space is incorrect. Place a \ character directly before a period that should not have any space, and put \thinspace directly after. For periods after single letters ( E. coli), LaTeX does not use an extra-large space. Thus, to get et al. and etc., write: et al.\thinspace and etc\.,
8. Some commands are only available in math mode, such as superscript ( \^{ script}), subscript ( \_{ script}) and Greek letters. You can bracket these commands with dollar signs ( $\^{ script}$) or for more prolonged usage of math mode, enter the equation environment. When in math mode, spaces are not recorded unless forced with a \: (or \; for a thicker space and \, for a thinner one) and all Roman letters are italicized.
9. Sometimes when you make changes, particularly in how your document is displayed, you may need to hit typeset again in order for those changes to show up.
10. A slew of files are created when you typeset a file. See this explanation for more about the specific files. Basically, the .tex file is the only one you need to back up (and if you have a biliography, .bib), but if changes aren't showing up in your typeset file (pdf), then you might need to trash the others.

Text Formatting in LaTeX

LaTeX ignores extra spaces and line breaks in the middle of a paragraph, so you don't need to worry about having these. To signify the end of a paragraph include a blank line in your input text by pressing Return twice. Use \\ to force a line break without an indent and use \  to include an extra space (this is particularly useful when italic text is right next to other text and it looks too close.

You can change the format of your text in three different ways:

• To change all the rest of the text in your document, simply type the command (see below for commands).
• To change just a small section of text, type {\thecommand yourtext}
• To change a larger section of text, type:
\begin{ thecommand}
...yourtext...
\end{ thecommand}

Type Size and Style Commands

The below table shows how these commands change the appearance in a typeset file. To see the unscaled table, click on the image. More information on fonts and sizing can be found here.

Paragraph Formatting

There are several options to consider when formatting a paragraph - spacing, indentation, numbering or bulleting, and justification. All of these are environments, so they are given with a begin command ( \begin{ environment}) and are concluded with an end command ( \end{ environment}). This means that for each formatting change you make, you will type:

\begin{ formattingenvironment}
\othercommands
\end{ formattingenvironment}

where formattingenvironment corresponds to the formatting you want to apply.

LaTeX will single-space your entire document unless you specify otherwise. The formatting command for changing this is \spacing, after which you must type { amounttospace} where amounttospace corresponds to the spacing you intend for the paragraph (1.5, 2, 3, etc). To doublespace more than a paragraph, include \usepackage{setspace} in the header of the document before \begin{document} and put the command \doublespace before the text you want doublespaced. To go back to single spacing, use the

\singlespace command. You can also use the command \onehalfspace for 1.5 spacing.

An example of how this spacing is used:

\documentclass[12pt]{article}
\usepackage{setspace}
\begin{document}
\singlespace
Single-spaced text here.
\doublespace
All of the text here is going to be double-spaced.
\onehalfspace
All of this text is 1.5 spaced.
\singlespace
Back to single-spaced text.
\end{document}

Commonly Needed Formatting Environments

• quote - Indents a section of text from both margins
• quotation - Indenting a section of text from both margins with an indent in the first line of text
• verse - Indenting a section of text from both margins with a hanging indent (use \\ for separating lines, a blank line for stanzas.)
• verbatim - Get your text to appear in your document precisely as you've typed it in the input window, including spacing, line length, and command characters.
• enumerate - Makes a numbered list (each new item should be prefaced with \item)
• itemize - making a bulleted list (each new item should be prefaced with \item)
• flushleft - text has a ragged right edge or is left justified
• flushright - text has a ragged left edge or is right justified
• center - centering your text

Special Characters & Symbols Charts

If you cannot find the symbol you need here, The Comprehensive LaTeX Symbol List has just about every symbol you will ever need in its 91 pages. You may want to check out our advice from math grads if you have physics or math symbols.

Non-Alphanumeric Characters

 Special Characters How to get them to appear $\$ & \& # \# { \{ } \} - \- ~ \~{} (for above a character) $\sim$ (for a tilde alone) ^ \hat{} (if desired, put a character inside the curly braces.) \ $\backslash$ Left Quotation  (two grave accents) Right Quotation '' (two single quotes) ° (degree) \textdegree (must include textcomp package) °C (celsius degree) \textcelsius (must include textcomp package)

Special Alphanumeric Characters

If you need these symbols because you are writing in a language other than English, you should read our language page.

 Special Character How to get them to appear How it looks Exponent or superscript 5$^{2}$ 5 2 Subscript H$_{0}$ H 0 acute accent \’{a} or \’a á grave accent \‘{o} or \‘o (That odd tick ‘ can be found above your tab key, on the same key as the tilde.) ò cedilla \c{c} ç circumflex \^o ê tilde \~{n} or \~n ñ umlaut \"{u} or \"u (To clarify, the " is shift-apostrophe, not two single apostrophes.) ö ellipsis $\ldots$ . . .

Basic Math Symbols

(Note: generally the commands for math symbols are flanked by dollar signs. % is among the exceptions in that it does not need to be in math mode. See this tip or the math page for more details.)

 Symbol How to get them to appear About Equal $\approx$ Not Equal To $\not=$ Greater Than $>$ Greater Than or Equal to $\ge$ Less Than $<$ Less Than or Equal to $\le$ Plus-Minus: ± $\pm$ Times: x $\times$ Divide: ÷ $\div$ Fractions: 5/8 $\frac{5}{8}$ Log: log 10 $\log$$_{10}$ Percent: % \% Square Root: √ $\sqrt[2]{5}$ Mean: x $\overline{x}$ Sigma: $\sigma$

Chemistry Symbols

Chemical formulas will look best if they are not italicized. Get around math mode’s automatic italicizing by using the argument $\mathrm{formula here}$, with your formula inside the curly brackets. So, Fe2+ 2 Cr2O4 is written $\mathrm{Fe_2^{2+}Cr_2O_4}$

 Symbol How to get it to appear Stacking Symbols $\stackrel{NaOH}{longrightarrow}$ Exponent or Superscript $^{exponent}$ Subscript CH$_{4}$ To stack numbers or letters, the subscript is defined first, and then the superscript. Angstrom: °A {\AA} Bullet: CuCl • 7H2O CuCl$\bullet$ 7H2O Double Dagger: ‡ \ddag Delta $\Delta$ (note the uppercase D) Reaction Arrows $\longrightarrow$ $\Longrightarrow$ Resonance Arrows $\leftrightarrow$ $\xrightarrow[on bottom]{on top}$ Reversible Reaction Arrows $\rightleftharpoons$ $\xrightleftharpoons[on bottom]{on top}$ (needs chemarr package)

Greek Letters

The basic formula is: dollar sign + backslash + name + dollar sign. Yup, Greek needs to be in math mode unless you want to work with it as a language.

 Greek Letter How to get it to appear Alpha $\alpha$ Beta $\beta$ Gamma $\gamma$ Delta $\delta$ Epsilon $\epsilon$ Zeta $\zeta$ Eta $\eta$ Theta $\theta$ Iota $\iota$ Kappa $\kappa$ Lambda $\lambda$ Mu $\mu$ Nu $\nu$ Xi $\xi$ Omicron o...yes, just a lowercase O Pi $\pi$ Rho $\rho$ Sigma $\sigma$ Tau $\tau$ Upsilon $\upsilon$ Phi $\phi$ Chi $\chi$ Psi $\psi$ Omega $\omega$

Note: Capitalize the first letter of the letter name to get the upper-case letter. This only works for Gamma, Delta, Theta, Lambda, Xi, Pi, Sigma, Upsilon, Phi, Psi and Omega.

How to Look for Help With LaTeX

If you are running into errors when typesetting, check out the section on fixing bugs, and if that doesn't help, look at the "when things go wrong" section of this FAQ or, of course, come to us!

The fastest and easiest way to look for help with LaTeX is Google.com. Go to Google and search for LaTeX along with the specific problem or issue. If you are having a problem with graphic placement, search for " LaTeX graphic placement". The first page of hits will almost always solve your problem. If you have just forgotten how to do something, like a specific syntax, google is your best resource. Again, search using LaTeX and the package name or two words describing what the command does. Good luck!

Books Available for Reference From CUS

• Math Into LaTeX by George Gratzer - focuses on math users
• A Guide to LaTeX by Helmut Kopka and Patrick Daly
• The LaTeX Companion by Gossens, Mittelbach, & Samarin