Overleaf-learn LaTeX in 30 minutes overleaf-learn LaTeX in 30 minutes

In this guide, we hope to give you an initial introduction to LaTeX. This guide doesn’t require any prior knowledge of LaTeX, but by the time you’re done, you’ll have written your first LaTeX document and, with any success, you’ll have a good idea of some of the basic features LaTeX offers.

What is LaTeX?

LaTeX (pronounced lay-tek or Lah-tek) is a tool for creating professional-looking documents. It’s based on the idea of “what you see is what you get,” which means you just have to focus on the content of your document and the computer takes care of the formatting for you. Users can type plain text and let LaTeX handle the rest, rather than breaking up the text on the page to control formatting like Microsoft Word or LibreOffice Writer.

/’leɪteks/

Why learn LaTeX?

LaTeX is used worldwide for scientific documents, books and many other forms of publishing. Not only can it create beautiful typographical documents, but it also allows users to very quickly handle the more complex parts of typography, such as entering mathematical formulas, creating tables of contents, drinking and creating bibliographies, and maintaining a consistent layout across all chapters. Given the number of open source packages available (more on that later), the possibilities for LaTeX are endless. These packages allow users to do much more with LaTeX, such as adding footnotes, drawing charts, creating tables, and so on.

One of the most important reasons people use LaTeX is that it separates the content and style of a document. This means that once you have written the content of the document, we can easily change its appearance. Similarly, you can create a document style that standardizes the appearance of many different documents. This allows scientific journals to create templates for contributions. These templates have a prefab layout and only need to add content. In fact, there are hundreds of templates available for everything from resumes to slides.

Write your first LaTeX article

The first step is to create a new LaTeX project. You can do this on your own computer by creating a new.tex file, or you can start a new project in Overleaf. Let’s start with the simplest working example:

\documentclass{article}

\begin{document}
First document. This is a simple example, with no 
extra parameters or packages included.
\end{document}
Copy the code

LaTeX already handles the first paragraph format for you by indenting the first line of the paragraph. Let’s take a closer look at the functionality of each part of our code.

Open an example in Overleaf

The first line of code declares the type of the document, called a class. This class controls the overall appearance of the document. Different types of documents will require different classes, i.e. a resume will require a different class than a scientific paper. In this case, the class is article, one of the simplest and most common LaTeX classes. If you are working with other types of documents, you may need a different class, such as Book or Report.

After that, you write the contents of the document wrapped in the \begin{document} and \end{document} tags. This is the body of the document. You can start writing here and modify the text as you see fit. You must compile the document to view the results of these changes in a PDF. You can do this in Overleaf by clicking Recompile. (You can also set your project to be automatically recompiled when you edit the files by clicking the little tip next to the Recompile button and setting Auto Compile to open.)

If you are using a basic text editor, such as Gedit, Emacs, Vim, Sublime, Notepad, etc., you will have to compile the document manually. To do this, simply run pdflatex < Your document > on your computer terminal/command line. For more information on how to do this, see here.

If you are using a specialized LaTeX editor such as TeXmaker or TeXworks, just click the Recompile button. If you are not sure where the location is, consult the program documentation.

Now that you know how to add content to a document, the next step is to give it a title. To do this, we must talk briefly about preamble (preamble means introduction, preamble, but it mainly refers to the code part of LaTeX, so keep the word).

The preface to a document

In the previous example, the text was entered after the \begin {document} command. Until then, everything in a.tex file was called preamble. In Preamble, you define the type of document you want to write, the language you want to write in, the packages you want to use (more on that later), and several other elements. For example, the preamble for a normal document would look like this:

\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
Copy the code

Here are the details of each line:

\documentclass[12pt, letterpaper]{article}
Copy the code

As mentioned earlier, this defines the type of document. Some additional arguments, enclosed in square brackets, can be passed to the command. These parameters must be separated by commas. In the example, additional parameters set the font size (12pt) and the paper size (letterpaper). Of course, other font sizes (9pt, 11pt, 12pt) can be used, but if not specified, the default size is 10pt. As for paper size, other possible values are A4paper and legalpaper; See the article on page size and margins for more details on this.

\usepackage[utf8]{inputenc}
Copy the code

This is the encoding of the document. It can be omitted or changed to another encoding, but UTF-8 is recommended. Unless you specifically need other encoding, add this line to Preamble if you are not sure.

Add title, author, and date

To add the title, author, and date to the document, you must add three lines to the Preamble (not the body of the document). These lines are

\title{First document}
Copy the code

This is the title of the document.

\author{Hubert Farnsworth}
Copy the code

Enter the author’s name here, and as an option, you can add the following command:

\thanks{funded by the Overleaf team}
Copy the code

This can be appended to the title command after the author’s name in braces. It will add superscripts and footnotes with text in parentheses. This feature can be very useful if you need to thank an organization in an article.

\date{February 2014}
Copy the code

You can enter the date manually or use the command \today to update the date automatically when the document is compiled.

After you add these lines, your Preamble should look like this

\documentclass[12pt, letterpaper, twoside]{article}
\usepackage[utf8]{inputenc}

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the Overleaf team}}
\date{February 2017}
Copy the code

Now that you have specified a title, author, and date for the document, you can print this information on the document using the \maketitle command. This should be included in the body of the document (in bold, as LaTeX terminology) where you want to print the title.

\begin{document}

\maketitle

We have now added a title, author and date to our first \LaTeX{} document!

\end{document}
Copy the code

Open an example in Overleaf

Add comments

As with any code you’re writing, it’s often useful to include comments. Comments are paragraphs of text that you can include in a document that will not be printed or affect the document in any way. They are useful for organizing work, taking notes, or annotating lines/sections during debugging. To comment in LaTeX, you simply write a % sign at the beginning of the line, as follows:

\begin{document}

\maketitle

We have now added a title, author and date to our first \LaTeX{} document!

% This line here is a comment. It will not be printed in the document.

\end{document}
Copy the code

Open an example in Overleaf

Bold, italic, and underline

Now, let’s look at some simple text formatting commands.

  • The bold: Bold text use in LaTeX\textbf{... }Command writing.
  • italics: Italic text use in LaTeX\textit{... }Command writing.
  • Underline: Used for underlined text in LaTeX\underline{... }Command writing.

Examples of each of these are shown below:

Some of the \textbf{greatest}
discoveries in \underline{science}
were made by \textbf{\textit{accident}}.
Copy the code

Another very useful command is \emph{… } command. In practice, the \emph command uses its arguments depending on context – in plain text, the emphasized text is italic, but if used in italic text, the behavior is reversed – see the following example:

Some of the greatest \emph{discoveries}
in science
were made by accident.

\textit{Some of the greatest \emph{discoveries}
in science
were made by accident.}

\textbf{Some of the greatest \emph{discoveries}
in science
were made by accident.}
Copy the code

In addition, some packages, such as Beamer, change the behavior of the \emph command.

Open an example in Overleaf

Adding images

Now we’ll look at how to add images to LaTeX documents. On Overleaf, you must first upload the image.

Here is an example of how to include images.

Translator’s note: The picture is a picture of an image and a picture of an image.

\documentclass{article} \usepackage{graphicx} \graphicspath{ {images/} } \begin{document} The universe is immense and it  seems to be homogeneous, in a large scale, everywhere we look at. \includegraphics{universe} There's a picture of a galaxy above \end{document}Copy the code

Open an example in Overleaf

LaTeX cannot manage images alone, so you need to use a package. Packages can be used to change the default appearance of LaTeX documents, or to allow more functionality. In this case, you need to include an image in our document, so you should use the GraphicX package. The new command \includegraphics{… } and \ graphicspath {… }. To use the GraphicX package, include the following line in your preamble: \usepackage{graphicx}.

The command ‘\graphicspath{{images/}} tells LaTeX that the images are saved in a folder named images in the current directory.

\includegraphics{universe} is the command to actually include the image in the document. Here universe is the name of the file containing the image without the extension, so university.png becomes universe. Image file names should not contain Spaces or multiple dots.

Note: File extensions are allowed, but it is best to ignore them. If you omit the file extension, it prompts LaTeX to search for all supported formats. It is also generally recommended to use lowercase letters as file extensions when uploading image files. For more details, see the section on Generating High – and Low-resolution Images. Translator’s note: The link given in the original paragraph cannot jump to the corresponding information section.

Titles, labels and references

You can add titles, labels, and references to images from the graphical environment, as follows:

Choose: mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark, mark \end{figure} As you can see in the figure \ref{fig:mesh1}, the function grows near 0. Also, in the page \pageref{fig:mesh1} is the same example.Copy the code

Open an example in Overleaf

This example contains three important commands:

  • \caption{a nice plot}: You might expect this command to set the title for the graph. If you create a list of graphics, the title will be used here. You can place it above or below the diagram.
  • \label{fig:mesh1}: If you need to reference images in a document, use this command to set labels. The label will number the image and be used in conjunction with the next command for your reference.
  • \ref{fig:mesh1}: This code will be replaced with a number corresponding to the reference graph.

When placing images in LaTeX documents, we should always place them in a graphical or similar environment so that LaTeX can place images in a way that suits the rest of your text.

Note: If you are using titles and references on your own computer, you will have to compile the document twice for the reference to work properly. Overleaf does this automatically for you.

Create lists in LaTeX

Creating lists in LaTeX is very simple. You can create lists using different list environments. The environment is the part of our document that you want to render differently than the rest of the document. They \ begin {… } command begins with \end{… } Command end.

There are two main types of lists, ordered lists and unordered lists. Each will use a different environment.

Unordered list

An unordered list is generated by an itemize environment. Each entry must be preceded by the control sequence \item, as shown below.

\begin{itemize}
  \item The individual entries are indicated with a black dot, a so-called bullet.
  \item The text in the entries may be of any length.
\end{itemize}
Copy the code

By default, individual entries are marked with black dots, known as bullet points. The text in an entry can be of any length.

Open an example in Overleaf

An ordered list

Ordered lists have the same syntactic rules in different environments. We use the enumerate environment to make ordered lists:

\begin{enumerate}
  \item This is the first entry in our list
  \item The list numbers increase with each entry we add
\end{enumerate}
Copy the code

As with unordered lists, each entry must be preceded by a control sequence, item, which automatically generates the number that marks the item. Enumeration tags consist of serial numbers starting at 1.

Open an example in Overleaf

Add mathematical symbols to LaTeX

One of LaTeX’s main advantages is the ease of writing mathematical expressions. LaTeX allows two writing modes for mathematical expressions: inline and display. The first is for writing formulas that are part of text. The second way is to write expressions that are not part of text or paragraphs and are therefore placed on separate lines. Let’s look at an example of inline mode:

In physics, the mass-energy equivalence is stated 
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.
Copy the code

To use inline mode to place an equation, use one of the following delimiters: \(… \], $… $or \ begin {math}… {\ end math}. They all work, and it depends on personal taste.

The displayed mode can be displayed in two versions: numbered and unnumbered.

The mass-energy equivalence is described by the famous equation

\[ E=mc^2 \]

discovered in 1905 by Albert Einstein. 
In natural units ($c = 1$), the formula expresses the identity

\begin{equation}
E=m
\end{equation}
Copy the code

To print the equation in display mode, use one of the following delimiters: \[… \], \begin{displayMath}… {displaymath} or \ \ end begin {equation}… {\ end equation}. Discourage use? . ? Because it produces inconsistent spacing and may not perform well when used with certain math packages.

Important note: The Equation * environment is provided by an external package, see the AmsMath article.

Open an example in Overleaf

Many mathematical mode commands require the AMsMath package, so be sure to include it when writing mathematical formulas. Some examples of basic mathematical mode commands are shown below.

Subscripts in math mode are written as $a_b$ and superscripts are written as $a^b$. These can be combined an nested to write expressions such as

\[ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} = T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) \]

We write integrals using $\int$ and fractions using $\frac{a}{b}$. Limits are placed on integrals using superscripts and subscripts:

\[ \int_0^1 \frac{1}{e^x} =  \frac{e-1}{e} \]

Lower case Greek letters are written as $\omega$ $\delta$ etc. while upper case Greek letters are written as $\Omega$ $\Delta$.

Mathematical operators are prefixed with a backslash as $\sin(\beta)$, $\cos(\alpha)$, $\log(x)$ etc.
Copy the code

Open an example in Overleaf

The mathematical possibilities in LaTeX are endless, and it is impossible to list them all here. Be sure to check out our other articles here

  • Mathematical expressions – Mathematical Expressions
  • Subscripts and superscripts – Subscripts and superscripts
  • Brackets and Parentheses – Brackets and Parentheses
  • Fractions and Binomials – Fractions and Binomials
  • Alignment Equations – Aligning Equations
  • Operators
  • – Spacing in Math mode
  • Sums and limits – Integrals, sums and limits
  • Display style in Math mode
  • List of Greek Letters and Math Symbols
  • Mathematical fonts – Mathematical fonts

The basic format

Now, we’ll examine how to write summaries and format LaTeX documents into different chapters, sections, and paragraphs.

Abstract

In the scientific literature, it is common practice to briefly outline the topic of the paper. There is an abstract environment in LaTeX. The Abstract environment places text in a special format at the top of your document.

\begin{document}

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}
\end{document}
Copy the code

Open an example in Overleaf

Paragraph and newline characters

\begin{document}

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}

Now that we have written our abstract, we can begin writing our first paragraph.

This line will start a second Paragraph.
\end{document}
Copy the code

Open an example in Overleaf

When writing the content of the document, if you need to start a new paragraph, you must press Enter twice (to insert double blank lines). Note that LaTeX automatically indents paragraphs.

To start a newline without actually starting a new paragraph, insert a line break point, which can be done with the \ (double backslash in the example) or the \newline command.

Beware of using multiple \ or \newlines to “simulate” paragraphs with large spacing between them, as this may interfere with LaTeX’s typesetting algorithm. The recommended approach is to continue with double empty lines to create a new paragraph without any \, and then add \usepackage{parskip} to the prologue.

You can find more information in paragraphs and newlines.

chapter

Commands for organizing documents vary by document type, but the simplest form of organizing is segmented and all formats are available.

\chapter{First Chapter}

\section{Introduction}

This is the first section.

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit.   Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\subsection{First Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem
Copy the code

Open an example in Overleaf

The command \section{} marks the beginning of a new section, setting the title inside curly braces. Segment numbers are automatically generated and can be disabled by including * in the segment command as \section*{}. Subsection {}s, and even ‘subsubsection{}s. The basic depth levels are listed below:

– 1 \part{part}
0 \chapter{chapter}
1 \section{section}
2 \subsection{subsection}
3 \subsubsection{subsubsection}
4 \paragraph{paragraph}
5 \subparagraph{subparagraph}

Note that \ Part and \chapter are only available in the Report and Book document classes.

For a more complete discussion of document structure, see the article on sections and chapters.

Create a table

Create a simple table in LaTeX

Below, you can see a simple working example of a table

\begin{center}
\begin{tabular}{ c c c }
 cell1 & cell2 & cell3 \\
 cell4 & cell5 & cell6 \\  
 cell7 & cell8 & cell9
\end{tabular}
\end{center}
Copy the code

The Tabular (table) environment is the default way to create tables in LaTeX. You must specify a parameter for this environment, in this case {c c c}. This tells LaTeX that there will be three columns and that the text in each column must be centered. You can also use r to align text to the right and L to the left. The alignment symbol & is used to specify delimiters in table entries. Alignment symbols in each row must always be fewer than the number of columns. To go to the next line of the table, we use the newline command \\. We wrap the entire table in a Center environment so that it appears in the center of the page.

Open an example in Overleaf

Add borders

The Tabular environment is more flexible, and you can place dividing lines between each column.

\begin{center} \begin{tabular}{ |c|c|c| } \hline cell1 & cell2 & cell3 \\ cell4 & cell5 & cell6 \\ cell7 & cell8 & cell9  \\ \hline \end{tabular} \end{center}Copy the code

You can use the command \ hline horizontal and vertical line parameter | add borders.

  • { |c|c|c| }: This declares the three columns divided by vertical lines and will be applied to the table.|Symbol specifies that the columns should be separated by a vertical line.
  • \hline: This inserts a horizontal line. Here, we include horizontal lines at the top and bottom of the table. Do you use\hlineThere is no limit to the number of times.

You can see a second example below.

\ begin {center} \ begin {tabular} {| | c c c c | |} \ hline Col1 and Col2 & Col2 & Col3 \ \ [0.5 ex] \ hline \ hline 1 & 6 & 87837 & 787  \\ \hline 2 & 7 & 78 & 5415 \\ \hline 3 & 545 & 778 & 7507 \\ \hline 4 & 545 & 18744 & 7560 \\ \hline 5 & 88 & 788 & 6344 \\ [1ex] \hline \end{tabular} \end{center}Copy the code

Sometimes creating a table in LaTeX can be tricky, so you might want to export the [LaTeX] code for the table using the TablesGenerator.com online tool. The File > Paste Table Data option lets you copy and Paste data from a spreadsheet application.

Open an example in Overleaf

Table description (title), label and reference

You can add titles and reference tables in much the same way as images. The only difference is that the table environment is used instead of the Figure environment.

Table \ref{table:data} is an example of referenced \LaTeX{} elements. \begin{table}[h!] , centering, begin {tabular} {| | c c c c | |} \ hline Col1 and Col2 & Col2 & Col3 \ \ [0.5 ex] \ hline \ hline 1 & 6 & 87837 & 787 \ \  2 & 7 & 78 & 5415 \\ 3 & 545 & 778 & 7507 \\ 4 & 545 & 18744 & 7560 \\ 5 & 88 & 788 & 6344 \\ [1ex] \hline \end{tabular} \caption{Table to test captions and labels} \label{table:data} \end{table}Copy the code

Open an example in Overleaf

Note: If you are using the title description and reference on your own computer, you must compile the document twice for the reference to work properly. Overleaf does this automatically for you.

Add a directory

Creating a directory is simple, and the command \tableofcontents does all the work for you:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{ }

\begin{document}

\maketitle

\tableofcontents

\section{Introduction}

This is the first section.

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit.   Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...

\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\end{document}
Copy the code

Sections, sections and chapters are automatically included in the table of contents. To add entries manually (for example, when you want an unnumbered part), use the command \ addContentsline in the example.

Open an example in Overleaf

Download your completed file

You can download your completed PDF by clicking PDF from the left menu above. A faster option is to click the Download PDF button on the PDF viewer, as shown below.