about // doc

Quick Reference of LaTeX

Last modified: Feb, 2014

TeXLive

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

Easy:

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

texhash

A basic Beamer template

 \documentclass{beamer}     
    \mode<presentation>
    {
      \usetheme{Berkeley}
    % check out http://www.pletscher.org/writings/latex/beamerthemes.php for more Beamer themes
      \setbeamercovered{transparent}
      % or whatever (possibly just delete it)
    }
     
    \usepackage[english]{babel}
     
    %\usepackage[latin1]{inputenc}
    % not needed if in English
     
    %\usepackage{times}
    %\usepackage[T1]{fontenc}
    % 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}
    \subtitle
    {} % (optional)
     
    \author{Lijun}
     
    \institute{
    The University of Nowhere}
     
    \begin{document}
     
    \begin{frame}
      \titlepage
    \end{frame}
     
    %\begin{frame}{Outline}
    %  \tableofcontents
    %\end{frame}
     
    \section[s1]{Section 1}
     
    \begin{frame}{Title of frame 1}
    \makebox{\includegraphics[width=45mm]{cmos_dc.png}} 
     \begin{itemize}
       \item
       Item 1
       \item
       Item 2
     \end{itemize}
    \end{frame}
     
    \section[s1]{Section 2}
     
    \begin{frame}{Frame 2}
     
    \begin{columns}[c]
    \column{1.8in} \\
    \makebox{\includegraphics[height=60mm]{b1.png}} \\
     
    \column{1.8in} \\
    \makebox{\includegraphics[height=60mm]{b2.png}} \\
     
    \end{columns}
    \end{frame}
     
    \end{document}

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

\newcommand{\mylogo}{
\begin{textblock}{1}(11,0.2)  % numbers here are in terms of unit length defined above
    \includegraphics[height=10mm]{mylogo.png}
\end{textblock}
}

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.

Reference

BibTeX

BibTeX entry format

A BibTeX entry example is like this

@ARTICLE{sc_eff_tables_v37,
  author = {Martin A. Green and Keith Emery and Yoshihiro Hishikawa and Wilhelm
  Warta},
  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

\usepackage{url}

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

Reference

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,

\bibliographystyle{unsrt}
\bibliography{mybib}

Reference

Tables

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

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

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

More information can be found at CTAN repo.

Fonts

Fontsize

Symbols

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

Math Equations

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

For example,

\begin{align}
S& = 1 + 1 \notag \\
& = 2
\end{align}
  • To write matrices and other arrays

http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/Matrices.html

Common Confusion

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

TeXMaker

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

\begin{verbatim}
#!/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))

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

For example:

\begin{center}
\line(1, 0){200}
\end{end}

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:

\newcommand{\specialcell}[2][c]{
  \begin{tabular}[#1]{@{}c@{}}#2
\end{tabular}}

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.