User Tools

Site Tools


About LaTeX

The recommended way for working with LaTeX is Overlaf, as it can be used both online (no installation necessary), or offline (by cloning the underlying git repo and setting up your environment as described below).

LaTeX Installation

On Windows

To create LaTeX documents on Windows, you need to download and install the following programs (in that order):

  1. Adobe Reader or Foxit Reader- PDF file reader
  2. Ghostscript v9.05 (32 or 64 bit)- An interpreter for the PostScript language and for PDF (on a 64-bit system, you can use 64-bit Ghostscript with 32-bit MiKTeX)
  3. GSview v5.0 (32 or 64 bit) - GSview is a graphical interface for Ghostscript under MS-Windows (on a 64-bit system, you can use 64-bit GSview with 32-bit MiKTeX)
  4. MiKTeX v2.9 (32 bit) - A TeX implementation for the Windows operating system
  5. Texmaker - A cross-platform text editor that works both on Windows and Linux

The version numbers refer to program versions that I have installed on Windows 7. If installing newer versions, be sure to check for compatibility between packages !

A few notes on MiKTeX installation:

  • I have chosen to install just the basic package using the “Basic MiKTeX” installer. Missing packages can be downloaded automatically, as needed.
  • After installing the basic package, run MiKTeX Update, choose a remote package repository (it's probably a good idea to choose one that's geographically close) and complete the updating process.

And that's it ! You are now ready to go on to the section LaTeX "Hello World" and start typing :)

On Linux

To install Latex on Ubuntu, open terminal and type:

$ sudo apt-get install texlive

Next you will need to install text editor. We recommend using Texmaker or Emacs. Texmaker is designed to work with Latex, while Emacs is advanced editor which can be set to work with Latex.

LaTeX Examples

LaTeX "Hello World"

To create the simplest possible LaTeX document, open WinEdt (or TeXnicCenter), create a new document, save it as 'helloworld.tex' and enter the following text:

 % helloworld.tex - My first LaTeX example
   Hello World!

Save the changes, click on the 'LaTeX' toolbar button, and then click on the 'dvi2pdf' button. Your PDF file reader should open automatically, displaying the PDF version of your document. For further examples check out this tutorial by Andrew Roberts.

Using Croatian Characters

To use Croatian characters (č,ć,đ,š,ž) in your LaTeX documents, add the following lines to the preamble (after \documentclass and before \title):


Make sure that you are editing your document in utf8 mode (on Linux, this is the default, while on Windows you might have to adjust some settings in your editor). Including the above packages also takes care of language specific behavior (e.g. figures labeled “slika” etc.)

Working with graphics

\includegraphics*[viewport=30 30 120 120]{myimage.png}

Sizing images

pdflatex: LaTeX => PDF

Pdflatex recognizes the following image file types: PNG, PDF, JPEG.

Converting EPS files to PDF using epstopdf (located in the MiKTeX bin folder):

$ epstopdf input.eps

Cropping pdf files (removing whitespace):

$ pdfcrop input.pdf

Converting EPS files to PNG using ghostview:

$ gs -r300 -dEPSCrop -dTextAlphaBits=4 -sDEVICE=png16m -sOutputFile=fig.png -dBATCH -dNOPAUSE fig.eps

Exporting Matlab plots

The recommended format for exporting plots from Matlab is .pdf. The exported images need to be cropped. On Windows, this can be achieved using the PDFcrop package. Install the package through the MiKTeX package manager, and just issue the command:

c:\>pdfcrop figure_name.pdf

If you get an error saying “Perl interpreter could not be found”, install a Perl interpreter, e.g. Strawberry Perl.

If you get the error “Perl script not fund”, try refreshing the FNDB (available through the Miktex Settings dialog).

Miscellaneous tips and tricks

Reducing PDF file size

Included graphics have by far the biggest impact on file size. One option is always to create lower resolution versions of your images. Alternatively, you can use Ghostscript to compress the graphics in the PDF document you produced. The command to do this is:

gswin32c.exe -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -sOutputFile="outfile.pdf" -dNOPAUSE -dBATCH "infile.pdf"

The above comman is taken from this very nice tutorial on LaTeX and PDF.

Working with tables

Editing tables by hand in a LaTex document can be a pain.

For simple tables, the best thing to do is keep your data in a .csv (character-separated values) file, which can be conveniently edited in OpenOffice or MS Word. The .csv file can then be included in your LaTeX document using the csvsimple package.

For more advanced use-cases, check out the pgfplotstable package (supports the booktabs table formatting package) and datatool package.

Typesetting source code (with syntax hilighting)

Note: Do not overuse this feature, i.e., do not simply put all of your code in a document (thesis, paper or whatever). In the main document, include just the most relevant code snippets. Whole source files can be added to the Appendix, but please restrict yourself to include only what is absolutely necessary.

Use the Minted package with Pygments syntax hilighting.

To get started, try out the following example, which is also available as an Overleaf template:

% These examples are based on the package documentation:
\title{Source Code Highlighting with Minted in LaTeX}
\section{Hello World!}
int main() {
  printf("hello, world");
  return 0;
\section{Math in Source Code Comments}
  Defined as $\pi=\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the perimeter
  of an $n$-sided regular polygon circumscribing a
  circle of diameter $d$.
  const double pi = 3.1415926535

On Overleaf, everything is already set up, so you can just copy-paste from the example above and you should be ready to go. If you are using Texmaker, you need to pass additional options to the LaTeX compiler, as described below.

Setting up compilation options in TeXMaker

Minted requires the -shell-escape option to be passed to the LaTeX compiler. To set this up in TeXMaker, go to Options→Configure texmaker and add the -shell-escape option under Commands→PdfLaTeX:

Options->Configure texmaker->Commands

Also set up the Quick Build→User command line as follows:

pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex |bibtex %.aux|pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex |pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex 

Options->Configure texmaker->Quick Build



Writing LaTeX documents


Tools for editing and manipulating LaTeX files

  • MiKTeX - A LaTeX implementation for MS Windows.
  • Texmaker - A free, open source, cross-platfrom (Windows, Linux and Mac) text editor.

Tools for manipulating PDF files

LaTeX and git

software/latex_intro.txt · Last modified: 2017/06/02 13:38 by admin