Categories
Tools

LaTeX, a text editor for scientists and professionals

Throughout my life I have always paid close attention to the presentation, appearance, of my written texts. In my university days there was not yet Microsoft Office and the texts that I made, which were basically the notes of the subjects, I made them with text editors that did not allow to produce documents of a colorful presence. One such program was WordStar (Fig. 1). Here is where LaTeX makes its appearance.

wordstar

Figure 1. WordStar’s “intuitive” user interface

Years later Microsoft Office arrived and within this office package,  Microsoft Word. Being as it is a great program it always struck me that there were things like using scientific terminology (formulas, connectors, arrows, etc.) that had to be turned around a lot. That I just want to put a formula, why I have to open this tab, and then the other one and then click on a small icon to bring out a measly simbol “>=”?.

LaTeX

A few years ago I learned of the existence of LaTeX  and decided that I was going to use it because it was perfect for the use that I wanted to give to a text editor. During the completion of a master’s degree I had to use it to do several jobs and I already set aside Microsoft Word. One of the advantages of  LaTeX  is that it is a text composition system with tags. On the one hand you see the code in which the embedded tags are, and on the other hand you have the output, usually in pdf format, of the document you are working on.

I have always liked to program and see the code of web pages or programming languages, therefore, I am delighted that it is a program with tags within your code, I feel at home. Whatever a labeled language allows you to conveniently copy and paste snippets and save editing time.

First steps on LaTeX

First you have to get a LaTeX distribution. Like any program, the first thing is to install it and although it is somewhat cumbersome listen to me, in the future you will thank me. A LaTeX distribution is a set of programs and packages that allow us to work without having to configure everything by hand. That is, when you install a distribution you’ll have compilers, a package manager, and other useful things. The most well-known distributions are:

  • TeXLive, cross-platform distribution, available for download on GNU/Linux, Windows and MacOS.
  • MikTeX,a Windows-specific distribution

Once the distribution is installed it is time to download an editor. I use TexStudio a cross-platform editor  available for Microsoft Windows, GNU/Linux, MacOS. There are several on the market that a Google search will allow you to choose another one if you want.

Starting work at LaTeX

First we access TexStudio. Now let’s go to  FILE > NEW FROM PLANTILLA… (Fig. 2) and we chose ARTICLE, with which we create a document already with its start tags to start our document from 0.

latex

Figure 2. Creating a LaTeX document from a template

It is interesting to note that a work in LaTeX is hosted in a folder on your computer and files are added as you edit the document with .tex extension as can be seen in fig. 2. It is not a single document, as can be Microsoft Word, but several and what you send is a compiled document, usually in pdf format.

tex format

Figure 3. Latex document with .tex extension

That’s when we can start creating our document. It is very important, if the document is going to be very large (such as a thesis or a master’s job, to give two examples), to have everything perfectly ordered and localized. That’s why I usually create a folder that I call “img” to add all the images I add to my document, another folder called “docs” where the data sources, documents, etc. are. A huge advantage of LaTeX is that once we have made a created document we can use it to make another one from that same document.

All the code is reused and if we have to add new images what we change is where the image code points, the path of the image. This you think doesn’t save much time and makes you work with a template document that you’re going to find very useful.

Code

This first LaTeX document, the base document has the structure that you can see in the extract below where the tags are appreciated. There are two fundamentals: thedocument, which indicates the start of the document, and    the document, where the document ends. Everything we do would have to be between these two labels. All tags that are started must be closed, otherwise it will fail to compile it. Build errors are often very common when you start working on LaTeX, but over time you’ll make documents more worked and errors will be anecdotal.

\documentclass[]{article}

%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{abstract}

\end{abstract}

\section{}

\end{document}

Anything in square brackets can be edited. That is why the above code can be left as follows:

\documentclass[]{article}

%opening
\title{Ejemplo de documentos de Latex}
\author{Avelino Dominguez}

\begin{document}

\maketitle

\begin{abstract}
All scientific documents have to have a summary of the work. He'd be standing here in Abstract. The name can be edited and put SUMMARY, but it will not be done in this sample job.

\end{abstract}

\section{Insertando imágenes}

\section{Insertando tablas}

\section{Creando fórmulas}

\end{document}

I will create 3 sections in my sample document: one in which I explain how to insert images, another in which I explain how to work with tables, and finally, another in which our friends the mathematicians will be delighted… add formulas. But before we continue let’s create an index on the document that is displayed on the first page. To do this, simply add \tableofcontents to the beginning of the document, with the Fig shown. 4.

Figure 4. Add table of contents to document and output in pdf

1. Inserting an image

Let’s first see how an image is inserted into LaTeX. The first time we use  LaTeX  and add an image can be done as follows but remember that in the future and being code between tags you can copy and paste that code, modifying the direction the image points to or other values of it. What you need to do is go to  ASSISTANTS > INSERT GRAPHIC, as you can see in Fig. 5. Obviously first we have to already have our image in the “imgs” folder to add it to our document. The image has been obtained from free repositories on the Internet, in particular https://morguefile.com/photos/morguefile/9/cats/pop.

latex

Figure 5. Inserting a chart into LaTeX for the first time

The image downloaded from the internet is chosen and click in OK.

latex

Figure 6. Insert Image Dialog Box

Doing so for the first time will give us a compiled error and you will not see the image.

Undefined control sequence. \includegraphics
Label(s) may have changed. Rerun to get cross-references right.

Seeing the error typology UNDEFINED CONTROL SEQUENCE is because the command is not defined. This is because we haven’t loaded a graphics package. This package is called GRAPHIX  and is installed by typing  \usepackage{graphicx} in our document at the beginning of the code. In this way we already see the image that we have downloaded from the internet that can be seen in the Fig. 7. As I had commented previously the images I usually place them inside a folder, hence in the code you can see  imgs/gatonavidad.jpg, that is, we tell LaTeX to look in the imgs folder  imgs for the image to be displayed. If we do not indicate anything LaTeX will search the root folder, the folder where we have the source file with  .tex extension.

Figure 7. Result of inserting an image

It should be said that there are multiple packages available for LaTeX, to add more functionalities to our documents such as adding color to the text, adding header and footer, adding text from an external source, etc., as you work LaTeX documents you will go silvering needs that a simple google search will allow you to know what package you need.

Code

Working with images is often very unpleasant the first few times you work at LaTeX. Why?. Because you come to think that LaTeX puts the images wherever it wants. There are several positioners for placing images such as:

  • Positioner [h] to indicate that the figure appears at the point where it appears in the font. LaTeX is not usually taken seriously by this order and usually ignores it.
  • It seems that the positioner [h!] is a sharper order, but LaTeX usually ignores it as well.
  • We can also use the float package and specify the [H] positioner (note that it is in uppercase), which is the one we will use in our example.

Over time you will realize that there is a fundamental factor in the position of an image… the size, the width of the image. As can be seen in Fig. 7 the width is 14.5 cm, we will change it to a size that fits on the first page, in this case 5 cm and in this way we get the image to “fit” in the space of page 1 remaining as can be seen in the Fig. 8.

latex

Figure 8. Result of inserting an image, playing with the size of it (width)

2. Inserting tables

Tables are also often complicated to understand at first but little by little you will get used to them and the jobs you do can use the code of tables that you have already used in the past. You can also use a wizard to create a table. The route is ASSISTANTS > INSERT TABLE…

latex

Figure 9. Insert Table Wizard

The code obtained would be this by adding some “rubbish data”:

\begin{tabular}{|c|c|c|c|c|}
	\hline 
	LUNES & MARTES & MIÉRCOLES & JUEVES & VIERNES \\ 
	\hline 
	10.5 & 9.7 & 8.2 & 4.9 & 8.9 \\ 
	\hline 
	6.3 & 7.2 & 9.2 & 2.3 & 9.4 \\ 
	\hline 
	6.5 & 7.8 & 9.7 & 2.3 & 6.5 \\ 
	\hline 
\end{tabular} 

As you can see the tag that is used is tabular. The first line tells  LaTeX that you have to start a table and then in square brackets comes “A c” (center c, center) that would be a vertical bar and “ccentered” text. If instead and “c” it says “l”, the text will appear positioned on the left and if we put “r” the text will be positioned to the right. I now put several codes from several tables.

\textbf{TABLA 1}\\

\begin{tabular}{|c|c|c|c|c|}
	\hline 
	LUNES & MARTES & MIÉRCOLES & JUEVES & VIERNES \\ 
	\hline 
	10.5 & 9.7 & 8.2 & 4.9 & 8.9 \\ 
	\hline 
	6.3 & 7.2 & 9.2 & 2.3 & 9.4 \\ 
	\hline 
	6.5 & 7.8 & 9.7 & 2.3 & 6.5 \\ 
	\hline 
\end{tabular} 
\\
\\
\textbf{TABLA 2}\\
\begin{table}[htb]
	\begin{center}
		\begin{tabular}{|l|l||l|l|}
			\hline
			\multicolumn{4}{|c|}{DEMANDAS}{COSTES DE MANTENIMIENTO} \\ \hline
			Empresa 1 & 250 unidades/mes & Empresa 1 & 1,5 \euro (unidad por mes) \\ \hline
			Empresa 2 & 500 unidades/mes & Empresa 2 & 1 \euro (unidad por mes) \\ \hline
			Empresa 3 & 400 unidades/mes & Empresa 3 & 2 \euro (unidad por mes) \\ \hline
		\end{tabular}
		\label{tabla:sencilla}
	\end{center}
\end{table}

\textbf{TABLA 3}\\
\begin{table}[htb]
	\begin{center}
		\begin{tabular}{|l|l|}
			\hline
			EMPRESA & Pedidos por año\\ \hline \hline
			Empresa 1 & 1.46  pedidos  \\ \hline
			Empresa 2 & 1.26 pedidos  \\ \hline
			Empresa 3 &  1 pedido \\ \hline
		\end{tabular}
		\label{tabla:sencilla31}
	\end{center}
\end{table}

What we have done can be seen in Fig. 10.

Figura 10. Distintas tablas en LaTeX

3. Insert mathematical formulas

We come to the exciting of mathematical formulas. The TeXstudio editor has a button bar (button) on the left side and there are some buttons that will allow us to add symbols by clicking on them. In our document we will see the code of the button that we have pressed as can be seen in the Fig. 11.

Figure 11. Insert fraction into LaTeX

Clicking the button on the left will create the code pointing to the arrow. It is convenient to say that if you are highlighted in red (as is the case) if you see it compile it will give you an error because it is a mathematical environment. To solve it is put the symbol $ remaining as shown in fig. 12. \usepackage{amsthm}). Note:if you reappear a form-compiling error:  Undefined control sequence, it is because you have to add mathematical symbol packages (install these 3:  \usepackage{amsmath}, \usepackage{amssymb}, \usepackage{amsthm}).

fraccion

Figure 12. Split output

That is, it all comes down to writing code. Below are several codes that you can copy and paste into your LaTeX documents.

$\dfrac{365.15}{250}$

\begin{center}
$Q^*$ = $\sqrt{\dfrac{2*a*d}{h}}$
\end{center}

\begin{center}
$T$ = $\sqrt{\dfrac{Q_1}{d_1}}$ = $\sqrt{\dfrac{Q_2}{d_2}}$ = $\sqrt{\dfrac{Q_3}{d_3}}$ 
\end{center}

\begin{center}
AC($Q_1$,..., $Q_n$) = a $\dfrac{d_1}{Q_1}$ + $\sum_{i \in N}$ $h_i$ $\dfrac{Q_i}{2}$ = AC ($Q_1$)
\end{center}


By working on your document you will realize how easy it is to write mathematical formulas. You’re going to memorize the way you put subscript (put something later “_” and something else, like 1_2), or put superscript (put something, then “A” and something else, like 1-2), how to put more or less than (write ‘geq’  and  ‘leq’, respectively), etc. With practice you will no longer need to search for codes or documents that you have made in the past. You will remember the name of the command and write it, thus saving precious time. And you will not need to search with your mouse a toolbar button as it can be in Microsoft Word.

In the end the example work with formulas is what you see in fig. 13.

fracción

Figure 13. End

Conclusions

If you are studying whether in the university, postgraduate activity, master’s degree work, etc., LaTeX  is an excellent text editor. Adds a touch of elegance and simplicity to your task. If you want to keep using Microsoft Word it’s fine, but I encourage you to work with LaTex. I’m sure you don’t want to re-edit texts by pressing small buttons instead of editing code.

I hope this publication will help you get to know this text editor. If you plan to start working with it great. You will surely love the idea. And if you don’t like it… you can always go back to the editor you were using until now. It is now your turn, to start making your first document in LaTeX. If you have any questions or consult comment on it in this post and I answer you.

Leave a Reply