### LaTeX: the first document

Posted by: maria | in LaTeX | 2 years ago | 0 comments

So let's start! You need a basic tutorial to get your hands a bit dirty with LaTeX but you don't know where to start? I'm here for you.

# Install LaTeX

Well that's easy enough! If you're under Debian or one of it's derived distribution you just have to type:

sudo apt install texlive-full

and wait quite some time ;)

If you really want to install an IDE specialized in LaTeX:

sudo apt install texmaker

I've been told there's another editor for LaTeX TexStudio that's way better but I haven't tried it (and I don't use TeXmaker either).

# Document types in LaTeX

There is a multitude of document types available in LaTeX, here are some of the most famous:

• the article class, which is the base one. It is used for scientific articles, reports, software documentation, and in general for a lot of things,
• the report class, which is used for long reports containing chapters, thesis, …
• the beamer class, which is used for presentations,
• the tikzposter class, which is used for posters,
• the lettre class, which is used for letters,
• the book class, which is used you know… for books.

I will mainly focus on the article throughout the articles.

# Let's get practical!

## Hello World!

In TeXMaker, click on the icon for a new document and please write:

\documentclass[paper=a4, fontsize=11pt, ]{article}\begin{document}Hello world!\end{document}

What did we just do? We just told LaTeX to work with the class article, with A4 paper and with a fontsize of 11pt.

Then we have the tags \begin{document} and \end{document}, and between those we write the document, here the string "Hello world!".

Thereafter, we will call preamble the part between the \documentclass and the \begin{document}.

Now you can save your document and click on "Run" and select "PDFLaTeX" which is the name of the compiler we're gonna use. You can then click on the small blue arrow to compile your first LaTeX document and then click on the blue arrow next to "View PDF".

## What about an author, a date and a title?

Sure thing! We're gonna use the following commands: \author, \date and \title.

\author{Maria Climent-Pommeret}\title{My first document \LaTeX}\date{\today}

We use the command \today that puts the date of the day of compilation which might come in handy and the command \LaTeX that pretty-prints LaTeX.

Please put this in your preamble and compile again. Do you notice any difference?

No, because we didn't tell LaTeX to display the title… How do we do this? By putting:

\maketitle

in the body of the document (that is, right after the \begin{document} tag).

## But the date isn't displayed in my language!

Damn. You're not writing in English. Well we have to tell LaTeX that you're not writing in english then… I'll take the French example.

We have to add a new command to the preamble: one that makes it use the package babel with the french option:

\usepackage[frenchb]{babel}

Re run the compilation et display again your PDF, everything should be in place by now: the date will be written in your language.

Did everything run smoothly? No, it did not. Damn.

Warning: OT1 encoding should not be used for French

You'll get your fair share of LaTeX warnings and will soon learn to ignore some of them, but you can't possibly ignore this one. Why you might ask? Well try replacing your "Hello World!" by the french holoalphabetic sentence "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis." and take a look at your PDF.

### Quick to the preamble!

Yup, well spotted, we have to add some new things to our preamble. In fact, I'm gonna make you add a couple of things so that everything will run smoothly from now on.

Since you've probably guessed, we'll have to add a tons of stuff in our preamble in order to make LaTeX do what we expect it of doing. Therefore, we're going to put some parts of our preamble in a separate document that we will be able to link when we will need to create a new document.

So please, copy/paste this block to a new file called preamble.tex that you will put in the same directory as your helloworld.tex :) You don't need to understand every bit of it, just know that the line correcting the warning is the fontenc one.


Note: if you use babel > 3.0 you have to invoke it that way:

\documentclass[french][…]\usepackage{babel}

### Changes in the body of the document

Now that we have a preamble.tex, we can include it in the body of the document, that will only contain the interesting part of the document: the real content.

\documentclass[paper=a4, fontsize=11pt,]{article}\input{preamble}\author{Alice Climent-Pommeret}\title{My first \LaTeX document}\date{\today}\begin{document}\maketitleVoix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.\lipsum\end{document}

Re run and display your PDF. Everything went as expected!

Note the use of the \input command that will become very handy as your documents grow: we will input some sections of the document to the main one, and, this way, hierarchize our content. Therefore, you would be able to comment out some chapters of your thesis, in order to compile only the chapters you're currently working on, decreasing the compilation time.

### A (very simple) front page

To get a very very simple front page for your document (I promise we'll get to the part where we get to create fancy front pages) you can add the command \clearpage right after \maketitle. By doing so, we're telling LaTeX to end the page, and start a new one with whatever is after the command.

\documentclass[paper=a4, fontsize=11pt,]{article}\input{preamble}\author{Alice Climent-Pommeret}\title{My first \LaTeX document}\date{\today}\begin{document}\maketitle\clearpageVoix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.\lipsum\end{document}

Alternatively, you can pass the option titlepage to you documentclass.

### Let's add some structure to the document!

There exists several levels of structuration in LaTeX. Let's focus on the ones that are available in the class we're currently using: article.

Here there are, from the biggest to the smallest:

• \part{Name of the part}
• \section{Name of the section}
• \subsection{Name of the sub-section}
• \subsubsection{Name of the sub-sub-section}
• \paragraph{Name of the paragraph}
• \subparagraph{Name of the sub-paragraph}

The granularity level is already quite impressive. Test them out to see how they are rendered in your document!

By the way, if you want an un-numbered structure element, you just have to put a * at the end of it's name: \part*{Un-numbered part}.

Structuring is fun and cool, but it's not very useful if we don't get a table of contents to navigate within the document.

You just have to add, after your \maketitle (or wherever, really, I just like to have my table of content right after the title) the following command:

\tableofcontents

I bet you're a bit disappointed ;) Where the hell are the paragraphs and sub-paragraphs?! Well that's just LaTeX… we need to tell it to display those. Let's put the following code in the preamble.tex and play a bit with the number between {}:

%----------------------------------------------------------------% Headers, footers, TOC, Appendix%----------------------------------------------------------------%-% Depth of the TOC\setcounter{tocdepth}{6}

Here you go ;)

Let's stop here for now, see you soon!

### New Comment

required

required (not published)

optional

RNA 2