Advertisement
Productivity

The Beginner's Guide to Using TeX in OS X

by

TeX is a wonderful and very versatile typesetting system that can be used to write almost anything – from reports to letters and even more complicated documents such as books and posters. This tutorial will show you the basics of TeX – how it works and how you can create a nice, simple document with very little effort.


You Can Do It!

What scares people away from TeX is its learning curve. It's not as simple as just opening up a word processor such as Pages or Microsoft Word and tapping away. With TeX, you have to learn the various commands before you can start creating documents. This may sound a bit scary, but TeX is a lot simpler to learn than other programming languages and once you've used it for a while you'll soon pick it up really easy.


What is TeX?

I think it would be prudent to first give you a brief introduction of TeX and why it's so popular within certain circles. Basically, it is a typesetting language that was designed and developed (mostly) by Donald Knuth, a professor at Stanford University, back in the 1970s. His aim with TeX was to create a system so that documents would look the same across all computers and that the look of the documents wouldn't diminish with time.

TeX is used heavily in the academic and scientific world, mostly due to the standardized layout and look of documents (though this can be changed), as well as the fact that TeX renders mathematical formulas extremely well (one of its fortes). If anyone has had to write a long formula in, say, the Equation Editor of Microsoft Word, then they will know how fiddly it is.

Before we get started with our first TeX document, there are a couple of things you need to install on your Mac first.


Getting Started

In order to be able to write TeX documents on your Mac, you'll first need to download and install a distribution, which renders your documents. There are quite a few TeX distributions out there that work with OS X, but my personal recommendation would be MacTeX, which is specifically written for the Mac and supports pretty much all OS X versions (including Mountain Lion).

You can download MacTeX directly here (direct download link – the file is approximately 2.1 GB in size) or via the Torrent network. Once you've installed it (it'll pop up in a dedicated TeX folder in your applications) then run the TeX Live Utility, which will update your TeX distribution to the latest version.

If you've installed all the available updates in the TeX Live Utility, then you should be presented with this screen.
If you've installed all the available updates in the TeX Live Utility, then you should be presented with this screen.

Just like HTML, you can write TeX is virtually any text editor or word processing package. However, I would recommend a specific TeX editor as you often get a handy list of tools with them (such as auto-complete and error reporting, which flags up any errors in your TeX coding before the document is rendered). With MacTeX, you get a couple of free solutions (TeXworks, which I will use for this tutorial, and TeXShop). There are also other options out there, such as TeXstudio and the commercial Texpad offering, which I reviewed last year on Mac AppStorm. You can also write TeX in commercial code editors such as Sublime Text with the relevant syntax, but you will need to open any documents up in a TeX editor so that they can be rendered. For beginners, I would recommend a dedicated TeX editor as it makes learning to write in TeX a lot easier!

Once you've installed everything, then it's time to create your first TeX document!


Your first TeX document

Tip: I have uploaded the tutorial document so you can download and play around with it. Click here to download the raw document (in .tex format) or here for a PDF example.

Every TeX document starts by defining the document class. This sets the layout and formatting of your document. There are loads of different classes to choose from, but for a standard document the article class is a good one to choose. Therefore, start by typing:

\documentclass{article}

All TeX commands are preceded by a backslash (\) and defined within {curly brackets}. Unlike other programming languages, TeX commands usually are in plain English, so often it's clear what the command is meant to accomplish.

Starting the document

Now that we've defined the document class, it's time to start the document. Here, we type:

\begin{document}

Of course, you have to tell TeX where your document ends and this is done by the command \end{document}. Are you starting to see that TeX really isn't that difficult? I usually type these commands at the same time, with four lines in between them. You don't have to, but I find it helps immensely. If you're following this example, then type:

\begin{document}



\end{document}

All your TeX coding should lie in between these two commands.


Titles and Authors

Now that we've defined the document class and where the document starts and ends, we need to give our document a title and author. Type:

\title{My First TeX Document}
\author{James Cull}

\maketitle

So far, your coding should look like the following:

First Shot

Tip: Syntax colouring can make it a lot easier to spot individual TeX commands and functions. Most TeX editors have it on as default – if you're using TexWorks, then click on Format > Syntax Coloring > LaTeX to activate it!

When you render this (by clicking on the little play button), then it should look like this:

First Shot Rendered

If the document fails to render, then check the coding against my example. If you haven't included the command \maketitle, for example, then the document won't render as it will simply be empty (the command \maketitle actually places the title in the document, whereas the command \title simply defines it for the document).

Abstracts

If you want to write a little abstract for your document (if you are writing a report or academic paper, for example), then type it in after the \maketitle command:

\begin{abstract}
The abstract text for your document always goes after the title and before the main body of your document.
\end{abstract}

Sections and Subsections

Sections are defined by the command \section, with the section title again going in between two curly brackets, for example: \section{Introduction}. In our particular document class, article, sections are numbered (so the Introduction section would automatically be rendered as 1. Introduction). You can also create subsections (1.1, 1.2 and so on) and subsubsections (1.1.1, 1.1.2 and so on). The commands for these are \subsection{Subsection Title here} and subsubsection{Subsubsection Title here}.

All text for the individual sections goes straight underneath the section commands and unlike the abstract, you don't have to start every single one with the \begin and \end commands. For this tutorial, I'll create a couple of sample sections (the files above both contain some place filler text as well within each section) so you can see how they work:

\section{Introduction}
Your introduction text goes here.

\subsection{More Introduction}
You can write some more text here.

Body Text and Formatting

If you're not using sections, then you can simply start writing your main body text after the \maketitle command. Make sure you insert an empty line between paragraphs so that TeX knows when to start a new paragraph.

TeX supports text in bold and in italics through the \textbf and \textit commands. Remember to encase the text you would like in either bold or italics between the two curly brackets. So:

I would like to emphasise that \textbf{this} measure is unacceptable.

\textit{Microsoft Corporation} is one of the largest technology and software companies globally.

TeX also includes three default fonts, which can be seen in the example below:

TeX Fonts

Use the command \textsf{ } for text in the Sans Serif font and \texttt{ } for text in the Typewriter font. The coding for the image above is as follows:

\documentclass{article}

\begin{document}

This is an example of text in the default \textbf{Roman} font. 

\textsf{This is an example of text in the \textbf{Sans Serif} font.}

\texttt{This is an example of text in the \textbf{Typewriter} font.}

\end{document}

You can mix and match fonts within the same document without any problems – just make sure you watch out for the correct placement of the curly brackets (some TeX editors will do this for you automatically).

TeX also supports different font sizes through a variety of commands.

TeX Font Sizes

To create the document, I used the following:

\documentclass{article}

\begin{document}

This text is in the {\tiny{tiny}} font size. It corresponds to a text size of roughly 7 pt. 

This text is in the {\scriptsize{script size}} font size. It corresponds to a text size of roughly 8 pt. 

This text is in the {\footnotesize{footnote size}} font size. It corresponds to a text size of roughly 8.5 pt.

This text is in the {\small{small}} font size. It corresponds to a text size of roughly 9.3 pt.

This text is in the {\normalsize{normal size}} font size. It corresponds to a text size of roughly 10 pt.

This text is in the {\large{large}} font size. It corresponds to a text size of roughly 12 pt.

This text is in another {\Large{large}} font size. It corresponds to a text size of roughly 14 pt.

This text is in yet another {\LARGE{large}} font size. It corresponds to a text size of roughly 16 pt. 

This text is in the {\huge{huge}} font size. It corresponds to a text size of roughly 19 pt. 

This text is in another {\Huge{huge}} font size. It corresponds to a text size of roughly 23 pt. 

\end{document}

Note the use of a curly bracket before the \ command and the two curly brackets at the end. If you only use one set of curly brackets (like with other TeX commands), the entire sentence will be in that particular font size.


Lists

Lists are relatively easy in TeX and there are three basic types.

An itemized list uses simply bullet points for your items:

\begin{itemize}
    \item The first item of your list
    \item The second item of your list
    \item The third item of your list
\end{itemize}

An enumerated list uses the standard sequential numbering for your individual list items:

\begin{enumerate}
    \item The first item of your list
    \item The second item of your list
    \item The third item of your list
\end{enumerate}

A descriptive list uses specific labels for each item of your list (for example, a, b and so on). TeX will not automatically generate the numbering and each label must lie within the [ ] as in the example below:

\begin{description}
    \item[a)] The first item of your list
    \item[b)] The second item of your list
    \item[c)] The third item of your list
\end{description}

When rendered, this is how the three lists turn out:

TeX Lists

Finishing Up

And that's it for your first TeX document! Hopefully, this tutorial has provided you with enough information to start creating simple documents in TeX that look good. Given the sheer extent of TeX, we can't cover everything in this tutorial, but in later articles we'll have a look at more advanced features, such as mathematical formulas and working with images (which I purposely haven't touched upon in this tutorial as it is quite complicated).

Once again, please feel free to download and play around with the sample document for this tutorial (all the examples listed here are in it) as it's a good way to learn how to use TeX. Yes, it takes a bit of extra time to learn but the main reason to use TeX is that you get standardized and professional-looking documents which can be used in a wide variety of scenarios.

Related Posts
  • Computer Skills
    OS X
    Introducing Markdown on OS XMarkdown
    Markdown is a popular formatting syntax that lets you easily write plain text that can be converted into a number of other formats; mainly HTML. In this tutorial I will show you how to use the Markdown syntax on OS X.Read More…
  • Computer Skills
    App Training
    How to Write a Screenplay in Plain Text with FountainFountain logo
    Writing a screenplay is difficult enough on its own. There's no reason screenwriting software should make it more complex. Here's how to simply write your screenplay in plain text, using the new Fountain syntax.Read More…
  • Computer Skills
    App Training
    How To Create an MLA Template in Word and PagesPreview
    In this tutorial, I will show you how to make MLA style templates in Pages and Microsoft Word to eliminate the need to remember each and every style rule each time you write an MLA style paper. You'll only need to make the template once, and every time after that it'll only take a click to get your paper formatted correctly.Read More…
  • Web Design
    HTML/CSS
    Why I Choose Stylus (And You Should Too)Stylus thumb
    The world of front end web development has been steadily increasing its uptake of what we call "CSS Preprocessors", which extend the functionality of regular CSS. Arguably the two most well known, with the greatest user base, are LESS and Sass/SCSS. However there is a third preprocessor that hasn't received quite as much attention, and that's Stylus.Read More…
  • Web Design
    HTML/CSS
    Foundation's Sassy Styles ExplainedFoundation sass retina1
    In this tutorial we'll cover what can be done with the flexible Sass styles included in the Foundation framework. A lot of these offer a more customisable feature set than that of the CSS version, plus there are shortcuts which can be used to style items such as the top bar quickly and easily.Read More…
  • Web Design
    CMS
    Organizing Ghost Theme Files and FoldersGhost files retina
    This is the second part of our Ghost theme design tutorial series. Everything from here assumes you have a foundational understanding of Ghost. If not, before continuing please take the time to read Understanding Ghost: Stages of Design).Read More…