about // doc

Quick Reference of LaTeX

Last modified: Feb, 2014


I use TeXLive for anything related to LaTeX in all my Linux machines. Installing from the source rather than distribution’s repositories is actually preferred.

Get TeXLive

I use rsync to grab the TeXLive source. The advantage is I can easily update the source to the latest version with rsync. Here is the rsync command:

rsync -a --delete --progress  rsync://mirror.unl.edu/ctan/systems/texlive/tlnet/ $HOME/texlive_src

Refer to this link for further information and this link for more mirrors.

Install TeXLive


cd $HOME/texlive_src
perl install-tl

Just follow the instructions after that.

Install and update packages

The program ‘tlmgr’ helps you with that:

tlmgr search [keyword]
tlmgr install [package_name]

To update TeXLive:

tlmgr update --self
tlmgr update --all

Install a LaTeX package

Sometimes when you compile a LaTeX source, there may be error messages like

! LaTeX Error: File `esint.sty' not found.

It means the style file “esint” is not found in the system. This can be resolved by installing package ‘esint’.

Method 1: use repository

In TeXLive, command tlmgr is used to manage TeX packages.

tlmgr install esint

A somewhat detailed usage of tlmgr can be found at tlmgr@TeXLive, or simply

man tlmgr

Method 2: install from source

Just download ‘esint’ from CTAN, unzip to a local directory like /home/user/tex/, and run command

texhash home/user/tex

Or copy the downloaded package to “texlive/201X/texmf-local/tex/latex/local”, and do


A basic Beamer template

    % check out http://www.pletscher.org/writings/latex/beamerthemes.php for more Beamer themes
      % or whatever (possibly just delete it)
    % not needed if in English
    % Or whatever. Note that the encoding and the font should match. If T1
    % does not look nice, try deleting the line with the fontenc.
    \title[title's short name]
    {The Status of My Project}
    {} % (optional)
    The University of Nowhere}
    %  \tableofcontents
    \section[s1]{Section 1}
    \begin{frame}{Title of frame 1}
       Item 1
       Item 2
    \section[s1]{Section 2}
    \begin{frame}{Frame 2}
    \column{1.8in} \\
    \makebox{\includegraphics[height=60mm]{b1.png}} \\
    \column{1.8in} \\
    \makebox{\includegraphics[height=60mm]{b2.png}} \\

Logos in Beamer

Beamer has “\logo” command, but I use package “‘textpos’”. Basically this package give users more control over the position of a “box” in LaTex text.

First enable this package:

\usepackage[absolute, overlay]{textpos}

Here “overlay” makes logos appear above Beamer’s text layer. Then define a macro that inserts logos

\setlength{\TPHorizModule}{10mm} % horizontal unit length
\setlength{\TPVertModule}{\TPHorizModule} % vertical unit length
\textblockorigin{1mm}{1mm} % define origin at the upper left corner

\begin{textblock}{1}(11,0.2)  % numbers here are in terms of unit length defined above

This draw a logo at the upper right corner. The code is self-explanatory.

TIPS: Do not use “_”, “-“, “.” and so on for macro names, or errors occur.

Insert command “\mylogo” in pages that need the logo.



BibTeX entry format

A BibTeX entry example is like this

  author = {Martin A. Green and Keith Emery and Yoshihiro Hishikawa and Wilhelm
  title = {Solar Cell Efficiency Tables (Version 37)},
  journal = {Prog. Photovolt: Res. Appl.},
  year = {2011},
  volume = {19},
  pages = {84}

Note that

  • In author field, one should specify names like “A and B and C and D” instead of “A, B, C and D”. The former will be automatically formatted to “A, B, C and D” in Tex compilation (and appear like that afterwards), while the later will give errors in compilation.

  • All characters except the first one in “title” field will be decapitalized after being processed by BibTeX. To keep the default style, one can encapsulate the part with {}. One can also use LaTeX macros within {} in these fields too. For example,

@MISC{example1, author = {A and B and C}, note = {{\LaTeX} in {X}}, year = {2012} }

  • To type math expressions in BibTeX, use “$…$” environment.

  • To insert URL in BibTeX entry, don’t forget including


in the LaTeX preamble. Otherwise there will be compiling error.


BibTeX citation order

Question: By default BibTeX orders citations alphabetically (by the last name of first author) in “plain” bibliography style. How to order citations by order of appearance?

Answer: Use ‘unsrt’ (unsorted?) bibliography style. For example,




  • Use package hhline to extend the “\hline” functionalities. Enable it by adding

in the preamble. Package website is http://www.ctan.org/pkg/hhline.

  • Use \cline to draw row line across specific columns. For example:
aaa & bbb & ccc \\ \cline{1-2}
ddd & eee & fff \\ \hline
  • Change background color in table cells: use package ‘colortbl’.
\rowcolor{yellow} aaa & bbb & ccc \\ \cline{1-2}
ddd & eee & fff \\ \hline

More information can be found at CTAN repo.




  • To write “V~IR” in latex:
V \sim IR

Math Equations

  • To supress the numbering for certain lines between “‘align’” environment, use

For example,

S& = 1 + 1 \notag \\
& = 2
  • To write matrices and other arrays


Common Confusion

  • Brackets that matches the text size inside:
\left( xxxxx \right)
\left[ xxxxx \right]
\left\{ xxxxx \right\}


TeXMaker is an excellent TeX IDE I used. However, in my 64-bit machine, I have to do a few hacks to make it work.

sudo ln -s /usr/lib/x86_64-linux-gnu/libtiff.so.4 /usr/lib/libtiff.so.3
sudo ln -sf /usr/lib/x86_64-linux-gnu/libjpeg.so.8 /usr/lib/libjpeg.so.62

Miscellaneous Commands

Insert code blocks in LaTeX

The easiest way is to put them in ‘verbatim’ environment

#!/usr/local/env python

import numpy as np 
import matplotlib.pylab as plt

x = np.linspace(0,6,100)
plt.plot(x, np.sin(x))

  • Insert a horizontal line with ‘\line’ command. Syntax:
\line(direction_x, direction_y){length}

For example:

\line(1, 0){200}

draws a line with direction (1,0) and length of 200.

  • Insert a new line in a table cell

First define a “new command” like:


in preamble. To use it:

Foo bar & \specialcell{Foo\\bar} & Foo bar \\    % vertically centered
Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule
Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule

Refer to this post for details.