0% found this document useful (0 votes)
29 views10 pages

Latex Tutorial

This document provides a brief introduction to using LaTeX, including how to structure a basic LaTeX file, add formatting to text, and include lists. It demonstrates various LaTeX commands for formatting text, inserting special characters, and creating enumerated lists.

Uploaded by

tame24m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Latex Tutorial

This document provides a brief introduction to using LaTeX, including how to structure a basic LaTeX file, add formatting to text, and include lists. It demonstrates various LaTeX commands for formatting text, inserting special characters, and creating enumerated lists.

Uploaded by

tame24m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

LATEX Mini-Tutorial

This is a very brief introduction to using the free LATEX typesetting system. It is assumed that you have installed
a typical LATEX system such as MiKTeX for Windows (available at http://miktex.org), though the general
ideas apply to any LATEX system for any operating system (e.g. TeX Live for Mac OS X or Linux, available at
http://tug.org/texlive/). More LATEX documentation can be found at http://www.tug.org/begin.html

Introduction
In LATEX, plain text files (called the source files) contain the commands that are used for producing a document
in a printable format, such as PDF or PostScript. In MiKTeX, these text files are typed into the TeXworks text
editor, then compiled into a PDF file by clicking the green arrow button in the main menubar. The PDF file is
displayed in a separate window. The LATEX files are typically given a .tex extension, for example myfile.tex. In this
case the resulting PDF file would be named myfile.pdf. A standard LATEX source file has the following structure:
\documentclass{...}

<some commands to load certain packages and set document settings>

\begin{document}

<main text of the document>

\end{document}

The first line of a LATEX source file is the \documentclass command, which is used as follows:
\documentclass[options]{name of class}

The [options] part is optional, though usually you end up using it. The {name of class} part is mandatory;
you must supply the name of the type of class of document you want. Some standard document classes are:
Class Description
article Short documents, e.g. reports, essays, papers.
exam Exams and quizzes.
letter Letters, either personal or business.
book Books, with chapters, sections, subsections, table of contents, etc.
For example, if you wanted to write a typical short document, using an 11 point font and the standard 8.5"×11"
US letter paper size, then the first line in your LATEX source file would be:
\documentclass[11pt,letterpaper]{article}

The section of your LATEX source file between the \documentclass command and the \begin{document}
command is called the preamble. This is where you can tell LATEXto load extra packages for more functionality
beyond the default. For example, the default page margins are fairly large, so you can load the geometry package
to make the horizontal margins (hmargin) and the vertical margins (vmargin) smaller, say, 1 inch each:
\usepackage[hmargin=1in,vmargin=1in]{geometry}

In general, packages are loaded with the following syntax:


\usepackage[options]{name of package}

If you exclude the optional [options] part, then LATEX will use the defaults for the package you load.

1
Simple Example
After loading any necessary packages in the preamble, you can start typing the text for the body of your document.
To do so, put your text between the \begin{document} and \end{document} commands. Here is an example of a
complete LATEX source file (save as hello.tex) which creates just one paragraph of text:

\documentclass[letterpaper,11pt]{article}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\begin{document}
Hello! This is my first \LaTeX{} document. I will learn more about this typesetting
system and write lots of math documents with it. Wish me luck!
\end{document}

The PDF document (hello.pdf) created by clicking the green arrow button in MiKTeX (or by compiling it with
the command pdflatex hello.tex in a DOS command window or Linux terminal) will look like this:

Hello! This is my first LATEX document. I will learn more about this typesetting system and
write lots of math documents with it. Wish me luck!

Notice that the first line of the paragraph is automatically indented. To suppress this indentation, use the
\noindent command (followed by a space) at the beginning of the paragraph. Notice also that in the source file
the first line of the paragraph ends at the word “typesetting,” but not in the PDF output file. This is because LATEX

2
treats a single newline (carriage return) and multiple spaces as a single space, and it will automatically wrap lines
for you. To force text on a new line, use the \\ command at the point where you want the current line to end:
This will be on line 1.\\This will be on line 2.

This produces the output:


This will be on line 1.
This will be on line 2.

Use blank lines (or the \par command) to start new paragraphs:
Hello! This is my first \LaTeX{} document. I will learn more about this typesetting
system and write lots of math documents with it. Wish me luck!

I now know how to start new paragraphs. This second paragraph is going to be fun!

This produces the output:

Hello! This is my first LATEX document. I will learn more about this typesetting system and
write lots of math documents with it. Wish me luck!
I now know how to start new paragraphs. This second paragraph is going to be fun!

Text Formatting
The following commands show how to change the appearance of text:
Appearance Command Example Output
Bold \textbf{. . .} \textbf{bold text} bold text
Italic \emph{. . .} \emph{italic text} italic text
Bold italic \textbf{\emph{. . .}} \textbf{\emph{bold italic text}} bold italic text
Underline \underline{. . .} \underline{underline text} underline text
Small caps \textsc{. . .} \textsc{small caps text} small caps text
Monospaced \texttt{. . .} \texttt{monospaced text} monospaced text
Sans serif \textsf{. . .} \textsf{sans serif text} sans serif text
Superscript \textsuperscript{. . .} a\textsuperscript{superscript} asuperscript
Tiny \tiny{. . .} \tiny{tiny text} tiny text

Superscript size \scriptsize{. . .} \scriptsize{superscript size text} superscript size text


Footnote size \footnotesize{. . .} \footnotesize{footnote size text} footnote size text
Small \small{. . .} \small{small text} small text
Normal size \normalsize{. . .} \normalsize{normal size text} normal size text
Large \large{. . .} \large{large text} large text
Larger \Large{. . .} \Large{larger text} larger text
Largest \LARGE{. . .} \LARGE{largest text} largest text
Huge \huge{. . .} \huge{huge text} huge text
Hugest \Huge{. . .} \Huge{hugest text} hugest text
Blue1 \textcolor{blue}{. . .} \textcolor{blue}{blue text} blue text
1
This requires loading the xcolor package in the preamble: \usepackage{xcolor}
You can of course use other colors, e.g. red, yellow, green, magenta, brown, etc. You can also define your own colors based on different
color models, e.g. RGB, CMYK, HTML. For more information see the xcolor package documentation at http://mirror.ctan.org/
macros/latex/contrib/xcolor/xcolor.pdf

3
Special Characters
There are some characters which have special meaning in LATEX, e.g. \. The table below shows how to use these
characters in normal text mode. To use the \symbol{. . .} commands for the last five characters in the table, you
need to load the fontenc package in the preamble with the T1 character encoding: \usepackage[T1]{fontenc}

Character Command Example Output


\ \textbackslash This is a backslash: \textbackslash This is a backslash: \
% \% This is 50\%. This is 50%.
$ \$ This is \$50. This is $50.
# \# This is \#50. This is #50.
& \& Abbott \& Costello Abbott & Costello
^ \symbol{94} This is a caret: \symbol{94} This is a caret: ^
~ \symbol{126} This is a tilde: \symbol{126} This is a tilde: ~
{ \symbol{123} This is a left brace: \symbol{123} This is a left brace: {
} \symbol{125} This is a right brace: \symbol{125} This is a right brace: }
_ \symbol{95} This is an underscore: \symbol{95} This is an underscore: _

Lists
Use the enumerate environment to create a numbered list. This starts with the \begin{enumerate} command,
followed by an \item command for each numbered item in the list, and ends with the \end{enumerate} command.
The example below on the left shows code for creating a list of 3 items, with the output shown on the right:

\begin{enumerate}
1. This is item 1.
\item This is item 1.
\item This is the second item. 2. This is the second item.
\item This is item 3.
\end{enumerate} 3. This is item 3.

Notice that you do not have to manually number the list items; LATEX does the numbering for you. You can
also create a sub-list within a list item by putting another enumerate environment inside that item. For example,
the code below on the left adds two parts, (a) and (b), to item 2 in our above list; the output is shown on the right:

\begin{enumerate}
\item This is item 1. 1. This is item 1.
\item This is the second item.
\begin{enumerate} 2. This is the second item.
\item This part will be easy. (a) This part will be easy.
\item This part will be hard!
(b) This part will be hard!
\end{enumerate}
\item This is item 3. 3. This is item 3.
\end{enumerate}

Notice that LATEX automatically knew to label the sub-items in item 2 with letters instead of numbers. You can
continue this nesting of enumerate environments within enumerate environments to produce sub-sub-lists, and so
on. If you were to start a new enumerate environment completely outside any previous enumerate environment,
then the list created by that new enumerate environment would have its numbering start back at 1. So, for example,
if you were creating an exam or quiz, you would typically have one main enumerate environment in your document
(with items numbered 1, 2, 3, etc), and any others would be inside that main enumerate environment. You would
use completely separate enumerate environments if, for example, you made an exam with multiple sections.

4
To create bullet (unnumbered) lists, use the itemize environment:

\begin{itemize} • This is the first bullet item.


\item This is the first bullet item.
\item This is the second bullet item. • This is the second bullet item.
\item This is bullet item 3.
• This is bullet item 3.
\end{itemize}

As with numbered lists, you can create sub-lists of bullet lists, in this case by nesting an itemize environment
within an itemize environment.

Tables
Use the tabular environment to create tables. In its most basic form, the format is shown below:
\begin{tabular}{column specifications}
row 1\\
row 2\\
...
row n-1\\
row n
\end{tabular}

The column specifications consist of a sequence of characters from among c, l, and r, one character for each
column in the table, which indicates how the text in that column is justified: c for centered, l for left-justified,
and r for right-justified.
The format for the rows is to separate the column entries by an ampersand (&) and terminate the row with a
double backslash (\\). For example, a basic table with 3 columns and 3 rows is shown below, with the first column
centered, the second column left-justified, and the third column right-justified:

\begin{tabular}{clr}
Column 1 & Column 2 & Column 3\\ Column 1 Column 2 Column 3
This & is & a row\\ This is a row
And this & will be & another row And this will be another row
\end{tabular}

By default there are no borders around the table or any lines to separate columns and rows. Vertical lines for the
columns are created by putting a vertical bar | in the desired positions in the column specifications, while horizontal
lines are created with the \hline command in the desired positions among the rows. The \hline command does
not need a terminating double backslash. For example, here is the above table with borders around the outside of
the table, a vertical line between columns 1 and 2, and horizontal lines between the rows:

\begin{tabular}{|c|lr|}
\hline
Column 1 & Column 2 & Column 3\\
\hline Column 1 Column 2 Column 3
This & is & a row\\ This is a row
\hline And this will be another row
And this & will be & another row\\
\hline
\end{tabular}

5
Spacing
Horizontal spaces of various sizes can be created with the following commands:
Command Example Output Command Example Output
\, |\,| || \enskip |\enskip| | |
\: |\:| || \quad |\quad| | |
\; |\;| || \qquad |\qquad| | |
~ |~| || \hspace{length } |\hspace{0.5in}| | |
The \hspace{length } command can be given lengths in different units, e.g. \hspace{1in}, \hspace{1.3cm},
\hspace{5mm}, \hspace{12pt} (72 pt equals 1 inch). It can also be given negative lengths to move backwards, e.g.
\hspace{-0.75in}. The maximum horizontal length on a page is called \textwidth.
Vertical spacing can be created with the \vspace{length } command, which can be placed at the end of
paragraphs and various environments (e.g. tables, lists). For example, in the list we created earlier, here is how to
put a 0.5 inch vertical space between items 1 and 2:

1. This is item 1.
\begin{enumerate}
\item This is item 1.\vspace{0.5in}
\item This is the second item.
\item This is item 3.
2. This is the second item.
\end{enumerate}
3. This is item 3.

To add vertical space below an entire environment, put your \vspace command after the \end{. . .} command
of the environment. For example, to add a 1 inch vertical space after an enumerate environment, you would use
\end{enumerate}\vspace{1in}. You can move upwards by using a negative length in the \vspace command. This
is helpful when you want to remove unwanted vertical space that was created automatically by some environment.
To add vertical space inside tables or other environments where rows are terminated by a double backslash, you
can use the [length ] command after the double backslash. For example, here is how you could add a 5 millimeter
vertical space between the second and third rows in our table example from before:

\begin{tabular}{clr} Column 1 Column 2 Column 3


Column 1 & Column 2 & Column 3\\ This is a row
This & is & a row\\[5mm]
And this & will be & another row And this will be another row
\end{tabular}

Boxes
Use the \fbox{text } command to put a framed box around a small amount of text (up to one line). To box
a paragraph of text, use the \parbox{width }{paragraph } command to put an invisible box width units wide
around the paragraph, then put that inside an \fbox. You can use the special length \textwidth for the width:

I’m going to box \fbox{this text} first.


I’m going to box this text first.
\fbox{\parbox{\textwidth}{This whole This whole paragraph will be boxed. This will make
paragraph will be boxed. This will make it it seem as if it is very important.
seem as if it is very important.}}

6
Positioning
To control the horizontal positioning of a fragment of text or of an environment (e.g. a table), you can enclose
the object within the following commands: \begin{flushleft} and \end{flushleft} for alignment on the left
margin; \begin{flushright} and \end{flushright} for alignment on the right margin; and \begin{center} and
\end{center} to center the object. For example:
\begin{center}
\Large{\textbf{Here is a centered title}} Here is a centered title
\end{center} This line is not centered.
This line is not centered.

Pagination
LATEX will automatically create new pages when needed. You can force a new page with the \newpage command
on a line by itself. You can disable page numbering with the \pagestyle{empty} command in the preamble.

Miscellaneous
Some extra symbols in normal text mode:
Symbol Command Example Output
fancy double quotes ‘‘text ’’ A ‘‘fancy quote’’ A “fancy quote”
accent acute \’{character } caf\’{e} café
accent grave \‘{character } tr\‘{e}s gauche très gauche
accent circumflex \^{character } L’H\^{o}pital’s Rule L’Hôpital’s Rule
umlaut \"{character } M\"{o}bius strip Möbius strip
cedilla \c{character } Fran\c{c}ois Truffaut François Truffaut
diacritical tilde \~{character } pi\~{n}ata piñata
cents2 \textcent 50\textcent 50¢
Examples of making horizontal lines of various lengths:
One inch line, 0.5 pts thick: \rule{1in}{0.5pt}

Same as above, 3 pts lower: One inch line, 0.5 pts thick:
\rule[-3pt]{1in}{0.5pt} Same as above, 3 pts lower:
Line to right margin:
Line to right margin: \hrulefill Put a line across the page:

Put a line across the page:\\


\hrule
You can import external graphics by putting the command \usepackage{graphicx} in the preamble and putting
the \includegraphics[scale=scale factor ]{file name } command in the document body where you want the
image to appear (scale factor is a ratio greater than 0). For example, suppose the image file oski.jpg is in the
same directory as your LATEX source file, and you want it to appear along the right margin at 85% its usual size:

\begin{flushright}
\includegraphics[scale=0.85]{oski.jpg}
\end{flushright}

2
Requires the textcomp package to be loaded in the preamble: \use{textcomp}

7
Mathematics
So far all the commands discussed are for LATEX’ normal text mode. Mathematical symbols and equations require
you to be in math mode. There are two ways to enter math mode:
1. Inline math: This is used when the mathematics is to appear in a paragraph with normal text. To use this,
enclose the mathematics between two dollar sign symbols ($...$) in a normal text paragraph.
2. Display math: This is used when the mathematics is to appear in a separate environment, not part of a
normal text paragraph. The most basic math environment is the displaymath environment. By default, the
various math environments are centered horizontally, apart from normal text paragraphs.
Here is an example of mathematics in both inline and display modes:
This is $x^2 =\frac{1}{4}$ in inline mode. This is x2 = 1
4 in inline mode. Here it is in display mode:
Here it is in display mode:
\begin{displaymath} 1
x2 =
x^2 = \frac{1}{4} 4
\end{displaymath}
The displaymath environment is built in to LATEX and requires no extra packages to be loaded. However, it is
likely that you will want to use some of the other math environments provided by the amsmath package, which we
will assume from now on you have loaded in the preamble:3 \usepackage{amsmath}
Here are some common math mode commands and symbols (enclose between dollar signs for inline mode):
Math Example Output Math Example Output
Addition a + b a+b Greater than or equal to a \ge b a≥b
Subtraction a - b a−b Less than or equal to a \le b a≤b
Multiplication a \times b a×b Implies P \Rightarrow Q P ⇒Q
Division a \div b a÷b Two-way implication P \Leftrightarrow Q P ⇔Q
Equality a = b a=b XN

Not equal a \ne b a 6= b Summation \sum_{n=1}^{N} a_n an


Greater than a > b a>b n=1

Less than a < b a<b Limit \lim_{x \to a} f(x) lim f (x)
x→a
a
Fraction \frac{a}{b}
b Derivative f’(x) f 0 (x)
Exponent a^b ab Second derivative f”(x) f 00 (x)
Subscript a_b ab Partial derivative \partial f ∂f

Square root a
Z
\sqrt{a}
Plus or minus \pm ± Indefinite integral \int f(x)~dx f (x) dx
Infinity ∞ b
Z
\infty
Degrees 45^{\circ} 45◦ Definite integral \int_{a}^{b} f(x)~dx f (x) dx
a
Angle \angle A 6 A ZZ
Triangle \triangle ABC 4ABC Double integral \iint\limits_R f~dA f dA
Parallel l \parallel m lkm R
Perpendicular l \perp m l⊥m
ZZZ
Intersection A \cap B A∩B Triple integral \iiint\limits_S f~dV f dV
Union A \cup B A∪B S
Subset
Z Z
A \subset B A⊂B
Multiple integral \idotsint\limits_V ···
Empty set \emptyset ∅
Equivalent y \equiv x y≡x I
V

Approximately y \approx x y≈x Line integral \oint_C f~ds f ds


Similar y \sim x y∼x C

3
Use \usepackage[fleqn]{amsmath} to make the math environments left-aligned instead of centered.

8
The above list barely scratches the surface of the math symbols available in LATEX.4 There are also commands
for some common math functions, operators, and Greek letters in math mode:

Command Output Command Output Command Output Command Output


\sin x sin x \log x log x \alpha α \mu µ
\cos x cos x \ln x ln x \beta β \pi π
\tan x tan x \log_b x logb x \gamma γ \rho ρ
\csc x csc x \dot{x} ẋ \Gamma Γ \sigma σ
\sec x sec x \ddot{x} ẍ \delta δ \Sigma Σ
\cot x cot x \bar{x} x̄ \Delta ∆ \tau τ
\arcsin x arcsin x \tilde{x} x̃ \epsilon  \phi φ
\arccos x arccos x \hat{x} x̂ \zeta ζ \Phi Φ
\arctan x arctan x vec{v} \cdot vec{w} ~v · w
~ \eta η \chi χ
\sinh x sinh x \overline{AB} AB \theta θ \psi ψ
\cosh x cosh x −−→ \kappa κ \omega ω
\overrightarrow{AB} AB
\tanh x tanh x \nabla ∇ \lambda λ \Omega Ω

Normal text in math mode is italicized and spaces are ignored. You can use ~ for spacing in math mode, or
(preferably) use the \text{some text } command. Compare how text appears in text mode and in math mode:

Bad: sin x is a function\\ Bad: sin x is a function


Terrible: $sin x is a function$\\ Terrible: sinxisaf unction
Good: $\sin x ~\text{is a function}$\\ Good: sin x is a function
Good: $\sin x$ is a function Good: sin x is a function

You may have noticed in the first math example on the previous page that fractions appear larger in display
math mode than in inline math mode. The same is true for math symbols such as \sum, \lim, and \int. You can
force display math mode sizes for those symbols in inline math mode by using \dfrac instead of \frac, and by
preceding the other symbols by \displaystyle, as the following inline math example shows:

dy dy
Fraction: dx =
dx

Fraction: $\frac{dy}{dx} = \dfrac{dy}{dx}$\\ P∞ X
Sum: n=1 =
Sum: $\sum_{n=1}^{\infty} = \displaystyle\sum_{n=1}^{\infty}$\\
n=1
Limit: $\lim_{n \to \infty} = \displaystyle\lim_{n \to \infty}$\\ Limit: limn→∞ = lim
Integral: $\int_a^b = \displaystyle\int_a^b$ Z b n→∞
Rb
Integral: a =
a

Here is an example of creating matrices and determinants:

\begin{displaymath}
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix},~    
1 2 5 6 1 2
B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix},~ A= , B= , |A| =
3 4 7 8 3 4
|A| = \begin{vmatrix} 1 & 2 \\ 3 & 4 \end{vmatrix}
\end{displaymath}

Delimiters such as parentheses, braces, brackets and vertical bars are not automatically sized to fit their contents
1
(e.g. the parentheses in ( ) do not fit the enclosed fraction). To fix this, use the \left and \right commands:
2
4
See The Comprehensive LATEX Symbol List: http://ctan.org/tex-archive/info/symbols/comprehensive/symbols-letter.pdf

9
\begin{displaymath}
\left( \frac{1}{2} \right) ,~   n
1 o Z Z 
∂f
\left\lbrace e^{x^2 + y^2} \right\rbrace ,~ x2 +y 2
, e , f dS ,
\left\lbrack \iint f~dS \right\rbrack ,~ 2 ∂x
\left| \frac{\partial f}{\partial x} \right|
\end{displaymath}

The displaymath environment can display only a single line. The amsmath package provides several multiline
math environments, such as the align* environment,5 which aligns multiple lines (each terminated by a double
backslash) at an anchor, which is preceded by an ampersand. The align environment does the same and labels
each line with a number. The example below uses align* and align, each with lines aligned at an equals sign:

\begin{align*}
f(x) &= e^{x-1}\\ f (x) = ex−1
\int_1^2 f(x)\;dx &= e^{x-1} ~\Bigr|_1^2\\
Z 2 2
&= e - 1 f (x) dx = ex−1
1 1
\end{align*} =e−1
%This is a comment and will be ignored
\begin{align}
2x - 4y - 7z + 8w &= \pi\\ 2x − 4y − 7z + 8w = π (1)
3x + 5y + 9z &= 213 3x + 5y + 9z = 213 (2)
\end{align}

Finally, here is a full example of a math quiz (save as mathquiz.tex then compile it into a PDF). Good luck!

\documentclass[letterpaper,11pt]{article}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage{amsmath}
\pagestyle{empty}
\begin{document}
Math Quiz \hspace{1in} Name: \hrulefill
\begin{enumerate}
\item Suppose that $ax^2 + bx + c = 0$. Show that
\begin{displaymath}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} ~.
\end{displaymath}\vspace{0.75in}
\item Solve the following system of equations:
\begin{align*}
2x - 4y ~&=~ \sum_{n=0}^1 \ln \left( e^3 \right)\\
3x + 5y ~&=~ \int_0^1 2x\;dx ~+~ \lim_{x \to -\infty} \frac{\sin x}{\sqrt[3]{x}}
\end{align*}\vspace{2in}
\item Draw a right triangle $\triangle ABC$ with $C = 90^{\circ}$.\vspace{1in}
\item Answer the following questions about the function $f(\theta) = \cos \theta$:
\begin{enumerate}
\item What is $f’(\theta)$?\vspace{0.75in}
\item What is $\lim_{\theta \to 0} f(\theta)$?
\end{enumerate}
\end{enumerate}
\end{document}

5
A good discussion of other such environments is at http://mirror.ctan.org/info/math/voss/mathmode/Mathmode.pdf

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy