My third LaTeX document

Posted: 30th August 2010 by Tim in LaTeX
Tags: , , , , , , , , , , , , , , , , ,

This tutorial is for those who have gone through the first and second LaTeX tutorials, and should give you the knowledge required to understand more specific LaTeX tips both on this site and on other websites. This tutorial will cover Packages and the basics of math mode.

Packages

Much like in programming, additional functionality can be added to LaTeX though the use of packages. Using packages may change the way the document looks (fonts, page orientation, etc) or make additional calls available to the user. Think of them as add-ons. Packages are included with the \usepackage{package-name} call.

I will illustrate this with an example. Let’s say that we wanted the document to be rendered in Times New Roman, and we want web addresses (URLs) to be displayed differently and for them to be clickable. A fairly common request. This can be achieved by including three packages; url, hyperref and times. url will provide you with a new command, \url{insert url here}, which makes the web addresses appear differently from the rest of the text. hyperref will make these URLs (and any other references within the document) clickable and times will change the font to Times New Roman. You can include the packages separately:

\usepackage{hyperref} \usepackage{times} \usepackage{url}

or in one line:

\usepackage{hyperref, times, url}

I personally prefer to include the packages individually, in alphabetical order, to make the code easier to work with.

From here, simply put any web address in a \url{} tag to make it a link. For example:

\documentclass{article} \usepackage{url} \usepackage{times} \usepackage{hyperref}

\begin{document} This font is in Times New Roman. To see how to change it to other fonts, see \url{http://timmurphy.org/2009/07/28/changing-fonts-in-latex/}. \end{document}

will produce this document

Math Mode

Possibly the most common reasons for using LaTeX over, say, Microsoft Word is the math mode. LaTeX has the ability to draw mathematical symbols and fractions within the document without too much messing around. All the math stuff needs to be defined within the math mode. This mode may be defined in the following ways:

$x = 1$ will place x = 1 inline with the rest of the text.
$$x = 1$$ or $x = 1$ will place x = 1 on a new line, centered.
$$x = 1$$ will also place x = 1 centered and numbered, on a new line, with the advantage of being able to be referenced. See this post to learn more about referencing.

Within the math mode, certain math commands can be used. For example, \frac{numerator}{denominator} will produce a fraction. There are way too many math commands available to mention here, but some of the most common are the summation symbol and integrals and limits. If you’re looking for a particular math symbol, google is your friend.

For example,

\documentclass{article} \begin{document} Math mode may inline, such as $1\frac{1}{2} = \frac{3}{2}$ or on a separate line such as: $$1\frac{1}{2} = \frac{3}{2}$$ $1\frac{1}{2} = \frac{3}{2}$ 1\frac{1}{2} = \frac{3}{2} \end{document}

will produce this document

This information, together with the first two tutorials, should give you enough background to understand the way LaTeX works and to go on to create your own documents. If you don’t know how to do something in LaTeX then do a google search – there’s probably someone out there who has explained how. If you can put it on paper, you can LaTeX it.