Latex

Table of Contents

1 Installation

To see what is your tex home:

kpsewhich -var-value=TEXMFHOME

It should be something like "~/texmf". Putting class and style file into correct path inside that folder will enable global usage of the class. check whether it works or not:

kpsewhich sig-alternate-05-2015.cls

Typically you don't need to update database, but if you want, Command to update the ls-R database

  • texhash
  • mktexlsr

2 Literals

2.1 Symbols

alpha beta
\alpha (α) \beta (β) \gamma (γ) \theta (θ) \phi (φ) \varphi (ϕ) \xi (ξ) \mu (μ) \pi (π) \rho (ρ) \sigma (σ) \epsilon (ε) \partial (∂) \ell (ℓ)
spacing
\quad (\quad) \qquad (\qquad)
logic
\cup (∪) \bigcup (\bigcup) \cap (∩) \vee (∨) \wedge (∧) \in (∈) \notin (∉) \neg (¬) \subset (⊂) \subseteq (\subseteq) \supset (⊃) \supseteq (\supseteq) \le (≤) \ge (≥) \neq (≠) \forall (∀) \exists (∃)
arrow
\leftarrow (←) \rightarrow (→) \Rightarrow (⇒) \Leftarrow (⇐) \Leftrightarrow (⇔) \longrightarrow (\longrightarrow)
accents
\hat{a} (\hat{a}), \bar{a} (\bar{a}) \vec{x} (\vec{x})
math
\infty (∞) \propto (∝) \lfloor (⌊) \rfloor (⌋) \lceil (⌈) \rceil (⌉) \sum_i^j (∑ij) \sum\limits_i^j (\(\sum\limits_i^j\)) \int (∫) \prod (∏) \times (×) \ldots ( \ldots ) \frac{a}{b} (\frac{a}{b}) \sqrt{n} (\sqrt{n}) \overline{abc} (\overline{abc})
mark
\checkmark (✓)

2.2 Font size

It can be used after table environment

\begin{table}
\small
% ..
\end{table}

In org mode:

#+ATTR_LATEX: :font \small

The different size reference

  • tiny
  • scriptsize
  • footnotesize
  • small
  • normalsize
  • large
  • Large
  • LARGE
  • huge
  • Huge

3 General Syntax

3.1 structure

3.1.1 enumerate

\begin{enumerate}
  \item xxx
  \item xxx
  \item xxx
\end{enumerate}

3.1.2 itemize

\begin{itemize}
  \item like this,
  \item and like this.
\end{itemize}

3.1.3 description

\begin{description}
  \item[Word] Definition
  \item[Concept] Explanation
  \item[Idea] Text
\end{description}

3.2 table & figure

3.2.1 table

\begin{table}
\centering
\begin{tabular}{l|r}
Item & Quantity \\\hline
Widgets & 42 \\
Gadgets & 13
\end{tabular}
\caption{\label{tab:widgets}An example table.}
\end{table}

3.2.2 figure

\begin{figure}
  \centering
  \includegraphics[width=0.3\textwidth]{frog.jpg}
  \caption{\label{fig:frog}This frog was uploaded to writeLaTeX via the project menu.}
\end{figure}

`figure*` can make the figure two column

3.3 label & reference

label:

\label{xxx}
\ref{xxx}

\label{xx:yy}
\ref{xx:yy}

3.4 in-pdf comment

\todo{Here's a comment in the margin!}
\todo[inline, color=green!40]{This is an inline comment.}

4 Beamer

#+AUTHOR: Hebi Li
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+BEAMER-FRAME-LEVEL: 2
#+BEAMER_THEME: Madrid
#+OPTIONS: H:2 toc:nil num:t author:t
#+LATEX_HEADER: \lstset{numbers=none,frame=shadowbox, basicstyle=\scriptsize, breaklines=true, basewidth={0.45em,0.3em}, stringstyle=\ttfamily}

Themes

  • Madrid
  • CambridgeUS

5 Packages

5.2 geometry

The the default for LaTeX is to have no indent after sectional headings. Thus the first paragraph will have no indent. To indent it, \usepackage{indentfirst}.

The default article class has too much margin. To change it:

%% this does not work
%% the default should be 1in, 11pt
%% \documentclass[a4paper, margin=1in, 11pt]{article} 
\usepackage{geometry}
\geometry{margin=1in}

5.3 fancyhdr

use headers and footers

  \usepackage{fancyhdr}
  \pagestyle{fancy}
  \fancyhf{}
  \rhead{573 HW1}
  \lhead{Hebi Li}
  \rfoot{Page \thepage}
  %% \lfoot{xxx}
  %% \cfoot{xxx}

5.4 qtree

The [ and ] should be surrounded by spaces!

\usepackage{qtree}
\Tree [ .S [ .S [ .S a ] [ .S a ] + ] [ .S a ] * ]

5.5 listings

5.5.1 Global setting:

Frame:

\lstset{frame=single}
\lstset{frame=trBL} % lowercase for single frame, upper case for double
\lstset{frameround=fttt} % from upper right, clock-wise
%% frame should not be too fancy
\lstset{framextopmargin=50pt,frame=bottomline}

Style:

%% after using courier, the font here will be much better
\usepackage{listings}
\usepackage{courier}
\lstset{basicstyle=\footnotesize\ttfamily\bfseries,breaklines=true}
\lstset{xleftmargin=0.4\linewidth}
%% none, left
\lstset{numbers=left, numberstyle=\tiny}
\lstset{stringstyle=\ttfamily}
\lstset{keywordstyle=\color{black}\bfseries\underbar} % the keyword
\lstset{showstringspaces=false}
\lstset{showspaces=false, showtabs=false} % the annoying space indicators

emphasize

\lstset{language=C}
\lstset{emph={key1,word2}, emphstyle-\underbar}
\lstset{emph={square}, emphstyle=\color{red}
        emph={[2]root,base}, emphstyle={[2]\color{blue}}}
\lstset{morecomment=[s][\color{blue}]{/*+}{*/} % /*+ xxx */ will be in blue!
        morecomment=[s][\color{red}]{/*-}{*/}}

Style arbitrary content:

\lstset{escapeinside={(*@}{@*)}}
\begin{lstlisting}
(*@\color{red}everything here will be red@*)
\end{lstlisting}

5.5.2 Local setting:

\begin{lstlisting}[float, caption=The caption] % using caption will cause the title be: "listing 1: xxx"
\end{lstlisting}
title=this is title
using title will remove the "listing 1:"
backgroundcolor=\color{yellow}

5.6 tikz

see tikz

5.7 ulem

uline
regular underline
uuline
double underline
uwave
wave
sout
strike out
xout
dense cross out
dashuline
dash
dotuline
dot

5.8 TODO pdfcomment

5.9 todonotes

% use the package
\usepackage[textsize=footnotesize, color=green!0]{todonotes}
% HACK: set length so that the paper can have better width for margin
\setlength{\marginparwidth}{1.5cm}

\todo[fancyline]{Here's a comment in the margin}
\todo[noline]{comment}
\todo[inline]{inline comment}

6 Bibliography

cite link (need to load a package like hyperref or url)

@misc{WinNT,
  title = {{MS Windows NT} Kernel Description},
  howpublished = {\url{http://web.archive.org/web/20080207010024/http://www.808multimedia.com/winnt/kernel.htm}},
  note = {Accessed: 2010-09-30}
}