TeX.fyi

Hi, this is a collection of small hints we've collected that help you master LaTeX.

1. Creating a document

To create a new document, you use \documentclass{article} at the very beginning of the document. Use \begin{document} to start contents and \end{document} to end the document.

\documentclass{article}

\begin{document}

\end{document}

2. Adding a title and author

To specify the title of the document, one can use \title{title of the document} and \author{name of the author} to set the author. To add a date, use \date{8th November 1986}. If you dont want to add a date, write \date{}, if you don't include the \date tag, LaTeX will use the todays date. These commands go before \begin{document}, the declaration \maketitle afterwards.

\title{This is the title}
\author{Firstname Lastname}

% \begin{document}
\maketitle
LaTeX

3. German Language

To make special features of the german language work, you have to include \usepackage[utf8]{inputenc} and \usepackage[ngerman]{babel} before the beginning of your document (This enables ä, ü, ö and ß, and the related capital letters).

% \documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

% \begin{document}

4. Comments

Comments are started with the % command and end with the line They are ignored when LaTeX renders your document, but help you, to add notes and additional information while writing.

While this text is visible,
% this text will later not be visible in your document
LaTeX

5. Paragraphs and linebreaks

To write text with LaTeX, you don't have to do anything special. If you want to start a new paragraph, use two line breaks (so there is one blank line inbetween). To start a new line, but not a new paragraph, use \\. You can use single linebreaks as much as you want, LaTeX will ignore them. Also, if you use tabs or spaces to indent some lines of your LaTeX, your file might be much more readable, as they are also ignored.

This is text you can write.
And this text will continue in the same line.

But here begins a new paragraph.
This line belong also to this new paragraph, but the text after this will be in a new line.\\
And here begins this new line.
LaTeX

6. Structuring your document with sections, subsections and paragraphs

To give your document a structure, you can use different levels of headings. In LaTeX, they are called \section{} and \paragraph{}. \section{} is the header of the highes order, after the title. In the braces you write the heading for your section, something like this \section{This is a top level heading}. The same one can do with \paragraph{This is a paragraph heading}, which gives a paragraph a heading. There are also other levels of headings, like \part{} and \subsection{}, which you can find below (in order of their level).

\part{This is a part}
  Best used, if you can split your document in to clearly distinguisable parts.

\section{This is a section}
  Best used for the highest level headings

\subsection{This is a subsection}
  One can use this as a smaller heading

\subsubsection{This is a subsubsection}
  Recommended to use only if necessary.

\paragraph{This is a paragragh}
  This is best used for giving paragraphs names.

\subparagraph{This is a subparagraph}
  Also not recommended to use.
LaTeX

7. Writing equations

If your document requires any kind of mathematical equations or formulas, LaTeX provides the package amsmath. This package is imported via and enables different styles of mathematical typesetting for your document.

If your want to be the formula to be in your text, you can use \( ... \), and write it inbetween. (How to write advanced mathematical formulas is covered in the next chapters) This type of inline math is mostly used for short definitions or descriptions.

Otherwise you can use \[ ... \] to write equations. This puts the equation in the center of a new line. This is especially helpful if you want to do some kind of transformation.

Let's take two variables \( a = 4 \) and \( b = 3 \)
and use the  Pythagorean theorem to calculate \( c \) by

\[ c^2 = a^2 + b^2 = 4^2 + 3^2 = 25 \]
LaTeX