Don't know how to do something in L^{A}T_{E}X ? Look here first. Below is an index of various L^{A}T_{E}X constructs.
In order to use this index, just look for an English term (either manually scroll through in alphabetical order, or use your browser's Find facility) which describes what you want to do.
bar (math):
To get, say, "Y bar", use \bar{Y}. However, the bar will be rather short. To get a wider one, use \overline. For example,
\overline{(\bar{A}+\bar{C}+\bar{D})(\bar{B}+\bar{E})}will generate
____________ _ _ _ _ _ (A+C+D)(B+E)
bibliographies:
\begin{thebibliography}{} \bibitem{anderson} T. Anderson {\it et al}. ``A Case for Networks of Workstations,'' {\it IEEE Micro}, 54-64, February 1995. \bibitem{mpi} M. Snir. {\it MPI: the Complete Reference}, MIT Press, 1996. \bibitem{trivedi} K.S. Trivedi, {\it Probability and Statistics with Reliability, Queuing and Computer Science Applications}. Prentice-Hall, 1982. \end{thebibliography}Here is an example of references to bibliography items:
In the last few years there has been a tremendous growth in interest in the use of networks of workstations (NOWs) as engines forparallel. processing \cite{anderson}. Among the most important advantages of NOWs is their economic feasibility; they are constructed from off-the-shelf, ``commodity'' components; new nodes can be added very easily; and good infrastructure software is available, such as \cite{mpi}.To cite the number of a specific page, section or whatever, precede the citation name with the desired information in brackets, e.g.
Durrett \cite[page 76]{durrett} references a model due to Chung and Lu,
There are variations, e.g. for using the author-year format like Smith (2001).
bibtex:
bibtex x(Note that the .bib suffix is not there.) Then one runs pdflatex or latex on x.tex as usual. You may need to run each of these commands more than once, so that all the cross-references are resolved properly.
You use \cite{} as above.
Place the line
\bibliography{x}in x.tex where you would have placed the bibliography. If you are using a special bibtex style, say mathbib, you may need a line
\bibliography{mathbib}
preceding the above line.
In many cases, a ready-made .bib entry for the given citation is already available, alleviating you of the need to write one. The DBLP database may have an entry, for instance. Or try plugging your citation info into Google, with the word "bibtex," or with "Export Citation."
Here is a Makefile for a file CL.tex:
CL.pdf CL.aux: CL.tex CL.bbl pdflatex CL.tex CL.bbl: CL.bib bibtex CLAs to the format of the file x.bib, there are many examples on the Web, but here are a couple:
@inproceedings{cozman, author = "F. Cozman and I. Cohen", title = "Unlabeled data can degrade classification performance of generative classifiers", booktitle = "Proceedings of the Fifteenth International Florida Artificial Intelligence Research Society Conference", year = "2002", pages = "327--331" } @inbook{hall, author = "Alistair Hall", title = "Generalized Method of Moments", publisher = "Oxford University Press", pages = "31", year = "2005" }As you can see, there are various categories for conference proceedings, books and so on. Moreover, many research sites already set these BibTeX entries up for you, very convenient.
Here is a good quick reference on the various bibtex entry types, such as Book, Article, Techreport and so on.
By the way, all this also produces a x.bbl file. When all your references are ready, you can comment out your BibTeX lines in your main source file x.tex, and then add x.bbl, together with the non-BibTeX \bibliography heading, into x.tex, thus keeping everything in a single file.
binomial coefficients:
\usepackage{amsmath}near the beginning of your file. But then \cases must be changed if one has that too. So, I think it's best just to use arrays, e.g.
The notation $ \left ( \begin{array}{c} 8 \\ 3 \end{array} \right )$ means ``n choose k.''blank space:
Suppose you wish to put a single-character blank in your document, say a blank entry in a table. Use `\ ', i.e. a backslash followed by a blank space. This also works to suppress extra space after the period after an abbreviation, i.e. to tell L^{A}T_{E}X not to consider this the end of a sentence.
Use \hspace to insert a variable amount of blank space.
{\boldmath $x^2$}
If you are already in math mode, use \mathbf, etc.
braces:
cursive script fonts (mathematical):
In math mode, to get cursive script, use \mathcal, e.g.
$\mathcal A$
for a curse ("calligraphic") capital A.
cases (mathematical):
Here is how one could express more symbolically the statement, "1 sub Q (t) is equal to 1 or 0, according to whether t is a member of the set Q":
1_Q(t) = \cases{ 1, & if $t \in Q$\cr 0, & if $t \notin Q$\cr }
If you are using the amsmath package, then change the above to
1_Q(t) = \begin{cases} 1, & \text{if $t \in Q$}\\ 0, & \text{if $t \notin Q$} \end{cases}
Include a line like
\usepackage{color}
Then for example
\color{blue}
will make all text (and figures, etc.) from here onward blue. There is also \pagecolor for background color, \textcolor for a one-time text-color change, etc.
For example, to get the sentence "Today is Monday" in red, write
\textcolor{red}{Today is Monday.}
Several primary colors are predefined (red, green, blue, cyan, magenta, yellow, black and white), and you can use \definecolor to make use of X11 windows colors, "mix" your own colors from the primaries, etc.
Note that the colors may not show up with xdvi but will show up in the Postscript or PDF files.
date ("article" style):
derivatives (math)
\frac{du}{dt}For partial derivatives, use the \partial construct, e.g.
\frac{\partial u}{\partial t}For the vector of partial derivatives ("del"), use \nabla. In evaluating a derivative at a certain value, using the "vertical bar" notation, do as in this example:
\frac{dx}{dt} \Big |_{t=1}double-spacing:
\renewcommand{\baselinestretch}{2}
"dropped" (occupies several lines of text, as in an old-fashioned novel) initial capital letter in a paragraph:
\dropping{3}{O} nce upon a time, there was...
will produce a large `O' which extends through the first 3 lines of the paragraph.
enlarging the font size:
Do {\LARGE NOT} wait until you are finished writing your program to add comments to it.
equations (math):
\begin{equation} \end{equation}The resulting equation will be numbered. If you don't want numbering, use eqnarray and \nonumber.
Note carefully: Do not leave blank lines in the equation environment, as it will cause an error.
escaping special characters:
floor, ceiling (math):
Use \hat, or \widehat.
hyperlinks:
You can get hyperlinks within your document--in the table of contents, equation references etc., as well as to external Web links--by including a line
\usepackage{hyperref}
near the beginning of your document. By the way, if you use \tableofcontents make sure to use it in that form instead of \tableofcontents{}.
implication arrow:Suppose you have an PDF file. x.pdf. (JPEG is OK too.) Then at the beginning of your document, tell L^{A}T_{E}X to use the graphicx package:
\usepackage{graphicx}
At the place in the document at which you wish to insert your figure, type, for example:
\begin{figure}[tb] \centerline{ \includegraphics[width=3.2in]{x.pdf} } \caption{your caption} % optional \label{label} % optional \end{figure}
Note the width option for \includegraphics. The latter command has various other options, including angle for rotation of the image, e.g. angle 180 for a reversal.
Run pdflatex instead of latex.
If you get an error message of "no bounding box": Run the bb command (if you have it) on your PDF file, producing a file with .bb suffix; it will contain the bounding box information. Use that as in this example:
\includegraphics[bb=0 0 504 504,width=2.5in]{edhist.pdf}
You may need to remove an option:
\usepackage{graphicx}
infinity (math symbol):
installing .sty files or packages:
Say there is a great L^{A}T_{E}X package on the Web that you wish to install.
In the case of an individual .sty file, say x.sty, do the following (for Unix-family OSs). First find the base directory, something like /usr/share/texmf-texlive/tex/latex/base. Then:
sudo -s cp x.sty /usr/share/texmf-texlive/tex/latex/base chmod go+r /usr/share/texmf-texlive/tex/latex/base/x.sty texhash
The case of a full package is only slightly more involved. Say the package is named x. Then typically you download files x.ins and x.dtx into some temporary directory, and then run
latex x.ins
This will produce a file x.sty. Such files are stored, for example, in /usr/share/texmf/tex/latex/ or /usr/share/texmf-texlive/tex/latex/; to see where these files are on your system, run
latex z.tex
on any L^{A}T_{E}X file, and look for ".sty" in the output.
When you use a style file, say x.sty, include a line
\usepackage{x}
in your L^{A}T_{E}X source file. If it is not already part of your installed L^{A}T_{E}X system, you will need to add its directory, say /u/v/w (full path name), to the search path:
setenv TEXINPUTS .:/u/v/w:
(The final colon is crucial.)
integrals (math):
\int_0^T x(t) dt"landscape" (as opposed to "portrait") printing:
The L^{A}T_{E}X command is
\usepackage{landscape}
Margins which are stated to be horizontal (\oddsidemargin and \evensidemargin) will now be vertical and vice versa. However, \textwidth and \textheight still refer to the lines of text themselves.
letterhead, skipping over:
limits (math):
To get a nice-looking limit, use \lim, e.g.
\lim_{n \rightarrow \infty} z_nlimits on integrals, sums etc. (math):
Limits on an integral, sum and so on can be produced by using ordinary sub- and superscript operations. This looks good for inline math within text, but for displayed expressions the \limits operator can be used to place limits directly above and below the integral, instead of to the "northeast" and "southeast." For example, to write the integral from 0 to 1 in this manner,
\int\limits_0^1line break:
I like the listings package. It even allows you to embed math, e.g.
\begin{lstlisting}[numbers=left] abc $x^2$ de f \end{lstlisting}
You can specify a programming language, in which case the package will highlight the keywords for that language, e.g.
\begin{lstlisting}[numbers=left,language=c]
In the case of C/C++ code, and possibly others, you may get odd space symbols, so try
\begin{lstlisting}[numbers=left,language=c,showstringspaces=false]long equations:
If an equation is too long to fit on a line, you can try using eqnarray to break it up. Or use the amsmath package's split environment, as follows:
\begin{split} first part of long equation \\ second part \end{split}
math symbols:
matrices (math):
\begin{equation} \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \end{equation}
There are lots of variations.
This must be accompanied by a line
\usepackage{amsmath}
before your \begin{document}.
If you don't use that package, just use arrays:
\begin{equation} \left ( \begin{array}{cc} 1 & 0 \\ 0 & 1 \end{array} \right ) \end{equation}
min, max, log etc. (math)
\max_i x_iwill result in the i going underneath "max" instead of to the side. the multline and eqnarry environments (math):
\usepackage{amsmath}before your \begin{document}. Here is an example of use of the environment:
\begin{multline} q(v) = q(v_{1},...,v_{d-1}) \\ = P(Y = 1 | X^{(j)} = v_{1},...,X^{(d-1)} = v_{d-1}) \end{multline}Note the \\ signal to go to a new line. If you want the equal signs to be aligned, the old standard choice (today, many prefer the similar but more flexbile align environment from the amsmath package) was eqnarray, e.g.
\begin{eqnarray} q(v) & =& q(v_{1},...,v_{d-1}) \\ & = & P(Y = 1 | X^{(j)} = v_{1},...,X^{(d-1)} = v_{d-1}) \end{eqnarray}
The ampersands are used here to align the equal signs. And they need not be equal signs; anything between the ampersands--including a blank--will line up with the others.
If you want, say, only the last line to be numbered:
\begin{eqnarray} q(v) & =& q(v_{1},...,v_{d-1}) \nonumber \\ & = & P(Y = 1 | X^{(j)} = v_{1},...,X^{(d-1)} = v_{d-1}) \end{eqnarray}L^{A}T_{E}X may place the equal sign in the above example further to the right than you wish. If so, try \lefteqn{}:
\begin{eqnarray} \lefteqn{q(v) & =& q(v_{1},...,v_{d-1})} \nonumber \\ & = & P(Y = 1 | X^{(j)} = v_{1},...,X^{(d-1)} = v_{d-1}) \end{eqnarray}
norm, vector (math):
\parallel u+v \parallel"not equals" sign (math):
page numbering:
paragraph indentation:
plus-or-minus (math symbol):
quotation marks:
Do not use the ASCII quotation mark character for quotes. Use `` for opening quotations and '' for closing them. (These are pairs of left single-quote and right single-quote characters.)
If you have a quote within a quote, so that the latter needs the single-quote marks, use ``\,` to open and '\,'' to close.
references:
\section{XYZ} \label{sectionxyz}sets up use of something like
...in Section \ref{sectionxyz}Use \pageref to refer to page numbers.
Note: I've found that in some distributions, I occasionally get "undefined reference" error messages, even though the reference is there. I've found that I can fix this by removing the .aux and .out files.
rotating text, including making it upside-down:
\usepackage[dvips]{graphics}
Then for the rotated text, have:
\rotatebox{angle, in degrees counterclockwise}{text to be rotated}
(The effect will show up only after use dvips, not xdvi.)
sections, subsections etc.:
\setcounter{secnumdepth}{4}If you want the same depth in your table of contents, write
\setcounter{tocdepth}{4}slides:
subscripts, superscripts (math):
{(x_{ij})}^2will produce the square of x with a subscript ij.
sums (math):
tabbing:
\begin{tabbing} set $F_1$ to the set of 1-item itemsets whose support exceeds the threshold \\ for \= i = 2 to b \\ \> $F_{i} = \phi$ \\ \> for \= each I in $F_{i-1}$ \\ \> \> for \= each K in $F_1$ \\ \> \> \> $Q = I \cup K$ \\ \> \> \> if \= support(Q) exceeds support threshold \\ \> \> \> \> add Q to $F_{i}$ \\ \> if $F_{i}$ is empty break \\ return $\cup_i F_i$ \end{tabbing}
Each \= establishes a tab mark, and each \> means to move to the next tab position. The \\ mean to start a new line.
table of contents:
\begin{tabular}{|r|r|} \hline ~ & 1011 \\ \hline AND & 1101 \\ \hline \hline ~ & 1101 \\ \hline \end{tabular}
Without vertical lines:
\begin{tabular}{rr} ~ & 1011 \\ AND & 1101 \\ \hline ~ & 1001 \\ \end{tabular}
Without vertical or horizontal lines:
\begin{tabular}{rr} ~ & 1011 \\ AND & 1101 \\ ~ & 1001 \\ \end{tabular}
With a wide column at the top:
\begin{tabular}{|r|r|} \hline \multicolumn{2}{|c|}{spans the full width of the table} \\ \hline ~ & 1011 \\ \hline AND & 1101 \\ \hline \hline ~ & 1101 \\ \hline \end{tabular}
Note: If a table entry should be blank, just put in a tile (~).
theorems, etc.
The amsmath package has Theorem etc. environments.
Many people redefine those environments. For example, the Journal of Machine Learning Research style file does this:
\newcommand{\BlackBox}{\rule{1.5ex}{1.5ex}} % end of proof \newenvironment{proof}{\par\noindent{\bf Proof\ }}{\hfill\BlackBox\\[2mm]} \newtheorem{example}{Example} \newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{remark}[theorem]{Remark} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{definition}[theorem]{Definition} \newtheorem{conjecture}[theorem]{Conjecture} \newtheorem{axiom}[theorem]{Axiom}tilde (math):
title page ("article" style):
union, intersection, subset, superset (math):