About instructions

Last actualisation 15. 10. 2020

The purpose of this tutorial is to explain the basics of LaTeX to a user with zero prior experience with TeX or other more complex software. Instructions try to be so that everyone really understands them, perhaps not too comprehensive. In the beginning, the reader is introduced to the necessary general basics of writing with LaTeX, and later the use for more specific purposes, such as writing mathematical texts, is outlined.

I expect you to pick up a mouse and keyboard while reading this manual, install LaTeX yourself, and try to create sample documents along with the instructions. For it is best learned through use.

Other tutorials in English can be found here, a list of symbols in LaTeX can be found here, or a search for symbols on Detexifywillhelp. Samples of what can be done with TeX can be found here, but also here.

Why is it worth learning LaTeX?

Installation

The X in the name TeX stands for the Greek letter chi and reads as Czech.

Let's start with the hardest thing for a TeX start-up -- installing it. I believe that once you install the TeX, you will be able to make a playful acquaintance with it, after which you can only use it for your service.

Technical details

In the installation, I calculate that you are using Windows 10, and that you have free 3GB or so of disk space (why so much is explained below).

In this manual, I show the basic workflow for working with TeX. Power-users may resort to the use of vim.

If you are using Linux, you can replace the installation steps with a single line to the terminal. For Ubuntu:


sudo apt-get install texlive-full && sudo apt-get install texmaker

For Arch Linux:


sudo pacman -S texlive-most texmaker

Programs needed

You can install so-called MikTeX instead of Texlive, and TeXworks instead of Texmaker. However, Texlive and Texmaker are the most solid I think (Miktex contains errors and Texmaker is clear and has a lot of functionality.) However, I have to admit that MikTeX installs on-the-fly packages, which is why it takes up less space on the computer.

LaTeX is, in a nutshell, a program to create pdf files. Pdf creates a LaTeX file based on the text file we give it, this text file has a distinctive .tex extension. The work at TeX is then done by writing the source code of our document in a text editor (we could also use a microsoft notepad, for example), which is then translated by LaTeX and received the required pdf.

So we need two things to do the job: a .tex file translation program and a text editor to create .tex files. Install Texlive, as editor back texmaker, for translation.

Texlive takes up about 3GB, as it contains all possible LaTeX extensions called packages, which often contain their own fonts or glyphs. Once installed, this program will remain on your hard drive, and you will never have to visibly interact with it again. Texmaker is the program in which you will move when planting documents.

First TeX Document

Preparing file

Go to your desktop or your favorite folder. Create a folder here with any name, say First_Document. For a single pdf file, you must have at least one .tex file in LaTeX, but also others that are automatically created when you compile it (like a .log file where you keep a record of how the compilation took place), so it's worth having all the files related to one document in one folder, and to do this you have the right First_Document folder.

Go to the First_Document folder (in the File Explorer) and create a .tex file here, like the first.tex. On Windows, you do this by first setting to show file extensions, then right-click, then click a new, then text document. You can then rename the file you just created using the F2 button or the menu resulting from the right mouse button click.

Open the file using Texmaker. Right click, open in program, select another program, check to use as default program, select Texmaker and ok will take care of this work, alternative you can open Texmaker and drag the file into it.

Something about how TeX works

You should now have an open Texmaker with an empty file as shown.

You can set the output and input windows to be really separate windows. This is particularly useful for small displays.



prázdný dokument otevřený v programu Texmaker

Texlive is a so-called backend program, while Texmaker is a so-called frontend program.

The left part of the programme is therefore used to write the code already mentioned, which is then translated into pdf. The resulting pdf appears on the right side of the program. But since we don't have a code yet, let's just write a simple sentence, like:


Ahoj světe!

We can try to translate a sentence using the Quick build or Quick Translation button, for which the program has an F1 shortcut. As you may have expected, the document did not translate successfully. Writing documents in LaTeX requires following certain rules, just like writing code in html or c++, for example. You may find it a little overwhelming to start with a LaTeX error message, however, watching these messages is an important part of working well with TeX. You may notice that the line is trying to tell you where you went wrong - on line 1. We also read that the formula \begin{document} is missing, which we can then add.



chybová hláška v Texmakeru

However, before I complete the necessary formalities, note that the first.log file was generated in our First_Document folder. This file contains everything Texlive deemed important in the translation. Reading this file can sometimes help detect errors, but if we delete it, nothing happens. As you proceed, other files will be created similarly. These help LaTeX with the compilation, you can peacefully delete them, but it's pointless.

So let's replace Hello world! with the correct version of the code. To do this, click on Wizard, Quick sTart and then on ok. In Czech version on Guide, Assistant for Document and ok. The following code will appear, which you can already translate after adding Hello World! to the correct location.


\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}
Ahoj světe!
\end{document}

The advantage of LaTeX over other documentary writing programs is that it can create documents in a clear way, offering separation of content from form. This clarity is invaluable, but requires the user to be aware of and actively care for it, e.g. by properly indenting blocks of code.

A little explainer. Like a html document, .tex the document is broken down into a header, where general properties such as font size or margin size are set, and onto the body of the document itself, where the user can insert their text. This breakdown aims to clarify the document. The header loads packages using the \usepackage{package} command, which are pieces of code written by someone else and stored somewhere on your computer, and which extend the program's functionality. Perhaps the inputenc package ensures that TeX knows you're using UTF8 file encoding, the geometry package provides page margins.

The body of the document is (as opposed to the header) bounded by \begin{document} and \end{document}. The code to be written between these two lines is the content of the document.

LaTeX contains two kinds of commands, or character sequences, that you can use to achieve some special effect. The first kind is \command[optional_argument]{mandatory_argument}, and each command may or may not have a mandatory and optional argument -- you need to know the command. The other, in the following form:


\begin{$p$rostředí}
Text
\end{prostředí}

The first simple command achieves a one-off thing like loading a package. The second command is also sometimes called an environment, and it works in such a way that whatever occurs in the environment is altered in different ways.

Basic Formatting

In previous sections of the manual, you may have learned how to create your own tex document. We will now show how to incorporate stylistic elements into the document. It'll be a short list, because there's probably no other way to put it. So to remember those commands, experiment and test what they do on their own.

Practical things first: comments can be inserted in the code that do not affect the result, such that the character % is in front of the segment being commented on. The % character itself is inserted with \%. Next, one line break acts as a gap. To create paragraphs, a person must press enter twice, or place a \\ command at the end of the paragraph. The two modes of paragraph differ in that \\ makes the paragraph without indentation. Commands \indent and \noindent are used to cancel indentations or introduce them.

Text style

Tip: you can create an empty environment with { }. So {\itshape italic} produces the same as \textit{italic}, however both commands work differently.

Images

Have you ever had an image inserted into Word and its change destroyed the entire document? This should happen less often at LaTeX. While it's true that it's hard to handle images without a graphical interface, LaTeX does have a reasonable default setting that you can use.

For all image manipulation, you must have the image in the same folder as the source .tex file. Let it be called Giant.png.

The \textwidth command is a line width. For example, half a line is 0.5\textwidth.

Mathematics

LaTeX is renowned for how easy it is to spell math. To write a mathematical equation, you must surround all mathematics with a dollar sign as follows: $x=2+3x$ → $x=2+3$. If your equation is significant and you want it to take up a line for itself, then surround it in two dollars:


$$E=mc^2$$

I don't recommend using \frac in line math because there's too little space. Just apply over → a/b.


\begin{align*}
x + 1 &= 0 \\ %Ampersand & říká, podle kterého symbolu se mají rovnice zarovnat.
x &= -1
\end{align}

Formatting

What else?

I was able to describe a lot in this tutorial, however I had no room to describe things like different packages such as memoir, varwidth or fancyhdr, nor could I explain how to create my own macros, which helps when you're working on a big project.

A file that summarizes several of LaTeX's beginner features can be found here. If the file looks weird, then change your browser encoding, which, for example, provides a Charsetextensionin Chrome. Try to compile it and make sure you really understand everything already. If so, you've done the basics of writing at LaTeX, and you can do almost anything with the help of the Internet!

Other tutorials can be found on Learn X in Y minutes (that's a similar tex file to mine, only more extensive) or on the Cloud tex document writing platform Overleaf.

But the best thing to do is to make something in TeX. Maybe a flyer to celebrate, marijuana rules to keep everyone from fighting, a diatribe for a lost cat, the possibilities are endless. I, for one, was a hymnal. If you don't know what to do, a search at DuckDuckGoGo and then Stack Overflow or Detexify for unknown symbols will help.

Did the LaTeX article help? Perhaps my guides to Gnuplot and Asymptote will help, or you can read one of my articles for example on foreign language learning or differential counting.