Go to home page  

Writing a Simple LATEX Document

logo LaTeX source logo View 1 logo View 2 logo View 3 logo Whole example

Let's examine the contents of a simple LaTeX file which has been used as a first example in this tutorial. First we must take a quick look at LaTeX syntax.

LaTeX files usually have a .tex extension. They consist of plain text interspersed with some LaTeX commands. The word command may sound scary. But don't worry. When you are beginning to write a LaTeX document, you really do not need to learn a new programming language or hundreds of commands. Basically you begin so that you get a simple template like the sample file below. Then start writing your own text inside the sections. The body text of paragraphs is simply plain text. Eventually you will need to write some commands but those you can usually copy and paste from other documents or templates.

When you want something special to happen, you must write a LaTeX command. The commands begin with a backslash and most of them want also parameters, which are enclosed in curly braces after the command. For example, write \section{My First Heading} to begin a new section of text with heading "My First Heading".

The names of the commands are quite intuitive. For example, if you look at the sample file below, you can easily guess that \title is the title of the document, \begin{abstract} starts the abstract text, and so on.

A comment line begins with a percent symbol (%) and continues to the end of the line.

That's all you need to know about the syntax now.

LaTeX Source of Example 1

Note: Here we just want to analyse the commands and structure of a LaTeX file. That's why we have removed most of the text content of the paragraphs. You can get the same file with more text here.

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\title{Introduction to \LaTeX{}}
\author{Author's Name}

\maketitle

\begin{abstract}
The abstract text goes here.
\end{abstract}

\section{Introduction}
Here is the text of your introduction.

\begin{equation}
    \label{simple_equation}
    \alpha = \sqrt{ \beta }
\end{equation}

\subsection{Subsection Heading Here}
Write your subsection text here.

\begin{figure}
    \centering
    \includegraphics[width=3.0in]{myfigure}
    \caption{Simulation Results}
    \label{simulationfigure}
\end{figure}

\section{Conclusion}
Write your conclusion here.

\end{document}

If you have installed MiKTeX and WinEdt or TeXnicCenter (see help for installation), the LaTeX processing of the above document is very simple. Open the .tex file in your editor. Then depending on the editor do the following:

You will get a PDF document with all formatting and layout applied.

Changing the Formatting

One of the main advantages of LaTeX is that it takes care of formatting the document. The user can concentrate on creating the information content of the document and he doesn't need to bother about fonts, page breaks, placing of figures, etc.

The so called document class defines the formatting of the document. LaTeX provides many standard document classes but you can also use other styles. For example, conferences often provide their own document classes that you can download. Changing the formatting of your document is very easy. You just change one line of text that specifies the document class to be used. For example, a standard article style is selected using the line \documentclass{article}. Here are some examples of different styles and the result as a pdf:

PDF
\documentclass{article}
A basic article style.
PDF
\documentclass{report}
A basic report style.
PDF
\documentclass[journal]{IEEEtran}
IEEE's style for submitting journal manuscripts.
PDF
\documentclass{ActaOulu}
University of Oulu PhD thesis style.
PDF
\documentclass[global,twocolumn]{svjour}
Springer (formerly Kluwer) journal style.

If you are looking for the LaTeX style files we have used in these examples, you can find links to them on our Getting Help page.

Detailed Analysis of the Sample File

If you are interested in the details of the sample file, here you go:

\documentclass{article}
Specifies that we want to format our paper using a basic article style.
\usepackage{graphicx}
This is needed if we want to include figures. Packages are extensions of a basic LaTeX system and provide additional functionality. Packages are loaded using the \usepackage command.
\begin{document} ... \end{document}
The whole document is enclosed between these.
\title{Introduction to \LaTeX{}}
Here you write the title of the document. (The \LaTeX{} command prints the fancy LaTeX logo.)
\author{Author's Name}
Name of the author.
\maketitle
Tell LaTeX to print the title, author name, etc. here.
\begin{abstract} ... \end{abstract}
Write the abstract between these commands.
\section{Heading of the First Section}
Every section begins with this command. Write the heading of the section between the curly braces. Then after this command you can write the text of the section. When you want to start a new paragraph of text, write an empty line in the LaTeX source file.
\begin{equation}
  \label{simple_equation}
  \alpha = \sqrt{ \beta }
\end{equation}
These commands insert an equation. Greek symbols are simply called with their name by inserting a backslash in front of them. \sqrt creates a square root function. The \label command gives a logical name for the equation. It can be used when creating cross references.
\subsection{Subsection Heading Here}
Every subsection begins with this command. You can also create subsubsections. If the selected document style uses numbering for headings, sections will be automatically numbered in a hierarchical way. That is, sections get a number like "1", subsections "1.2", and subsubsections "1.2.4".
\begin{figure}
\centering
  \includegraphics[width=3.0in]{myfigure}
  \caption{Simulation Results}
  \label{simulationfigure}
\end{figure}
These lines insert an image file into the document. More about images can be found here. Anyway, the most important command is \includegraphics, which now inserts an image named myfigure.eps (LaTeX appends .eps extension by default) or myfigure.pdf (PdfLaTeX appends .pdf). Additionally the figure gets a caption "Simulation Results" using the \caption command.

1 If your document contains references and this is the first time you are compiling this document in TeXnicCenter, more than one LaTeX run is needed to get all references right: Click "Build current file". Wait until the processing is finished. Then click again "Build current file". And finally click "View output" to see the resulting PDF file. Later you can just click once "Build and view current file" and you see the PDF immediately.

Go to home page