This lesson is being piloted (Beta version)

Running LaTeX

Overview

Teaching: 10 min
Exercises: 5 min
Questions
  • how do we build a LaTex document?

  • What are the common editors for LaTeX?

Objectives
  • Explain that LaTeX is compiled

  • Introduce TexStudio and Overleaf editors

Setting up LaTeX

Running LaTeX from the command line

LaTeX code has to be ‘compiled’ to convert it from the LaTeX language into a PDF file which can be easily viewed, distributed or printed. One method for doing this is to run the command pdflatex from the command line and tell it which LaTeX file we want to compile. Providing there are no errors this will convert the LaTeX into a PDF file.

Download the example file helloworld.tex.

Or type out the code in your favourite text editor and save it as helloworld.tex

\documentclass{article}
\begin{document}
\title{Hello World}
\author{Jane Doe}
\maketitle
\end{document}
pdflatex helloworld.tex

This should produce some output like:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./helloworld.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 7 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./helloworld.aux)
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./helloworld.aux) )</us
r/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share
/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texliv
e/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb>
Output written on helloworld.pdf (1 page, 26419 bytes).
Transcript written on helloworld.log.

It should also create a file called helloworld.pdf in the same directory which you can open in a PDF viewer such as Adobe Acrobat. It will also create some other temporary files called helloworld.aux and helloworld.log. These can be deleted afer you’ve compiled your document.

Running LaTeX from TeXstudio

Now we’ll paste the same code we used above into TeXstudio, then save the document and press the green button that looks like a play symbol with a tail on it or press the ‘F5’ key or click on the “Tools” menu and choose “Build and View”. The icon to build and display in TeXStudio

TeXStudio showing the preview

Building a PDF with TeXstudio

Instead of previewing inside TeXstudio we can also build a PDF file by clicking on the green Play button, pressing ‘F6’ or choosing ‘Compile’ from the Tools menu.

Running LaTeX from Overleaf

Overleaf Screenshot

Compiling a document yourself

Pick one of the methods shown above (a simple text editor, TeXStudio or Overleaf) and do the following:

  1. Paste in the hello world document above.
  2. Change the author to your own name.
  3. Compile the code to make a PDF file and open it in a PDF viewer.

Key Points

  • LaTeX is compiled by running the pdflatex command

  • There are lots of editors which include a button to run pdflatex

  • Some editors like Overleaf include a preview of your document