This tutorial is for those who have gone through the first tutorial. Here we will cover new lines and paragraphs, comments, font decoration (bold, italic and underline) and sections. Fun.


New lines and paragraphs

First we will look at paragraphs. In LaTeX, having a new line in your .tex file (which we will refer to as the source code from now on) does not necessarily mean that a new line will appear in your compiled document. This may seem a bit strange to most beginners, but it allows you to format you source code to make it more readable without affecting the resulting document. The advantages of this will become apparent when you start working with big documents.

So how do we tell LaTeX to put stuff on a new line? This can be done using two backslashes (ie: \\). To signal the end of a paragraph, we can place an empty line between the first and second paragraph in the souce code (this will start the second paragraph directly under the first) or put a double slash at the end of the first paragraph AND leave an empty line between the paragraphs in the source code. Confusing? Let’s look at an example then.

\documentclass[11pt,a4paper]{article}
\begin{document}
1. There are three types of people.\\
Those who learn by reading,\\
those who learn by observation\\
and those who need to touch the fire to see if it really is hot.

2. The best contraceptive for old people is nudity.\\

3. Stealing from one source is plagiarism. Stealing from multiple sources is research.
\end{document}

This code will produce the following document (the PDF produced can be downloaded from here):

    1. There are three types of people.
Those who learn by reading,
those who learn by observation
and those who need to touch the fire to see if it really is hot.
    2. The best contraceptive for old people is nudity.

    3. Stealing from one source is plagiarism. Stealing from multiple sources is
research.

From this you can see the differences in line breaks. New paragraphs are indented by default (see this post for how to remove this). Keep this in mind when writing your documents.


Comments

Like any other programming or markup language, LaTeX source code can contain comments. A comment is text that the compiler ignores when generating the document. A comment is any text on a line which has a percent sign (%) before it.

For example, in the code below all text in grey is a comment:

% this text is a comment
\documentclass[11pt,a4paper]{article} % this is a comment too

Comments are used for adding notes to the source to explain what code is doing, for leaving notes for other developers and that sort of thing.


Font Decorations

Any text in LaTeX can be made bold, italic, underline or any combination of the three.

To make text bold, surround the text in \textbf{...}.

To make text italic, surround the text in \emph{...}.

To underline the text, surround the text in \underline{...}.

These tags can be used with one another. For example:

Text in LaTeX can be \textbf{bold}, \emph{italic}, \underline{underline} or any combination such as \emph{\textbf{bold and italic}}.


Sections

LaTeX articles can be organized into sections, sub-sections and sub-sub-sections via the \section{section name}, \subsection{sub-section name} and \subsubsection{sub-sub-section name} tags, respectively. You don’t have to number the sections manually – LaTeX will do this for you. If you want to add an un-numbered section, use the \section*{section name}, \subsection*{sub-section name} and \subsubsection*{sub-sub-section} tags.

For example:

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


\section{The first section}
This text is in section 1


\subsection{The first sub-section}
This text is in section 1.1


\section{The second section}
This text is in section 2


\subsection{Another sub section}
This text is in section 2.1


\subsubsection{A sub-sub-section}

This text is in section 2.1.1
\subsubsection{Another sub-sub-section}
This text is in section 2.1.2


\section*{Another section?}
This section does not have a number


\end{document}

Will produce the following (view the actual document here):

1 The first section
This text is in section 1
1.1 The first sub-section
This text is in section 1.1

2 The second section
This text is in section 2
2.1 Another sub section
This text is in section 2.1
2.1.1 A sub-sub-section
This text is in section 2.1.1
2.1.2 Another sub-sub-section
This text is in section 2.1.2

Another section?
This section does not have a number