A LaTeX Course for UoA Students
A HTML version Instructor: Theo J. Mertzimekis
Home > First Steps
Main menu
» First Steps
» Basic Commands
» Math equations
» Thesis template
» Bibliography
» Examples
» Useful Links

 

University of Athens

Questions? Comments?
 
First steps

Once MikTeX is installed on your systems, pop up your text editor, Texmaker. We will create our first document in LaTeX. Typically, the first document to test our new system is to write "Hello World". For that we will need to define the document style that we want to produce. LaTeX has many document styles, but the most common ones are article, report, letter and book. For UoA students we will use report, but for our little test, the first line in our document will use the article class:

\documentclass[12pt,a4paper]{article}

This line also defines the font size, which is set to 12pt and the paper size of the output document, set to A4. The square brackets in front of the class definition contained in {...} are used to provide attributes to a command, here the article class. The actual document begins by explicitly stating that:

\documentclass[12pt,a4paper]{article}

\begin{document}

The text we would like to include ("Hello World"l) is typed next and the document ends with a proper command:

\documentclass[12pt,a4paper]{article}

\begin{document}
Hello World
\end{document}

Next, you save the document (let's use the name hello.tex) and it is time to put LaTeX into work. Texmaker has a built-in menu that compiles the document. For the time being, we will use PDFlatex, and not XeTeX. After some processing depending on the power of your laptop, a PDF file is produced, hello.pdf. Check that PDF has been produced ok. See the above example here [TeX][PDF].


Page numbers

Notice that at the bottom of the page, the page number is also produced. If you would to hide it for this page only, you may add the command:

\thispagestyle{empty}

just before "Hello World". See the example here [TeX][PDF]. You can hide the numbers from all pages by putting the command in the preamble (the part of the document before \begin{document}) with this command:

\pagestyle{empty}

The final output is here [TeX][PDF], but you won't be able to see it clearly until you produce a document spanning several pages


Spaces, linebreaks, new pages

One of the nice features of LaTeX is line justification does not depend on how many spaces you include between words. Typing two or more spaces does not matter; it always count as one. There are ways to increase blank space between words, but we skip this lesson for now. An empty line in the source file signifies a new paragraph.

A line break occurs when you type \\ at the point you need to break. Try for example:

\documentclass[12pt,a4paper]{article}

\begin{document}
Hello World\\
Hello World\\
Hello World
\end{document}

We can also set the spacing between the lines after the break explicitly. If e.g. we need to leave 3mm after the break we can write: Hello World\\[3mm]. See here: [TeX][PDF]. You will notice immediately that the first line is indented. This happens automatically for the first line of each paragraph, except when a section starts; the first paragraph is not indented. We may cancel the indentation by writing:

\documentclass[12pt,a4paper]{article}

\begin{document}
\noindent Hello World\\
Hello World\\
Hello World
\end{document}

see here: [TeX][PDF].

A new page can be created by inducing a pagebreak:

\documentclass[12pt,a4paper]{article}

\begin{document}
\noindent Hello World\\
Hello World\\
\newpage
Hello World
\end{document}

see here: [TeX][PDF]. This time we need to run LaTeX twice to produce the correct output. (run LaTeX and then run it again!). The reason is that LaTeX needs to run an intermediate step to count pages correctly before producing the final document. This is something very common as we will see later on. A couple more remarks: (a) there is an indentation of the first paragraph in the second page (b) page numbers are produced correctly.


End remarks

The above simple example has exhibited some of the basic features of LaTeX. In the next lessons we will continue with a description of the essential commands and styles our UoA students will need during their thesis writing. The Hello World example is the mere beginining of a wonderful journey in LaTeX world.