## My first LaTeX document

Posted: 28th February 2010 by Tim in LaTeX, Ubuntu
Tags: , , , , , , , , , , ,

The learning curve for LaTeX documents can be a steep one. This step-by-step guide covers installing and setting up the LaTeX environment, and creating and compiling your first document so that you can read and distribute it.

##### Setting up the LaTeX environment

A few things need to be installed before we can start creating documents.

###### Linux Users

You will need to install a bunch of packages, all of which should be available from your distro’s repository system. I would recommend installing the following packages:

• texlive-latex-base
• texlive-latex-extra
• texlive-latex-recommended
• texlive-fonts-recommended
• texlive-fonts-extra

To install these in Ubuntu, enter the following in your command prompt:

sudo apt-get install texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-fonts-recommended texlive-fonts-extra

###### Mac Users:

Most of you are probably used to writing documents using Microsoft Word, Open Office or something similar. These environments give you a point-and-click method for creating the document. LaTeX is different. Much like HTML files, LaTeX documents are all written in plain text. There’s no bold button to make text bold. There’s no create table wizard to help you add tabular data. Everything about the document has to be described using keywords and tags.

To create you first document, open a text editor (notepad in Windows, gedit in a linux Gnome environment, kate in a linux KDE environment, TextMate (or similar) on the Mac, Vim or Emacs on a linux terminal… take your pick). Then, copy the following code into the document and save it as hello.tex (the code will be explained in a moment):

\documentclass[11pt, a4paper]{article} \begin{document} Hello World \end{document}

When this is done, open a command prompt (cmd in Windows, terminal or konsole in linux, iterm on the Mac) and navigate to the directory where you saved the file. From here type:

latex --output-format=pdf hello

This command tells the computer to turn your hello.tex document into a PDF file. There should now be a file called hello.pdf in that directory, which should look like this.

So what did all that gibberish in the hello.tex file mean? Let’s step through it one line at a time.

\documentclass[11pt, a4paper]{article}
This line must be the first command in the file. It sets up some basic document properties. 11pt is the size of the font on the page, and a4paper refers to the paper size of the document. article is the type of document – don’t worry about this setting for now.

\begin{document}
This indicates the start of the document contents. Everything between this and the \end{document} tag is considered part of the document.

Hello World
This is the actual document text.

\end{document}
This line indicates the end of the document. This is usually the last line in your tex file.

So there you have it, your first LaTeX document. If you’re feeling comfortable with everything in this tutorial then move on to My second LaTeX document which covers paragraphs, bold, italic and underlined text, code comments and sections.

1. Jenisha says:

excellent tuitorial.Worked well. Simple!