Chapter 2 Simple LaTeX Documents

Let’s start by creating a simple LaTeX document.

2.1 A very short document

Open up your favourite text editor1, enter the following text, then save it as a file called turing.tex:

\documentclass[a4paper]{article}
\begin{document}
Computational excursions
\end{document}

To turn this into a pdf we need to use a LaTeX compiler, we’re going to use pdflatex, though several other compilers are available.2 On Linux the pdflatex compiler is already installed and can be used from the command line.3 If you’re not using Linux, you’ll need to explore the options at latex-project.org/get.

# compile turing.tex
pdflatex turing.tex
# open the pdf output
xdg-open turing.pdf
# or just open turing.pdf on a mac

The first command outputs a pdf file from your turing.tex input using the pdflatex compiler. The second command opens the file you’ve created. If you list the directory contents, you’ll see that the compiler has also created an auxillary *.aux file and a *.log file which can be helpful when you’re debugging the compilation:

# files created on compilation
turing.tex
turing.pdf
turing.aux
turing.log

2.2 A longer LaTeX document

Our turing.tex file is a very simple document, so let’s add some sections and fill them out a bit:

\documentclass[a4paper]{article}
\begin{document}


\section{Algorithms: Cooking Up Programs}
A program specifies in the \textbf{exact syntax} of some programming language the computation one expects a computer to perform. The syntax is precise and unforgiving. The slightest error in the program as written may cause the computation to be in error or may halt altogether. The reason for this situation seems paradoxical on the surface: It is relatively easy to design a system that converts rigid syntax to computations; it is much harder to design a system that tolerates mistakes or accepts a broader range of program descriptions.

\section{Finite automata: The Black Box}
It occasionally happens in industrial, military or educational settings that one is presented with a piece of electronic hardware whose exact function is uncertain or unknown. One way of discovering how the device works is to take it apart, piece by piece, and deduce its function by analysing the components and their interconnections. This is not always possible, however, nor is it always necessary. Given that the mystery machine has both input and output facilities, it may be possible to discover what it does without ever taking it apart. Since its appearance gives no clue about its function, we call it a \textit{black box}.

\section{Systems of Logic: Boolean Bases}
In an age of computers and automation, almost every electronic device one can name incorporates at least one boolean function. For example, many current models of automobile will emit a high-pitched whine, buzz or other disturbing noise until their drivers fasten their seat belts. Such a device realises a boolean function of two variables.

\section{Simulation: The Monte Carlo method}
In the quest to understand the many systems that comprise the modern world we turn increasingly to computer simulation. Whether the system is natural or artificial, frequently one or more of its components have such complex behaviour that the only feasible approach to approximating such behaviour is to assume that it is random.

\section{Gödel's Theorem: Limits on Logic}
In the early 1930's, Kurt Gödel, a German mathematician, attempted to show that predicate calculus was complete - that one can obtain mechanically  (in principle, at least) a proof of any true formula expressed in that calculus. His failure to do this was crowned by the discovery that the task was impossible.

\section{Can machines think?}
Turing addressed the question ``Can machines think?'' in his 1950 paper \textit{Computing machinery and intelligence}.

\section{But what is LaTeX good for?}
We're using this \LaTeX\ document to demonstrate some of its key strengths that you will find useful during and after University:

\begin{enumerate}
\item LaTeX can quickly create pdf files
\item LaTeX uses professional typesetting
\item LaTeX documents can be more legible, clear, and visually appealing to the reader than those created with word processing software
\end{enumerate}

\end{document}

The text here is excerpted from The New Turing Omnibus: 66 excursions in Computer Science (Dewdney 2001). The Omnibus is a lovely introduction to the fundamentals of Computer Science that you might enjoy. In his book review, the software engineer Jeff Atwood calls the omnibus an “incredibly fun little book”. (Atwood 2007)

2.3 Exercise one: documentum

In your file turing.tex either cut-and-paste this longer text into your document or make your own sections and text. You could use text from Lorem ipsum at lipsum.com to fill out the page.

Now, at the top of your document after the \begin{document} line and before first \section, add the following commands, each on their own line:

\title{The New Turing Omnibus}
\author{A. K. Dewdney}
\maketitle
\tableofcontents
\newpage

The title, author, tableofcontents and newpage commands are self-explanatory. The maketitle automatically inserts today’s date. Your table of contents won’t be created until you run pdflatex twice because on the first run, LaTeX gathers and stores information about what to put in the table of contents, and only creates it on the second run.

# remember to run pdflatex twice for the table of contents
pdlfatex turing.tex
pdflatex turing.tex

2.4 Bold, italic and lists

Here’s a few points to note about the text above:

  • Notice how bold and italic formatting are created using \textbf{} and \textit{}
  • Notice how lists are created with \items inside either \begin{enumerate} for numbered lists or \begin{itemize} for bulleted lists.

2.5 Quotation marks

Typographic or “curly” quotation marks are different characters and not the same as straight quotes. They look nicer, but you have to remember that unlike straight quotes, open and close quotation marks are different characters:

  • open quote which looks a bit like a miniature 66
  • close quote which looks a bit like a miniature 99

Look carefully at the quotation marks in the text below:

  • Turing addressed the question “Can machines think“… ❎
  • Turing addressed the question “Can machines think”… ✅

In your *.tex file the correct version looks like this

Turing addressed the question ``Can machines think''

not

Turing addressed the question ``Can machines think``

or

Turing addressed the question ''Can machines think''

The difference is subtle in most web browsers, but it’s really noticeable in print and pdf so worth paying attention to.

2.6 Summary

You’ve created a basic document in LaTeX and we’ve introduced some of its advantages:

  • LaTeX can quickly create pdf files
  • LaTeX uses professional typesetting
  • LaTeX can create pdf files that look better than those created with conventional word processing software packages

Next we’ll look at adding some cross-references, figures and citations. This is one thing that LaTeX does much better than your average word processing software which makes it great for editing larger and longer documents, such as your Bachelors, Masters or PhD thesis.

References

Atwood, Jeff. 2007. Practicing the Fundamentals: The New Turing Omnibus.” codinghorror.com. https://blog.codinghorror.com/practicing-the-fundamentals-the-new-turing-omnibus/.
Dewdney, A. K. 2001. The New Turing Omnibus: 66 Excursions in Computer Science. New York: Henry Holt. https://en.wikipedia.org/wiki/Special:BookSources?isbn=978-0805071665.

  1. it is worth configuring your editor so that it is LaTeX aware, and can do syntax highlighting, suggest auto-completions and spell-check for you. Tools like VS Code and sublimetext and many others will do this for you↩︎

  2. https://www.overleaf.com/learn/latex/Choosing_a_LaTeX_Compiler↩︎

  3. for example the Linux VM image for VirtualBox https://wiki.cs.manchester.ac.uk/index.php/CSImage_VM↩︎