Learn LaTeX — A Beginner's Step-By-Step Guide
Guides and eBooks LaTeX

Learn LaTeX — A Beginner's Step-By-Step Guide

Deeptanshu D
Deeptanshu D

Table of Contents

What is LaTeX?

LaTeX, usually pronounced either as “Lay-tech” or “Lah-Tech” is a typesetting software used as a document preparation system, very often used by academicians, researchers, scientists, mathematicians, and other professionals. In contrast to the general word processing software like Microsoft Word, Google Docs, and others which function on the principle of WYSIWYG (What You See Is What You Get), LaTeX functions as a plain text markup language, that leverages optimal typographical rules which later gets compiled into a PDF document. A plain text format is usually used to write the content and then further annotations with subsequent commands are used, to control the display of various elements. As a result, you get documents that bear a more professionally designed appearance and belong to a completely different class to the output from a word processor.

LaTeX provides you with numerous customization options that allow you to introduce diversity in the documents with precise control over the layout and formatting. Moreover, creating templates in LaTeX is simple enough, it does not require a much-advanced level of knowledge for LaTeX to use and configure. All these features allow, even,  a novice LaTeX user to create beautiful documents and learn as they go.

Why you should read this beginner's guide to learning LaTeX?

This guide has been extensively curated to provide you with a hands-on introduction to LaTeX. No matter even if you have used word processors like MS- Word or Docx, LaTeX, being simple and easy enough, can be learned in no time.

Built on the assumption that the majority of the readers might not have any prior know-how of the LaTeX typesetting, this guide starts from the basics and then gradually delves into the advanced formatting. One feature at a time will be introduced as you progress through this guide.

Once you have completed this guide, you will be able to create a LaTeX document all by yourself. The introductory features will let you get versed with the basic features of the LaTeX typesetting, empowering you to typeset your research paper or dissertation easily. However, the advanced features will allow you to build fluency with LaTeX, therefore, boosting your productivity.

LaTeX: The Backstage Story

In the late 1960s, Donald Knuth, arguably one of the most prominent and well-respected scientists in the domain of Computer science, was deeply disappointed by the quality of his famous series “The Art of Programming”. In order to eradicate this misery in document typesetting, he started a project to create a new typesetting infrastructure, called TeX (Pronounced “TeK”).  The purpose of the project was to develop a typesetting program that can accommodate the texts and mathematical formulae easily.

He observed that the existing digital typesetting system of that era was not matching appropriate typographical standards. A decade later, he froze the system and TeX was born. TeX gave the fine-grained control and huge flexibility over the document layout, as envisioned by Knuth.

However, the enormous amount of flexibility associated with the TeX made it complex, too.  So, by the mid-1980s, Leslie Lamport introduced a higher language that used TeX as the base but made it a lot easier to use. Introduction of predefined document styles, sectioning, indexing, automatic cross-references, automatic numbering, and various other useful features, as integrated by  Lamport, brought real ease in the usage of TeX. Because of its user-friendliness LaTeX is sometimes referred to as “Lamport-TeX” too.

Difference between TeX and LaTeX

TeX exists as a combination of a program (that performs the typesetting; tex-core) and a format( a set of macros that engines bring into use; plain-tex). However, TeX lends itself with the basic features only. TeX can help you in formatting your document in great detail using its various commands( e.g. kerning, spacing, ligatures, font styles, etc.). Additionally, it provides different algorithms tailored to compute the optimal flow of text in your document( e.g. where to insert page breaks, line breaks, etc.) Therefore, TeX is built over providing users with various algorithms and commands to specify the tiniest detail to maintain the quality standards of the document.

Whereas, LaTeX, being built on the TeX, is a set of macros basically employed for formatting the documents. The idea behind LaTeX is to simplify the formatting so that users stay more focused on the content rather than the format. LaTeX generally provides you with commands that preside over the structure and appearance of your document. (e.g. sections, emphasis, tables, indices, etc.).

Assume you want to insert a section in your document. Now if you are using TeX, the procedure is to select a larger font, choose a different font style and insert spacings before and after the section heading. Whereas, in LaTeX, you just need to insert a command as \section{____} and you will find your section in front of your document with the appropriate font style, size, and spacings.

Moreover, since LaTeX functions over the same stack as TeX, a beautifully curated document is obtained as output, whereas the input also remains well structured, easier to read and write both for humans and machines as well.

Why should I learn LaTeX?

LaTeX is the best choice for creating any scientific and technical documents. Moreover, LaTeX provides easy typesetting of mathematical formulae. If you are a scholar or researcher, then LaTeX is the best tool that you can leverage to write down your thesis or research paper. Besides its top-notch technical features, it can help you produce extremely stable and high-quality output documents, built with the easy handling of the complex sections, no matter how large they are.

Apart from the fact that worldwide, most of the academic and non-academic journals strongly recommend or accept submissions in the LaTeX format, below are the 8 reasons why should you learn LaTeX:

  1. While using LaTeX,  there is no need for you to worry about the structure of the document. You can put your entire concentration behind the content. According to your chosen template or the set rules, LaTeX automatically ensures that typography i.e. fonts, text height, spacing, etc. remains consistent within the document.
  2. LaTeX has been built on the parameters of flexibility and transparency. In LaTeX, the document structure remains visible to the user and can be easily replicated i.e. copied to another document.
  3. You can easily generate the references, indexes, footnotes, and citations in LaTeX.
  4. The real trigger for Donald Knuth for developing the Tex typesetting Platform was to insert quality mathematical formulae and expressions in the document. That is why LaTeX provides you with the features through which you can easily SciSpace any mathematical expressions and formulae.
  5. The LaTeX document source exists as a plain text.
  6. Any text editor can easily read and understand the text source.
  7. Equations, expressions, tables, figures, etc. can be easily generated and inserted in the document, using algorithms in any language.
  8. Leveraging the version control software, any modifications or changes can be easily tracked.

Further remarkable features of LaTeX are its cross-referencing capabilities, automatic numbering, and generation of a table of contents, figures, indexes, glossaries, and bibliographies. Moreover, LaTeX provides multilingual benefits, through its language-specific features integrated with PostScript and PDF features.

While using LaTeX you can produce your output document in the format as per your choices. DVI (Device Independent) and PDF are the two formats that LaTeX supports natively, but using other software integrations, you can easily convert that to PostScript, PNG, JPEG, etc.

Getting Started With LaTeX

Installing LaTeX

To bring the magic of LaTeX to your system, we will be using the platform of LaTeX distribution-TeX Live. TeX Live has the huge benefit of being OS friendly i.e. it stays compatible with Windows, Mac OSX, and other Unix-based operating systems. TeX live is well managed and brings frequent updates. Therefore, a very trusted platform for anybody who wants LaTeX.

To start with, visit the homepage of TeX Live - TeX Users Group (tug.org)

You should explore the homepage in detail to understand the depth of information available there.

TeX Live - TeX Users Group

The installation can be done in two ways. The first method requires an internet connection whereas the second starts with a download of a file, which can be then installed in offline mode easily.

Installing the TeX Live through Net Installer Wizard for Windows

Follow through the steps described below and you will find LaTeX running on your system within a few clicks:

1. You can click the download link from the homepage of TeX Live - TeX Users Group (tug.org) or directly visit Installing TeX Live over the Internet - TeX Users Group (tug.org).

Installing TeX Live over the internet

2. Download the install-tl-zip. This will provide the installation suite in zip format.

3. Extract the files using any zip extractor. Personally, I prefer WinRar.\

4. After the extraction is complete, open the containing folder and double click the windows batch file install-tl.

5. A window of TexLive will appear

TeX Live Installer

6. Choose the folder where you want the installation to happen and keep the paper size to A4 (recommended), or you can choose any other as per your choice.

7. Click the Install button at the right bottom.

8. A pop-up window showing the installation progress will appear.

Tex Live Installer - Installation Process

9. Click, Finish when the installation window  shows the installation progress as complete.

After the installation you can go to your start menu to check if the suite contains a TeX Live 2021 comprising 6 programs:

  1. DVIOUT DVI Viewer: This is a viewer program built to support the classic LaTeX output DVI. Since PDF is the most widely used format today, so probably you won't be in need of that.
  2. PS_View: In case you use the PostScript format for either writing or reading the docs, then you will need this viewer.
  3. TeX Live Documentation: This will be of great use for configuring and managing the LaTeX software.
  4. TeX Live Manager: This will help you in managing different packages and updates for the software.
  5. TeX Doc GUI: Any kind of information that you might need while using the LaTeX software, you can always refer to it. It is built and integrated as a graphical user interface. Rather than searching online for different try this one out, you will find this one lot quicker.
  6. TeX Works Editor: This is the actual platform that we will be used extensively to create different forms of LaTeX documents.

Installing LaTeX for Mac OS, Linux, and other OS

If you are a Mac OS user, you can visit TeX Live. Download the installation file in the .zip  provided. Once done with the extraction, double-click the setup file to install it.

For most Linux users, installation is quite easy. You can go to your systems package manager and search for TeX Live. For Ubuntu, you may use Synaptic, on SUSE systems use YaST, with Red Hat an RPM frontend, and on Debian systems use Aptitude.

Pro Tip: For easy and smooth installation, you can choose to use the MikTeX bundle. The platform provides all the options for different OS. It will provide you with regular use packages and comes with an easy & lightweight editor.

Miktex bundle

Installing Extra-Packages or Add-On features

Add-on features built for introducing various kinds of document styling and formatting for the LaTeX documents are known as packages. A package usually exists as a file or sets of files comprising certain commands and programs that either add new typesetting features or modify the already existing ones. Usually, there are no restrictions on the number of packages that you want to install, however, there exists a configuration limit on the number of packages that can be executed under a single LaTeX document, although that also depends on the package size.

Usually, a large set of pre-installed style packages comes integrated with the LaTeX installations. You can easily configure and manage these packages through the package manager of the respective TeX distribution.

However, in some situations, you do need some extra packages to bring some uniqueness to your LaTeX document. In such situations, you can visit the CTAN website. Use the CTAN search page to find out the packages easily. Once you get the package of your choice, use the indexes on the CTAN server to find out the directory from where it can be downloaded.

Automatic Installation of Packages

You can find various packages in the repositories of the package manager, depending upon the OS you are currently using.

With MikTeX, you can choose the packages individually. MikTeX has an advantage; it asks you to download the missing packages by itself, after the compilation of the document.

In TeXLive, you will find the specific packages bundled with the distribution package. For example, to provide the document in different languages related to internationalization, you need to install a package like TeXLive-Lang. In addition, you can extensively use TeXLive Manager- tlmgr to configure and manage packages separately.

Manual Installation of Packages

Before downloading any package, you need to ensure that it contains two files, one with .dtx and the other one as .ins. The first one is a DOCTex file, which functions to keep the program and its documentation as a single entity. The second one i.e. .ins is an installation file, usually smaller in size.

Besides, always keep the practice of keeping the downloaded packages in a temporary directory.

Now hopping onto the steps to install the package.

I have summarized the entire process into 5 easy steps to install a LaTeX package. Follow along and you will find it easier to run through your system.

1. Extracting the Files

Click on the .ins file and run it on the LaTeX. What I meant to say is that you should open the .ins file in your LaTeX Editor.  Another way is to visit the temporary directory, open the command window, and type LaTeX followed by the .ins file name. In this way, you will be able to extract the files required from the .dtx file (Because of this it is required that both the .dtx and .ins file remains in the temporary directory).

2. Preparing the Documentation

Click onto the .dtx file and Run LaTeX editor. To keep the cross-references in the correct sequence, it might happen that you need to run it multiple times. As a result, you will get a .dvi file that will explain the key features and functioning of the package.

If you want to create a PDF documentation file, then run the .dtx file on pdfLaTeX instead. In case the package contains an index file within, then you must make a  .idx file as well. In some situations the system itself creates a .glo(Glossary) file, then you can run the following command to keep it correct:

3. Files Installation

Files installation means that you need to move or copy the files created in the previous step from the temporary directory to TeX Local Installation Directory Tree. you must ensure that you keep all the manually installed packages in the TeX Local Installation Directory Tree. It is important as it prevents the new packages from overwriting the files in the main directory or from getting overwritten by the main files.

In a TDS (TeX Directory Structure) compatible system, a TeX Local Installation Directory Tree is nothing but a folder containing many subfolders within it.  The main folder is usually named texmf-local/ or texmf/. The main folder’s location varies from system to system. You can access it as :

  • MacTeX: Users/username/Library/texmf/.
  • Unix-type systems: Usually ~/texmf/. If you use TexMaker on Linux based OS like Ubuntu, access it via: /usr/share/texmf/
  • MikTeX: you can designate any folder as a local directory provided you need to register it first as a user-managed texmf directory.

Moreover, you must refer to the documentation to understand if there are any prescribed locations or folders where the files should be moved.

Tex directory structure

4. Index Update

This is the most important step, any mistake can be catastrophic as nothing will work.

After the package installation, it is required that you update your package database. To do this, run the TeX indexer program. The indexer program comes in various names depending upon the original TeX distribution package.

For example:

  • teTeX, TeX Live, fpTeX: texhash
  • web2c: mktexlsr
  • MacTeX: MacTeX appears to do this automatically for you.
  • MikTeX: initexmf --update-fndb (or use the GUI)

Also, in Win 8 and above, you can do it easily by:

MikTeX>Settings>Refresh FNDB>OK.

5. Updating Font Maps

Font mapping files require an update if, during the index, any files like TrueType or Type1 fonts have been installed by default. A .map file comes attached with the packages. Depending upon the LaTeX distribution, the font map updating program exists on the updmap.

  • TeX Live and MacTeX

For files stored on a personal tree, use updmap --enable Map=mapfile.map

For files stored in the system directory, use updmap-sys --enable Map=mapfile.map

  • MikTeX

Run initexmf --edit-config-file updmap, add the line "Map mapfile.map to the file that opens, then run initexmf --mkmaps.

Check any Package Status

To check if a package file is available with the TeX compiler, you can use the command as depicted below:

Additionally, you can use the tool tlmgr in TeXLive to gain further information on packages. The command can be used as depicted below:

Package Documentation Information

You must refer to the documentation files whenever you want to have a detailed idea about the commands and functions a package provides. For every installed package, there exists a corresponding .DVI file in the texmf/doc subdirectory. However, the location of these subdirectories varies for different LaTeX distribution packages.

Pro-Tip:

You can easily access the installed packages’ distribution information using the below command. In the editor, just use the texdoc command followed by the package name and you will find out the details in front.

LaTeX Document Structure

Standard Global Structure of the Document

The basic structure of a simple LaTeX document will look like the following:

\documentclass[10pt,a4paper]{article}

\usepackage{graphicx,geometry}

\begin{document}

\end{document}

Here, the LaTeX document structure contains 2 main parts.

Preamble Part

Preamble part exists between \documentclass[10pt,a4paper]{article} and \begin{document}. The Preamble part actually tells the LaTeX program how to SciSpace the document.

In the example above, the code \documentclass[10pt,a4paper]{article} will SciSpace the content of the document using article class (produces article type) in 10pt font size, and its output would be generated in a4paper size. Like an article, one can produce different types of documents, such as books, reports, thesis, etc.

The line \usepackage{graphicx,geometry} tells the LaTeX to load additional style files for supporting more typesetting features. For example, graphicx package is loaded mainly for the support for including Images in the document, the geometry package provides more flexibility in defining page dimensions.

Document Class

Document class defines the standard layout under which LaTeX will create your document. You can access various layout standards within the class files folder. These files generally contain “.cls” extension.

From the above image you can easily notice that the class parameter associated with the command \documentclass, tells LaTeX which “.cls” file to use for the current document. Also, you must put this declaration at the beginning. The option parameter will help you customize the document as desired. In case you use multiple options, you must use commas to separate the options.

For example,

By using options, you can direct the LaTeX engine to create an article with a font size of 11pt and t an output file that is suitable for printing on both sides of A4 paper.

Below is a list of document class that you can easily incorporate while creating documents in LaTeX:

Class Name 

Function

Article

Used for creating articles for scientific journals,program documentation, research papers, etc.

Letter

For creating Letters

Books

For creating books.

Slides

For Slides creation. Note that it uses SANS Sheriff as font.

Beamer

For creating presentations

Reports

Normally suited for documents containing multiple chapters, thesis, etc.

IEEE Tran

Documents required in IEEE transaction Format.

Additionally, LaTeX provides you with various options to customize your document. You can read the below mentioned list of options used quite often for document creation in LaTeX:

Options

Functions

10pt, 11pt, 12 pt

The default font size is 10pt. However you can keep the font size as 11pt, 12pt, etc.

a4paper,
letter paper

LaTeX engines use letter paper as default document size. However, you can modify it to a4 paper, a5 paper, executive paper, etc.

fleqn

Brings formulae with left-alignment instead of center alignment

Titlepage,
Notitle page

Document class like report or book always start with a page title as default.However, while using article class you have to specify whether the page will start with title or not.

twocolum

Directs LaTeX engine to typeset a document as two-column.

Landscape

To fix the document orientation as landscape mode.

Open right,

openany

It commands the engine to start typesetting either on right hand pages or on the next available page. The report class as default starts on next available pages whereas the book class does on right hand pages.

leqno

Put the numbering of the formulae on the left hand side.

twoside, oneside

It states whether the output will be a double sided or single side.

Packages

The packages generally come into use when you want to insert an image or graphics, colored texts, or a source code from a file into a document. LaTeX engines come with many pre-installed packages. Additionally, you can add some extra packages if the need arises.

The command to use a package is:

Here, inside the curly brackets, you should enter the name of the package that you intend to use. Also, using options with the command that can let you use certain features of the entire package.

For example, in order to add some colors while typesetting a document in LaTeX, you can use the color package as:

Body Part or The Environment

Body part is the place between \begin{document} and \end{document}, where the actual content of the document can be added, which includes Document Title, Author/Address/Date, Headings/Texts, Table/Figures/Equations/Lists/Quotations, Bibliography/Appendix/Glossary etc.

Top Matter

The LaTeX engine defines the document and author information as Top Matter. Although there does not exist any command as such \topmatter, the top matter includes document information like title, date, and author information like name, email, etc.

A standard article will begin with a document title, followed by author names and addresses. The code to obtain these are:

\begin{document}

\title{Title of the document}

\author{Donald Knuth and Leslie Lamport \cr

{Address of Authors}

\date{\today}

\maketitle

\end{document}

Here, \cr is used for breaking the line after the names in \author. The document date can be simply changed by writing the date in it, for example, \date{30 August 2021}, or the date can be ignored by leaving its content empty, i.e., \date{}.

The above code will produce the following output

Notes:

(a) The content of the document should be between \begin{document} and \end{document} environment as in the above example.

(b) The Title part should always end with \maketitle command. This command will produce the formatted output of Title and Authors.

(c) authblk package provides more flexible formatting of author/address.

Abstract and Keywords

While writing research papers it is mandatory to include the abstract and the keywords before the main section of the body. The LaTeX engine bears pre-defined commands that inform it what part of content makes up the abstract and keywords respectively. The command to include abstract and keywords in the document exist for document class like article and report, however, not available for book class of document.

Immediately after the Title part, the Abstract and Keywords can be added as follows:

\begin{abstract}

Abstract text goes here ... a

Keywords: keyword; keyword; keyword

\end{abstract}

The above code will produce the following output of Abstract and Keywords:

Note: For line break or new paragraph, leave a blank line space between lines as seen in the code of Abstract text and Keywords.

Different Levels of Heading

You can write different levels of headings using the following codes:

\section{Heading - Level 1}Text goes here ...

\subsection{Heading - Level 2}Text goes here ...

\subsubsection{Heading - Level 3}Text goes here ...

\paragraph{Heading - Level 4}Text goes here ...

\subparagraph{Heading - Level 5}Text goes here ...

Output of Headings produced with the above codes:

Unnumbered Headings

Unnumbered headings can be obtained with the starred option of their respective sectioning commands. For example: \section*{Acknowledgements}

Sectioning Commands

In order to introduce different sections in your document you can use the section commands as provided by LaTeX. Also, certain section commands stand appropriate as per the document class. For example, an article contains sections and paragraphs whereas a book contains chapters. You can view the section commands as provided by the LaTeX below:

Moreover, the LaTeX engine automatically sorts the section numbers for you. Therefore, no need to enter the section numbers separately. Note that you don’t need to use any \begin and \end commands while using section commands.

Additionally, there exist 7 levels of depth for introducing sections in a LaTeX document. In the table below you can see the various levels of sections, which exist as a subsection of its above-mentioned section:

Section Numbering

Sections are numbered automatically in LaTeX. You just need to add the heading for different sections in the curly brackets. Roman numerals like I, II III are attached with parts, for chapters and sections decimal numbering like 2.1, 2.2, 2.3, etc., are attached and for appendices, alphabets are used like A, B, C, and so on.

In case you prefer only the main sections like parts, chapters, and sections to be numbered, not the subsections and subsubsections, then you can use the command setcounter, defining the level of depth as you like.

You can use "*" sign after the section commands if you don’t want certain sections to be numbered. Additionally, using the "*" sign after the section commands will not reflect that particular section in the table of contents, too.

However, if you want certain unnumbered sections to be a part of table of contents you can use the package unnumberedtotoc. This package comes bundled with commands like addchap, addsec, and addpart. You can use these commands as depicted below:

\addsec{Introduction}

Moreover, if your document contains hyperlinks pointing towards different locations in the document, then you must use the hyperref package. The package includes a command, i.e., phantomsec that enables hyperlinks to perform in a proper way. You can refer to the below example to understand how this command works:

Ordinary Paragraphs

Text paragraph follows after the section headings. You can simply switch to new paragraphs by simply leaving a blank line. The blank line tells the SciSpace engine about the commencement of a new paragraph. Note that you will not see any blank line in the output document.

Further details on formatting a paragraph will be separately provided in the Paragraph section.

Table Of Contents (ToC)

The LaTeX engine inserts all the numbered headings automatically in the ToC. You can get the ToC in your document by using the command \tableofcontents. The ToC is generally inserted after the Abstract or the Summary in the document.

If you have used multiple figures and tables in your document, you can insert a list of them as well. Use the commands \listoffigures and listoftables to insert a list of figures and tables respectively.

Moreover, you can use the \addcontentsline command to provide a preface or any un-numbered section headings for your document. For example, if you want to add a Foreword or Preface for the article, you can use the commands as,

To rename the ToC, you can use the following code:

\renewcommand{\contentsname}{<New table of contents title>}

Likewise, you can rename the LoF and LoT using the same above mentioned command by replacing the \contentsname with \listfigurename and \listtablename respectively.

Depth for the ToC

The LaTeX Engine by default only includes section headings with level 3 and above. In case you want to modify the depth for the ToC, you can do so easily by adding the below-mentioned command.

setcounter{tocdepth}{4}

Additionally, it is important that you use this command in the preamble part of the LaTeX document.

Book Structure

In the document class ‘book’, there lies few variations from the article class. The LaTeX engine by default typesets a book document with two columns format. Further, the header contains the information related to the current chapter and section.

Also, it is mandatory to use chapters in the book class. Otherwise, it won’t be technically called a book.

The basic syntax for a book class document appears like this:

In the book, LaTeX uses Roman numerals to number pages in the front-matter chapters. Also, the front matter part will not be included in the numbering. Actually, the front-matter remains devoid of any sections and that’s why it is numbered as`0.n`.

No difference exists in the functioning of the main-matter chapter. It works as usual. However, Arabic numerals are used for page numbering in the main-matter chapters.

Similar to the article class, the \appendix command can be used to tell the SciSpace engine that the following sections or chapters are to be included and numbered as appendices. Moreover, you should use the \appendix command only once, even if you have used multiple appendices in your document. For example, to indicate multiple appendices, you can use the \section command.

The backmatter and frontmatter functionality are same. The section numbering follows the same mechanism as the front matter.

Additionally, the book document class treats special entries like ToC as an unnumbered chapter.

Bibliography

A bibliography contains the list of references that were used for preparing a document.  To insert a bibliography in the document, you must create a .bib file first. The syntax to create a .bib file goes as follows:

@BOOK{DUMMY: 1

AUTHOR="John Doe",

TITLE="The Book without Title"

PUBLISHER="Dummy Publisher",

YEAR="2100"

}

The example contains the document class as book and other parameters are self explanatory.

Once done through the creation of the BiBtex file, you need to use commands \bibliography that informs the LaTeX engine the location of your bib file and \bibliographystyle that directs the engine to SciSpace the bibliography in a chosen style. You can use these commands as described below:

\documentclass{article}

\begin{document}

Random citation \cite{DUMMY:1} embeddeed in text.

\newpage

\bibliography{lesson7a1}

\bibliographystyle{ieeetr}

\end{document}

The output document will appear like

Note in the above example that the bibliography document is named “lesson7a1” and the corresponding style is ‘IEEEtr’ which is a common style used widely in the scientific domain.

Most of the LaTeX editors allow you to select and run the bibtex automatically after the compilation. In TeXworks or MiKTeX, this option exists as a default option.

Formatting the LaTeX Document

This section of the guide will introduce you to the commands that can help you towards formatting the body text in different ways. It includes text formatting i.e making texts bold, italic, adding comments, inserting lists( both ordered and unordered), and inserting figures and images into your LaTeX document.

Text Formatting

You can use the command \emph to bring emphasis on some particular texts. This command will bring out the text shape in Italics. Also, the \emph command is the default way by which the LaTeX engine emphasizes any text. You can use this command as:

Similarly, to make some texts appear bold, you can use the command \textbf and \textit for italicized appearance of the text.  You can refer to the below image for details:

Note that the emph command is dynamic in its functionality, i.e., if you will use this command in a sentence that is already emphasized, then the second used text will revert back to the original font. For better understanding, refer to the below image:


LaTeX comes equipped with various commands for text formatting. You can find a list of these commands below and use it accordingly.

Adding Comments

Comments are inserted in a LaTeX document to add special notes. The Comments command is often used in templates to inform users about the functionality of a template.

The comments are added in a document using the % percentage sign. While processing an input file, whenever the LaTeX engine discovers a % sign, it ignores the text following the percentage sign. It means the engine won’t display any text, line breaks, and whitespaces written after the percentage sign until a new line begins.

The comment command, i.e., % sign is extensively used to put notes in a document that will not be visible in the output document.

Refer to the below image to understand the command functionality and the generated printable output version:

Adding Floats (Tables And Figures)

Floats are those objects which float in the pages since they will not break the contents on their own. For example, a full-page Table placed at the middle of the page will automatically move to the next page. This is to avoid the possibility of Table content going beyond the bottom margin. By default, LaTeX defines Table and Figure as floats. More floats can be defined with custom LaTeX packages.

Tables and Figures shall be coded within the environment in its name itself. For example, \begin{table} ... \end{table} and \begin{figure} ... \end{figure}. Because of its power of floating nature, LaTeX will intelligently place them in the pages while typesetting documents. The placement of these floats can also be controlled by giving instructions in the optional argument in square brackets. For example:

\begin{figure}[t] or \begin{table}[b]

This means, the figure will be placed at the top of the page and the table will be placed at the bottom of the page if there is enough space within the page.

Following table shows the available options for the placement of floats.

In two-column documents, the starred variants of these float environments can be used for spanning the floats over two columns. For example, \begin{figure*}   or \begin{table*}

Caption for the Tables and Figures

Another common feature of the float environment is Caption. The \caption{} command will typeset the caption in the required style and it will automatically produce the label and number. For example, the caption in the Table will be prefixed with Table 1, Table 2, etc. Similarly, the Figure captions will be prefixed with Figure 1, Figure 2, etc.

Adding a Table

The code for a simple Table will look like the following:

\begin{table}[t]

\caption{\label{tab1}Caption text goes here.}

\centering

\begin{tabular}{| l | c | r |}

\hline

Head 1 & \multicolumn{2}{c|}{Common Head}\\

\hline

Col 1 & Col 2 & Col 3 \\

\hlineCol 1 & Col 2 & Col 3 \\

\hlineCol 1 & Col 2 & Col 3 \\

\hline

\end{tabular}

\end{table}

Output of Table produced with the above codes:

In the code above, the \caption{} command formats the caption text. It also produces label and numbering automatically. \label{tab1} given inside the caption is for cross-referencing the Table that can be cited with \ref{tab1}. The \centering command is used to center after that.

The tabular environment is an array-like construct of rows and columns. In tabular, the columns are separated by ‘&’ and the rows are separated by ‘\\’.

The code after \begin{tabular} defines the alignment of each column. So, in the example code above ({| l | c | r |}), there are three columns in total and they are defined as l, c, and r; “l” for left alignment, “c” for the center, and “r” for right column alignment. The pipe symbol (|) produces the vertical line between columns.

\hline produces horizontal rules between rows, while \\multicolumn can be used to merge columns.

Useful packages:

float.sty: Defines new custom floats like Graph, Picture. Provides more formatting styles like boxed, ruled etc.

placeins.sty: Placing floats within the sections.

endfloat.sty: Placing floats at the end of the document.

caption.sty: Formatting caption text.

Adding Images

The images should be loaded as separate files in commonly used formats like .png, .jpg, .pdf, or .eps. You can copy the images in the same directory or in a different path, and these images can be loaded with \includegraphics command in the document. This command requires the graphicx package in the preamble, which may be loaded as \usepackage{graphicx} in the preamble.

The LaTeX code for including a figure as a float is as follows:

\begin{figure}[t]

\centering\includegraphics{<path>/fig1.eps}

\caption{\label{fig1}Caption text goes here.}

\end{figure}

It is also possible to set the default path(s) for loading images, the command is \graphicspath{{dir1}{dir2}...{dir3}}. The \includegraphics command provides many options to format the image, for example, adjusting width, height, scale, rotate, crop etc. For example \includegraphics[width=10cm,height=10cm]{fig1.eps}

Useful packages:

subcaption.sty: Handling of subfloats within a single float.

Adding Lists

In the academic domain, Lists are often used to present the document structure in a more orderly, clear, and concise manner. In LaTeX, Lists structures are a kind of environments that are generally classified as:

  • itemize refers to a  bullet list
  • enumerate refers to an  enumerated list and
  • The description refers to a descriptive list.

Lists can be either ordered (numbered) or unordered (bulleted/symbols), the number or bullets will be generated automatically.

Code for Ordered Lists

\begin{enumerate}

\item First item

\item Second item\

item Third item

\end{enumerate}

Output of ordered list produced with the above codes:

Code for Unordered  Lists

\begin{itemize}

\item First item

\item Second item

\item Third item

\end{itemize}

Output of unordered list produced with the above codes:

Nested Lists

The nested lists can be used either as ordered/unordered or combination of both. Here is a sample:

\begin{enumerate}

\item First item

\item Second item

\begin{itemize}

\item First item

\item Second item

\item Third item

\end{itemize}

\item Third item

\item Fourth item

\end{enumerate}

Output of nested list produced with the above codes:

Useful packages:

enumitem , scrextend, tasks, exsheets for better & more formatting options.

Description Lists

Description lists may be used to produce a descriptive list, where there may be a definition term and its description.

\begin{description}

\item[Term 1] This is the definition of the first term.

\item[Term 2] This is the definition of the second term.

\item[Term 3] This is the definition of the third term.

\end{description}

Output of description list produced with the above codes:

Adding FootNotes

The footnote in a document can be created with \footnote command. The command can be used as \footnote{This is a sample footnote} in the document. The footnote number will be generated automatically.

Sample code: This is a sample text for footnote
`\footnote{This is a sample footnote}, more text after footnote mark.`

The following image shows the output of the above code:

Footnote Numbering

The format of footnote number can be changed with the following commands:

\renewcommand{\thefootnote}{\arabic{footnote}}}} - Arabic numerals, e.g., 1, 2, 3 ... \renewcommand{\thefootnote}{\roman{footnote}}}} - Roman numerals (lowercase), e.g., i, ii, iii ...

\renewcommand{\thefootnote}{\Roman{footnote}}}} - Roman numerals (uppercase), e.g., I, II, III ...

\renewcommand{\thefootnote}{\alph{footnote}}}} - Alphabetic (lowercase), e.g., a, b, c ...

\renewcommand{\thefootnote}{\Alph{footnote}}}}- Alphabetic (uppercase), e.g., A, B, C ...

\renewcommand{\thefootnote}{\fnsymbol{footnote}}}} - A sequence of nine symbols, like *, †, ‡, ...

Footnote number can also be given explicitly as: \footnotemark[33]\footnotetext[33]{Footnote text ...}, footnote number will be 33 in this case.

Useful packages:

"footmisc" package provides many features for customizing the appearance of footnote.

Paragraph Formatting

Let's learn how to format paragraphs in your LaTeX document using LaTeX commands and environments.

Paragraph Alignment

The LaTeX engine by default incorporates a justified alignment in all the paragraphs, i.e., flush with both the left and right ends. In case you want to change the alignment of the paragraph in your document, you can easily do so by using some LaTeX environments and their equivalent commands:

Alignment 

Environment 

Command

Left Justified

flushleft

\raggedright

RIght Justified

flushright

\raggedleft

Center

center

\centering

It is advisable to prefer environments rather than commands as using the environment ensures that all the text between \begin and \end will be justified accordingly.

Paragraph Indent

Indenting a paragraph means moving it either left or right edges towards the center. The LaTeX engine by default does not allow the indentation of the first paragraph after the heading.  The indenting space of a paragraph is regulated by the command \parindent. This command tells the engine by how many points the left or the right end of a paragraph should be indented. The commonly used syntax for this command is:

If you wish to indent a paragraph you can do so easily by using the command \indent. Additionally, you must ensure that the \parindent is not set to zero, otherwise, the \indent command will not work. Similarly, you can use the \noindent command to unindent any paragraph.

Moreover, you can indent the subsequent lines of a paragraph using the \hangindent command. By default, this command provides an indent of 0.7cm.

Besides, you can use the \leftskip or the \rightskip commands to provide an extra space to the ends of the document. This command will help you format the paragraphs that you want different from the original document margins.

Paragraph LineBreak

Line Breaks are not advisable while using paragraphs as the LaTeX engine does not bear compatibility to it. However, if the need arises, you can use a hack to insert a line break in a paragraph.

The simplest syntax to follow is; \paragraph{Title} \hspace{0pt} \\

Note, that there lies a space after the closing of the curly bracket. If you will not provide the space, the LaTeX will display the following error message.

There is another shortcut method for bringing in the line breaks inside a paragraph ; \paragraph{Title}  ~\\

Line Spacing

You can modify the line spacing within the whole document using the command \linespread. Besides, you can use the packages like "setspace" which includes several commands that regulate the space between lines for different sections and paragraphs till the command ends. The \setspace package provides you with the following commands and environments:

  • doublespace: lines are double spaced;
  • onehalfspace: line spacing set to one-and-half spacing;
  • singlespace: normal line spacing;
  • spacing: customizable line spacing

Adding Mathematical Expressions and Equations

Typesetting mathematics is one of LaTeX's greatest strengths when compared with other word processors. With many predefined commands and environments, the mathematical equations can be typeset with good-looking and high-quality output, especially the spacing of variables, operators, symbols, parenthesis, etc. LaTeX is one of the most efficient and best available tools to typeset complex mathematical formulas.

By default, LaTeX provides all necessary commands and environments for typesetting math content. However, amsmath package provides more features like different kinds of alignment, the numbering of equations, etc. It is highly recommended to use the amsmath package if your document contains complex formulas. The syntax to use this package follows: \usepackage{amsmath}).

Alternatively, another package that you can use is mathtools package. Moreover, you should try using this package with amsmath package to take advantage of the extra features and make the modifications as per your choice. The usual syntax to use this package follows: (\usepackage{mathtools}).

Inline math

Inline math can be coded either as $...$ or \ (...\). It is also possible to use the math environment as \begin{math}... \end{math}.

For example:

This is an inline math $f(x) = x^2$.

or

This is another inline math \(f(x) = x^2\).

or

The syntax for using Inline math using math environment  follows:

\begin{math}f(x) = x^2\end{math}.

Displayed Equations

Displayed equations are independent from the surrounding text and are displayed in their own lines. Displayed equations can be either numbered or unnumbered.

Numbered Equations

Single line numbered equations can be created with the equation environment.

\begin{equation}1+1=2

\end{equation}

Multiple line numbered equations can be created with  `eqnarray` environment.

\begin{eqnarray}

a, b &=& c \\

a, b &=& cccc \\

a, b &=& cccccc \

end{eqnarray}

eqnarray environment is an array-like construct of 3 columns. The columns are separated with & character and  rows are separated with \\ (double backslash). The \\ also produces equation numbers at the right side of the equation within parenthesis.

amsmath package ( \usepackage{amsmath}) provides many environments like align, gather,  multline, alignat, etc., for different kinds of equation formatting.

Un-numbered Equations

Single line unnumbered equations can be created with any of the following codes:

\begin{displaymath} ... \begin{displaymath}

\[ ... \]

$$ ... $$

The starred version of eqnarray, align, gather  (for example: \begin{eqnarray*}.... \end{eqnarrray*}) and other environments mentioned above can be used to produce unnumbered equations. With these environments, equations can be aligned in different ways.

Inserting Fractions

LaTeX carries the in-built capacity of inserting various forms of mathematical expressions including integrals, fractions, and more in the document. There are different syntaxes to use for various mathematical notions. For example, to insert a fraction mathematical notion in the document you can use the below-mentioned syntax:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}

f(x) &= x^2\\

g(x) &= \frac{1}{x}\\

F(x) &= \int^a_b \frac{1}{3}x^3

\end{align*}

\end{document}

The output generated through this appears like:

Additionally, LaTeX provides flexibility in combining more commands and creating complex mathematical expressions like as described below:
\frac{1}{\sqrt{x}}

The output :

Inserting Matrices

You can insert the matrix expression in your document by using the `amsmath environment. There exists a command `matrix that can be used for this purpose.

Follow the below syntax to add matrices in your document:

\begin{matrix}

1 & 0\\

0 & 1

\end{matrix}

The output displayed will be like:

Inserting Brackets and Scaling

You can use the [ ] to insert brackets outside any mathematical expression. To insert brackets i.e. [ ] , you can use the following syntax:

\left(\frac{1}{\sqrt{x}}\right)

The output displayed will be like:

But using the same  [ ] command for the matrices will result in output error. You can see the below example of what happens when we simply use [ ]  command for matrices.

[

\begin{matrix}

1 & 0\\

0 & 1

\end{matrix}

]

The output displayed will be like:

While using matrices and brackets, it is required that you use scaling of parenthesis as described in the first example. See the below example for further clarity:

\left[

\begin{matrix}

1 & 0\\

0 & 1

\end{matrix}

\right]

The output displayed will be like:

Download Your Finished Document

Since this is the last section of this guide, I will tell you how to download the formatted document through an example. Just follow through. As an application of all that you have learned by now, you can create a new document with the following codes in the TeX editor (I personally use MikteX).

After entering the code, click on the option File>Save in the Top menu. You will find a pop-up menu to save the file.

Rename the file as per your choice and finally click the Save button to save it in your preferred location. Now to typeset and view the output document, click the green arrow button on the top left side (highlighted in the image below).

The output document will open in a new window.

In the output window, again go on the File>Print PDF option in the top menu at the top left corner. You can, also, use the keyboard shortcut, i.e., Ctrl + P to print the PDF document.

On clicking Print PDF, the document will open in a PDF viewer (like Adobe PDF, Google Chrome, etc.), from where you can download the document.

Enjoy!

I certainly hope that you will enjoy creating documents in LaTeX. To get fluent with the LaTeX commands, you must execute the commands simultaneously while referring to this guide. Moreover, this guide has been divided into various sections so that any user, facing difficulties while typesetting documents in LaTeX can refer to particular sections of the LaTeX guide and easily format the document. There do exist online editors and freelancers that can work for you, but there is no loss, only advantages associated with learning LaTeX by yourself so that you can present the document in the best possible way.

Feel free to drop your queries regarding LaTeX in the comments section. Also, tell us what points did I miss that I should add later, to make this LaTeX guide more comprehensive.

Since you made it to the end you should definitely check out SciSpace LaTeX. It brings together the best of LaTeX and word processors into one simple tool. It was specifically designed to serve the research writing industry. It allows authors to collaborate and write their thesis/research papers in just a few clicks.

We also have the best-in-class academic repository called SciSpace discover where we cater to millions of peer-reviewed papers across domains in one place. This is a suite of products that covers everything, from literature searching and discovery to profile management and research writing and formatting.

SEO summarized abstract

General FAQs about LaTeX:

1. What are the special characters in LaTeX?

“#, $, %, &, ~, _, ^, \, { }” these characters are often called as special printing characters or special characters in LaTeX. Each of these characters bears a specific meaning which are:

~ (tilde)- unbreakable space, use it whenever you want to leave a space that is unbreakable, and cannot expand or shrink, as e.q. in names: A.~U.~Leslie.

  • $ (dollar sign)- to start and finish math mode.
  • _ (underscore)-for subscripts in math mode.
  • ^ (hat)- for superscripts in math mode.
  • \ (backslash) starting commands, which extend until the first non-alphanumeric character.

Additionally, if you want the character to be displayed as it is, just introduce a “\” (backslash) in front of it. For example, a “\$” will produce the output as “$”, itself.

2. How do I change text color in LaTeX?

Using the “xcolor’ package, you can change the color of some text blocks in LaTeX. It comes with a command like \textcolor{<color>}{<text>}. Refer to the below sample LaTeX code that shows how you can change the color of the text:

\usepackage{xcolor}

\begin{document}

This is a sample text in black.

\textcolor{blue}{This is a sample text in blue.}

\end{document}

Play with different colors and see how the LaTeX document appears.

You can use the “hyperref” package in your preamble to make clickable links in your LaTeX document. You can add a link with the description using the syntax: \href{URL}{DESCRIPTION}. Moreover, you can use the same “\href” command to provide clickable email links using the syntax:            \href{mailto:support@typeset.io}{support@typeset.io}

4. How to highlight texts in LaTeX?

You have to use the package “xcolor.” Declaring the package in the environment you can use the command \hl{highlighted text}.This command will provide a yellow color highlight to your texts. Additionally, you can change the highlight color using \sethlcolor{color name} command.

5. How to write two equations in LaTeX?

In order to split lengthy equations in a LaTeX document, you can use the package amsmath or mathtools. After that, you can simply use the “\\” i.e. the double backslash to split the equation at a point you wish. Additionally, you can use the \boldmath environment to write equations in bold format. However, if you want to make a single equation appear bold, you can use the command \mathbf{equation inside}.

6. Which class file to make presentations in LaTeX?

LaTeX provides you with a document class by the name “beamer” through which you can easily create presentations. Additionally, you can use various slide templates and slideshow features integrated with it, to make your presentation more appealing. Moreover, it shows compatibility with pdfLaTeX, LaTeX + dvips, etc.

7. What is TikZ in LaTeX?

TikZ is a powerful package that is used to introduce various graphics in a LaTeX document. Basically, TikZ is a part of PGF(portable graphics format). By using the TikZ package, you can easily create lines, dots, curves, circles, graphs, etc., in a LaTeX document.

8. Is LaTeX better than word?

LaTeX, indeed, is better than Word or Docs. It is so because you can easily create footnotes, bibliography, table of contents, indexes, appendices, references, images, captions, cross-references, mathematical equations, etc. Even though Word or Docs provide some (not all like mathematical equations, graphs, cross-references, etc.) of these features, it lacks the ease, flexibility, and professional aesthetic appearance.

If you found the above LaTeX informative, here are some good reads for you:


Become a Guest Author on SciSpace — Write for us to gain exposure among the research community!
Want to share helpful tips and insights for an active community of students, researchers, publishers, and university administrators? Become a SciSpace Guest Author now.