LaTeX information and cheatsheets.
Switch branches/tags
Nothing to show
Clone or download
Latest commit e513a86 Apr 23, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
media Simplify. Aug 16, 2014
shared @ df4444e synctex, tex variants, index. Aug 23, 2014
.gitignore moved from latex Apr 16, 2013
.gitmodules use https instead of ssh Jul 7, 2013
Makefile synctex, tex variants, index. Aug 23, 2014 CTAN, tlmgr. Aug 24, 2014 Comment on Softcover. Aug 2, 2014
main.bib Simplify. Aug 16, 2014
main.tex form Apr 23, 2017
min.tex Simplify. Aug 16, 2014
shared.sty back to symlink method May 3, 2013

LaTeX Cheat

LaTeX information and cheatsheets.

If you are looking for a template, see It was used to make this repo.

Relies on the submodule for boilerplate.

See the documentation of the submodule for additional installation instructions.

Most important files of this repo:

  • index.tex: the main LaTeX cheat.
  • min.tex: minimal LaTeX file. Useful starting point for minimal examples.


TODO where is LaTeX specified? Is it standardized by an organization, or just book based like early C?


Useful SE questions:


Also called plain TeX to emphasize the difference from LaTeX.

One major design goal of LaTeX is to separate content from form, as TeX itself is very low level, and not very useful for end users.

TODO what is the exact relation between TeX and LaTeX?

The LaTeX language is almost TeX language with libraries, but this is not exact: there are TeX commands that are not available in LaTeX: TODO are there LaTeX commands that are not available in TeX?

LaTeX renames some TeX macros:, most of them by adding the @ prefix, e.g. \@@input.

This cheat shall focus on LaTeX from high level point of view, and mostly on differences between LaTeX and TeX. TeX specific stuff that works analogously in LaTeX will not be commented upon.

While you can get away with high level only for a while, you need to understand the low level stuff to do things like:

  • understand error messages
  • create your own libraries

For a TeX cheatsheet see:

TODO what about output formats? Is it possible to do plain TeX to PDF?


The easiest way to get started with LaTeX is by using a distribution that packs up everything you need.

Some distributions also come with a package manager which automatically downloads sty files as needed.

TeX Live

Most common Linux distribution and recommended on the LaTeX website. Also works on Windows and Mac OS X.

The main ways to install it are:

  • download ISO: Our recommended method, which overcomes all the difficulties of the others.

    This will do the full install:

    curl | bash 

    If you are doing it interactively, downloading via torrent which may be much faster (15 minutes vs 4 hours).

  • a distribution package manager. Easiest method, but on Ubuntu, installs 2009 version, which is too outdated.

    texlive-full is the name of the Ubuntu repo for the TeX Live distro which contains the most packages.

    sudo aptitude install -y texlive-full
  • install-tl script. Has worked for us, but:

    • not very reliable, as it downloads packages one by one, and if one of them times out, the installation fails.
    • not very reproducible, as it may download different package versions from each mirror.
  • from source at:

The full install takes 3-4 hours, ~ 2.5GB on the compressed ISO. Some install methods can install many packages which install only parts of TeX Live, but we think its not worth it: just get the entire package and save yourself future headaches with missing packages later on.


You can get the 14 GB source at:

svn co svn://

It contains:

  • 4 GB of precompiled binaries for many different architectures under /bin, including precompiled tex and pdflatex.
  • the source code for many other utils that must be compiled such as zip and wget.


Most popular Mac TeX distribution. TeX Live based, with Mac only additions.


Most popular Windows distribution.


Includes MiKTeX and other things, such as the TeXstudio editor.

It used to contain the TeXnicCenter editor.


LaTeX has spawned several closely related variant libraries / languages, mostly because in certain aspects it sucks hard. Despite it's shortcomings, LaTeX still seems to be the dominant variant, and has the best tool / community support.

Good info:


Extends TeX.


Its main goal is tu support Unicode out of the box.

Comes in TeX Live full.


Supports embedded Lua scripting.

Just great: part of the TeX community wants to replace Perl, it's traditional scripting language, with Lua. Huge improvement! Python, LSB and much more widely used, anyone?

Allows you to do stuff like:

  j = io.popen(" ls -l")

which pastes Lua output into TeX.

Comes in TeX Live full.


Comes in TeX Live full.

Command line interface

Important options include:

  • -interaction=nonstopmode: don't stop LaTeX on each error. This is useless since what we really want is to fix the source file in the editor. The problem then becomes that it is hard to find the error messages amidst all the noise. A possible solution is texfot.



Compiles LaTeX files into PDFs directly, without going through DVI, thus allowing for better PDF specifics support.

TeX Live 2013 symlinks latex to it.

Some packages only work on pdflatex. TODO: how are those packages written? Does pdflatex have new primitives, or some other mechanism exists?

Some packages implement very PDF specific features, e.g.:


Perl script that provides a very good CLI interface to LaTeX Implication: the default CLI interface is horrible.

This script is a life saver. Use it.

In TeX Live 2013.

Does important stuff like:

  • run latex and bibtex the right number of times to get references right
  • preview, build on save
  • clean only the generated files

I can't wait for it to incorporate texfot.

Make DIV:

latexmk a.tex

Make PDF:

latexmk -pdf a.tex

Clean all temporary files like .aux and .log, but not output files like .pdf or .div:

latexmk -c

Same as -c, but also remove output files:

latexmk -C

-pv: preview: open output in viewer

-pvc (preview continuously): watch and build mode (compile on save with inotify)

Almost any options that pdflatex LaTeX and friends accept can be passed to latexmk and will be forwarded to pdflatex. Some of those may trigger special effects on latexmk in addition to being forwarded. The exact list of options can be found with:

latemk -showextraoptions

Error messages

Very Important!

LaTeX stdout default output is overly verbose and chaotic, making it very hard to find errors.

There however is a simple but non obvious at first sight convention:

errors that prevent compilation are marked with an exclamation mark ! at the beginning of the line, followed by l.XXX indicating the line.

For example if you forget to use a package with a line like:

The command \asdfqwer is undefined, and this line is very very very very very very very long.

The error will look like:

! Undefined control sequence.
l.266   The command \asdfqwer
                            is undefined, and this line is very very very ...

See how the line breaks at the column of the error.

So you know that the problem is at line 266, around \asdfqwer.

The line number does not need to be the line immediately following the exclamation point.

For example, if you forget to supply macro parameters:


The error will look something like:

! Paragraph ended before \label was complete.
<to be read again>

meaning that the error occurred around line 267.

Filter only errors

Good no external dependencies one liner option:

pdflatex a.tex | perl -0777 -ne 'print m/\n! .*?\nl\.\d.*?\n.*?\n/gs'

Best external dependencies option. In TeX Live but not yet in 2013 ISO:

Basically a super advanced heuristic regex filtering script.

Warning messages

  • <to be read again>: TODO what is it?
  • overfull hbox: a single word is too long for the line, and LaTeX does not know how to break it up, e.g.: AVeryVeryVeryLongClassName.

sty search path

For a single user first find:

kpsewhich -var-value=TEXMFHOME

Commonly ~/texmf/ in Linux.

For multiple users use:

kpsewhich -var-value=TEXMFLOCAL

Commonly /usr/local/share/texmf/ in Linux.

Note that TEXMFHOME and TEXMFLOCAL are not regular environment variables.

The other paths which you should not touch are:

kpsewhich -var-value=TEXMFMAIN
kpsewhich -var-value=TEXMFDIST

Main being default stys, usually at /usr/share/latex/texmf and dist being the one managed by your distro (texlive), usually /usr/share/latex/texmf-dist/.

Under Ubuntu, those values are determined in the following settings file: cat /usr/share/texmf/web2c/texmf.cnf

Next, you should use the following subdir structure:

"`kpsewhich -var-value=TEXMFHOME`"/tex/latex/NAME/NAME.sty
"`kpsewhich -var-value=TEXMFLOCAL`"/tex/latex/NAME/NAME.sty

But I am not sure if the NAME subdir is imposed or not since putting the sty anywhere tex/latex worked for me. Only the basename of the seemed to matter.

So at the first usage you will want to:

texmfhome="`kpsewhich -var-value=TEXMFHOME`"
mkdir -p "$texmdfhome"
mkdir -p "$texmdfhome"/tex/
mkdir -p "$texmdfhome"/tex/latex/

And for every new sty you create (clone) a new dir there with the same name as the sty.

It may be necessary to update package database with:

sudo texhash

texmf stands for Tex Meta Fonts. My guess: an historical name that was a path for fonts which was extended to .sty files.

Environment variables

  • TEXINPUTS: colon separated list of directories under which LaTeX will search for all kinds of inputs, including LaTeX files and images.


env TEXINPUTS=./media//:~/tex/:

Note that:

  • you can give paths relative to the current directory with a dot as in: ./media//
  • you can give paths relative the home directory with a tilde as in: ~/tex/
  • a double trailing slash as in ./media// means: search recursively under ./media/
  • a trailing colon at the end of the entire variable as in ~/.tex/: means: append after the default search path.


Allows forward and backward searches: give a TeX line, and find the corresponding PDF page to view it or the inverse.

It is quite painful to use it sometimes, and the docs are not very good, but it is the only solution.

First you must make the compiler produce SyncTeX information with the -synctex=1 option. This only needs to be done once on the last pass, and can be done through latexmk:

latexmk -synctex=1 main.tex

This will generate a main.synctex.gz files which contains the mappings between lines and PDF positions.

Call Synctex with:

synctex "$LINE:$COLUMN:$TEX_FILE" -o "$PDF_FILE"

Concrete example:

synctex "10:1:rel/path/to/a.tex" -o "path/rel/to/a.pdf"

Make sure that the output file (PDF) is in the same directory as the .synctex.gz: I have not been able to get it to work otherwise:

Sample output (in case of success):

This is SyncTeX command line utility, version 1.2
SyncTeX result begin
SyncTeX result end

TODO what does each field mean? I think x and y are positions in the page, h and v the actual rectangle corresponding to the line (tools like Texmaker highlight a rectangle inteligently, not just a point).

You must then parse that output to get the value you want.

POSIX sh example of how to parse to get the page:

echo "SYNCTEX_OUT" | awk -F: '$1 ~/Page/ { print $2; exit }

Okular can call SyncTeX and parse it's output for you if you give it a special input path of the form:

okular --unique '/path/to/main.pdf#src:123/path/to/main.tex'

where 123 is the current line number. TODO where is documented?

Highlight exact point in output page for the given input input line on forward searches: not yet possible, feature request at:


Command line tool to access LaTeX documentation files.

Searches some path (TODO which), and opens a compiled PDF output documentations.

The advantage of having PDFs over in terminal man pages is that it is then possible for the manual to contain live examples.

Documents both LaTeX internals and packages.

Get documentation for a package:

texdoc hyperref

There are also documentation on LaTeX in general:

texdoc source2e
texdoc latex2e
texdoc tex

In TeX Live 2013.


Convert LaTeX to MathML.

HTML output

There are many tools that try to do LaTeX to HTML output, but it is not easy to get it right as it was not designed with reflowable content in mind.

The most realistic approach is to try convert only a subset of LaTeX, which is what tries to do.



Easy to use open source cross platform LaTeX editor. Qt based. Good choice for beginners:

sudo aptitude install -y texmaker


Popular Windows only open source editor, can use either MiKTeX or TeX Live.

Used to be included in the proTeXt distribution, but was recently replaced by

Lint tools


De facto standard package index provider.

Package URLs of form:

Contains a web interface for browsing the files in each package under, e.g.

Does not appear to host version control systems like Git or have pull requests: you have to email patches to the author or find in the docs where he keeps the dev code tracked.

Does not appear to offer fixed versions: only the last thing that was updated by the author, so in theory the latest stable.

All CTAN submissions appear to be human reviewed and categorized into the tex-archive tree before inclusion:


TeX Live package Manager.

Easily download missing packages from the command line.

TODO: where does it finds the packages? CTAN?

TODO: is it possible to fix package versions like in a Gemfile file? It not, never use this, since if you can't specify versions, it is not possible to reproduce bugs, and bugs may crop up on regressions! Always use a fixed year ISO if that is the case.

It seems that Debian devs are against making it work out of the box so as to not conflict with apt-get. I don't understand how this can be considering all the other languages with package managers (Ruby gem, Python pip, etc.).


  • how to add an hrule after every environment of a type?
  • how to create theorem environments with label (bold Theorem thing at beginning) given in source and not in definition
  • how to center all rows in a tabular without specifying how many rows are there ([c] instead of [ccccc], which might change afterwards)