← back

Getting Started with LaTeX

Written by Matthias Osswald - December 2020
LaTeX is great for many use cases. It makes it very handy to cite and add a bibliography, put references in a file or place elements without them jumping around randomly. Also it is pretty easy to work with formulas and equations.

Other reasons to choose LaTeX are that it is platform independent and the changes can be tracked well in version control.

Checkout this repository for the complete project.

How to structure my project

I usually create a similar structure as below for my documents. There is a directory to put the figures, another containing the literature file and the third for the glossary and acronym entries. The main.tex file contains the actual document. The Makefile is the configuration for building the document and the README.md documents how everything is done. For bigger projects I add a content folder with files for each section.

$ tree
    ├─ figures
    │  └─ figure1.png
    ├─ bib
    │  └─ literature.bib
    ├─ glossary
    │  ├─ glossary.tex
    │  └─ acronym.tex
    ├─ main.tex
    ├─ Makefile
    └─ README.md

Makefile - How to Build the Document

On Linux or MacOS we can define a makefile as below to compile the document on changing anything. It has a section to run all the compilation commands necessary to build the document, the bibliography and the glossary. Then there is a section to clean up and one to watch file changes and rerunning the latter.

    ALL=$(wildcard *.tex content/*.tex figures/*.{png,jpg})
    LATEX=rubber --pdf

      $(LATEX) $(MAIN)
      biber $(MAIN:.tex=)
      makeglossaries $(MAIN:.tex=)
      $(LATEX) $(MAIN)

      rubber --clean $(MAIN)

      @while [ 1 ]; do             \
        inotifywait $(ALL);        \
        sleep 0.01;                \
        make all;                  \
        make clean;                \
        echo "%%%%%%%%%%%%%%%%%%"; \
        echo "Finished Compiling"; \
        echo "%%%%%%%%%%%%%%%%%%"; \

Bibliography & Glossary/Acronyms

The bibliography source and the definitions of glossary and acronym entries are located in separate files. The bibliography file can either be assembled by hand or exported from e.g. Zotero.
Within the headers there is the hyperref package. It sets clickable references wherever there is a citation or reference to one of the glossaries.
Then defining biblatex we choose between many citation styles (here IEEE). Since we use biber as the backend there are a whole lot of styles to choose from, probably including the one you have to use.


      \section{First Section}
      Example Quotation \cite{aharonov2008quantum} \\
      Example Acronym \acrshort{ITSCM} \\
      Example Glossary \Gls{microservice} \\


Glossary entries in glossary/glossary.tex start with the tag to be referenced with. Then they have a name and a description.

      description={A microservice is a service to be used in a bigger context.}

Acronym entries contain the tag to be referenced, the acronym and its meaning.

    \newacronym{ITSCM}{ITSCM}{IT Service Continuity Management}

Check out Overleaf to get more information about how to use glossaries.

Table of Content & Appendix

Adding a table of content is a piece of cake. Also, adding the appendix is not rocket science either. The appendices are numbered A, B, C... automatically.



      \section{First Section}
      Normal section

        \section{I'm Appendix A}
        Some text
        \section{I'm Appendix B}
        More text

List of Figures & Tables

Let’s add some more Lists to the document. The included packages help to easily add figures and tables. Adding something in the figure or table section will automatically add it to it’s corresponding list using the caption as it’s title.



        \includegraphics[scale=.5]{figures/example_figure.png} \\
        \caption{Example Figure}\label{fig:example_figure}

        \begin{tabularx}{\textwidth}{| p{1cm} | X | p{6cm} |}
            1 & Lorem
              & Ipsum \\ \hline
            2 & Dolorum
              & Est \\ \hline
        \caption{Example Table}\label{tbl:example_table}


The label lets us reference the table like:


A nice header and footer can be added using fancyhdr and resize the page a little using geometry.
Also very handy is the automatically set date (in this setup on the footers left side).

      \usepackage[a4paper, total={6in, 9in}]{geometry}

        \THEDAY. \monthname[\THEMONTH] \THEYEAR}

      \rhead{Top right text}
      \lhead{Top left text}
      \rfoot{Page \thepage}


Language & Encoding

The following packages can be used to set the encoding and a custom language. In this example we use the language ngerman. This will rename most of the headings to that language for example.



Title Page & Abstract

To add a title page add a new section within the document.


        \title{Example Document}
        \author{Matthias Osswald}

          Lorem ipsum dolor sit amet, consetetur...

Useful stuff

The emergency stretch option is very useful to avoid lots of box oversize errors since it allows a little over sizing.
The showframe package shows the box frames on removing [noframe] which also is very handy for debugging.



To include external pdf pages into the document the package "pdfpages" can be used. For including some colors to tables "colortbl" is pretty nice.