How to write a paper using LaTeX

*UPDATE (8.9.18)  – I recently discovered a wonderful online LaTex writing tool called overleaf. I strongly recommend it over TeXMaker (presented below). It offers a nice and clean user interface along with a great platform for collaborating with coauthors which includes change tracking,  .git, and more. Nonetheless, the template provided here can be uploaded and used there as well. Here is a registration link to overleaf.

 

Getting started with LaTeX can be a little discouraging. LaTeX has a learning curve, but, its totally worth the effort!

This post contains some tips and tricks for LaTeX beginners and will help you write your first paper using LaTeX.

Skip to the gist at the bottom of the page for the download links without detail.

 

Step 0:  The TeX distribution

If you are working on windows (like me) you need to install a TeX distribution (like MiKTeX) first .  The editor is used to create and edit the TeX code, while the TeX distribution is used to compile and create the pdf file.

So install MikTex.  Make sure to do this before you install the editor. This way you won’t have to worry about configuring the editor to use it.

 

Step 1:  The editor

I work with Texmaker.  I found that it has some great customization features That I really like.

So, install Texmaker.

After you install it I recommend doing the following:

  1. Create a build subdirectory automatically:  Options -> Configure Texmaker – >  check the box “use a “build” subdirectory for output files”.   When you compile a TeX file it creates the pdf file but it also creates some other files and it becomes a mess very fast. working with a build subdirectory will automatically put the pdf (and the other files) there.
  2. Built-in pdf viewer:  If you are working with one screen you will find the embedded built-in viewer very efficient. If you are working with two screens (like me) then make sure that the “embed” checkbox is unchecked and drag the viewer window to the secondary screen.
  3. External viewer: If you want to preview your pdf using an external viewer, and you followed step 1, you need to change the external viewer path to ” “Path to your viewer” .\build\%.pdf”. I use Adobe pdf reader so for me its :   “C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe” .\build\%.pdf. Just remember to close it before you recompile the document (you will get an error unless you use a reader that allows updates and refreshes)
  4. Adjust font size:   options -> Configure Texmaker,->  editor (on the left) ->  editor font size. I like 11.

Step 2:  The Paper

Now that you have everything set up you can start working on your paper.

Before you do, I highly recommend watching these youtube tutorials by Michelle Krummel. It will help you understand the basics.

Now that you know the basics you can simply download this template and read the following explanations without actually having to do anything.

  1. Download this template.
  2. Extract the template files into your working directory (keep the zip file for future papers).
  3. Open “main.tex” in TexMaker.
  4. Run a quick build.
  5. BOOM ! Your first paper in LaTeX is ready! (assuming that you had no errors)

Now let us try to understand what is going on in the template:

The Preamble

The preamble includes all lines  that come  before:

\begin{document}

In the preamble, you define many things.  Usually, you will define the type of document, which packages to use and other custom definitions.

The document class is defined by :

\documentclass[10pt,twocolumn,letterpaper]{article}

Here you can set the paper size, one or two columns, font syze etc.

I included some useful packages. There are surely more packages that you will need in the future but this will get you started.

The document

The document is whatever comes between

\begin{document}

and

\end{document}

You can basically start writing your entire document here.

I recommend working slightly differently and use separate files for the different sections.

Sections

Most papers have the same general structure (names may change according to the field and other sections may be added) :

  • Abstract
  • Introduction
  • Related Work
  • Approach / Method
  • Results
  • Summary / Conclusion

In the template, each section has its own .tex file inside the “sections” subdirectory.

The following lines basically insert these separate .tex files into the main document.

\input{sections/abstract}
\input{sections/intro}
\input{sections/related-work}
\input{sections/approach}
\input{sections/results}
\input{sections/summary}

In TexMaker you can see them on the left. Simply clicking them will open each file for editing.

If you want to be able to compile the main file (without having to go back to it each time you edit a section) you can simply choose the Options -> Define current document as ‘Master Document’  option (make sure you are editing the main document when doing so).

Assets

Assets are valuable things (by definition). In our case, it usually refers to images and figures but can include any other type of file that your .tex file uses.  In the template, I created an assets folder. You can simply place all your images in it.

The line

\graphicspath{{assets/}}

makes sure that the compiler will know where to find our images.

Figures and Tables

To insert a figure into the document you can use :

\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{test.jpg}
\caption{This is how you include an image}
\label{fig:approach} %always put label after caption
\end{figure}

Here the image name is “test.jpg” (it is located inside the assets directory).  The label you give here is the string you will use in order to reference this figure in the text ( in this case its “fig:approach”).

I recommend adopting a labeling method that uses a colon between the type of element you want to reference and its description.  In this case “fig” is the type and stands for figure and “approach” is the image description (I use “sec” for sections, “eq” for equations and “table” for tables).

To reference this figure in the text  use

\ref{fig:approach}

TexMaker will help you with some autocomplete options so make sure to give short, yet meaningful descriptions.

 

Tables are super important in scientific work and I must say that I find styling them super annoying in LaTeX.

To insert a table use the following code:

    \begin{table}[t]
	\centering	
		\tabcolsep = 0.01\textwidth
		\begin{tabular}{| m{0.1\textwidth} | M{0.15\textwidth} | M{0.15\textwidth}|} 
			\hline
			\centering\textbf{Method} & \textbf{Criterion 1} & \textbf{Criterion 2}
 			\tabularnewline
 			\hline
 			Method 1 & score 1 & score 2 \\
 			Method 2 & score 1 & score 2 \\
 			Ours  & The best & The best \\
		    \hline
		\end{tabular}
	\caption{Example of a table }
	\label{table:example_table}
\end{table}

Make sure that you have the following line in the preamble

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

I won’t go into detail here. I refer the interested reader to this page.

If you find yourself lost, you can try this online LaTeX table generator.

Math

You will mostly insert math into the text using equations but sometimes you will want to insert math inline into the text.

For inline text, simply use the $ sign to open and close the math you wish to write, like this:

$x^2 + y^2 + z^2 = R^2 $

If you need a numbered equation then simply use:

\begin{equation} \label{eq:circle}
x^2 + y^2 + z^2 = R^2
\end{equation}

Here is a tip – if you have a really complicated equation and you are not a LaTeX Guru yet, you can use some software tools to help you get the code. I used MathType to style my equations and then exported the LaTeX code.  There are also some free online tools like this one.

Footnotes

I was working on a document with some collaborators and found that using tagged footnotes useful (though, not as good as review mode in Microsoft word). If a collaborator wants to write a comment regarding a specific region of the text you can simply create a tag for him using:

\newcommand{\IBS}[1] {\footnote{Itzik: #1}}

Now wherever you write

\IBS{My footnote comment}

You will get a footnote with your name followed by a colon in the beginning of the comment.

References

I use BibTex.

To insert the bibliography simply use

\bibliographystyle{plain}
\bibliography{references}

In your “reference.bib” file you place your references.

For example here is a citation of one of my papers :

@article{ben2017graph,
title={Graph Based Over-Segmentation Methods for 3D Point Clouds}
author={Ben-Shabat, Yizhak and Avraham, Tamar and Lindenbaum, Michael and Fischer, Anath}
journal={arXiv preprint arXiv:1702.04114}
year={2017}
}

To cite it in the text simply use:

\cite{ben2017graph}

I use google scholar a lot, you can get your citations from there by clicking cite (now its the ” symbol to the bottom left of each entry) and click BibTex to get the code. PAY ATTENTION – google scholar doesn’t get the citations right about 60% of the time. I had to manually edit a lot of references so make sure to do it for each entry as you insert it (and not when you finish the paper because it is very tedious).

Step 3:  Becoming a LaTeX Guru

Well, I just recently started so I am still working on this step. I think that the best way to do this is simply to use LaTeX a lot.

If you find yourself stuck trying to do something simple (which in the beginning happens very often) I recommend the following helpful links:

 

The Gist

If you already read everything or just want the important links without having to scroll through. I summarized it here: