LaTeX Tricks
LaTeX is a typesetting language and system. It is very powerful and produces very professional looking documents, but sometimes it takes some tricks to accomplish the effect you want.
Fonts
Fonts have two names. It is easier if you don’t have to know the lower-level names. By default, LaTeX uses Computer Modern font, which has the textbook look, but it must be embedded into the PDF file, making the file bigger. But you might want to use Postscript/PDF standard fonts. My suggestion
Font Packages
Instead of tweaking fonts individually, it may be better to use a font package, which can define the serif, sans-serif, and typewriter fonts to use and may look more coherent in a document.
\usepackage{times}
uses the built-in Postscript/PDF fonts
Times for serif, Helvetica for sans-serif, Courier for typewriter, and Symbol. The advantages are (1) saves space (2) PDF file is smaller.\usepackage{mathptmx}
will set the math font to be consistent with the main text font (otherwise it uses the default Computer Modern font for math, which may look somewhat inconsistent). Note that previously this was mathptm.sty, but it is now obsolete. mathptmx.sty (with the extra x) is recommended now.\usepackage{inconsolata}
for typewriter (monospace) font
Inconsolata blends in better with Times. Courier is not a good-looking typewriter font, because it is too wide and too thin.
Setting Fonts and Sizes directly
\fontsize{9pt}{10pt}\selectfont
Chooses font size of 9pt, line height of 10 pt, but it does not take effect until the selectfont command is executed.
Lists
Lists include itemize, enumerate, and description environments. Useful packages in conjunction with lists are
\usepackage{enumerate}
for setting enumeration style. Example\begin{enumerate}[I.] \item Foo \item Bar \end{enumerate}
This will use Roman numerals. 1. for arabic, a. for lower-case letters, i. for lower-case Roman numeral, etc. Actually, the . can be omitted or ) or any other symbol. You can also put (i), i), etc. in conjunction with other letters. To protect one of these special symbols (1, i, I, A, a), just use braces.
\usepackage{enumitem}
for tweaking list parameters, such as margins, spacing between lists, indentation, bullet symbol. Example\begin{itemize}[leftmargin=0cm] \item Foo \item Bar \end{itemize}
You can use
label=
to change bullet symbol,itemsep=
to change spacing between items, etc.
Graphics
\usepackage{graphicx}
for including graphics into LaTeX. This is the recommended package to use because it is independent of pdflatex (which outpus pdf) or old latex (dvi then ps).\includegraphics[width=2in, height=3cm, rotate=90]{filename}
This includes an instance of the graphic in filename (with one of the found suffixes if not explicitly given) and scales it to width and height and rotates it by the given degrees. Of course, the width, height, and rotate are entirely optional.\DeclareGraphicsExtensions{.pdf, .gif, .jpg, .png, .eps}
This declares a list of file-name suffixes to search for as graphic files to include. In the example, it will prefer a .pdf to a .gif, for example, when you provide just the stem name without the suffix.\graphicspath{{./pic/}}
This adds a search path so when you include graphics you don’t have to specify the directory prefix for your graphic files.
\usepackage{pdfpages}
documentation
It is good for extracting PDF pages from another file and inlining them into your own document. You can use it to extract pages, concatenated multiple PDF documents into one, etc.\includepdf[pages={1-5},nup={4x2}]{sourcePDF}
This reads pages 1 to 5 of sourcePDF and inlines them into your document. You can say leave off starting and ending pages to indicate beginning and end pages of the PDF source. It shrinks them so it puts 4 pages horizontally and 2 pages vertically on the page. By default nup={1×1}.
Algorithm Pseudocode
Many packages have been written to support formatting of pseudo code. The choice depends on the requirements of the publication or your own taste. The ones I have used more include
- algorithm2e.sty: this is what ACM Transaction journals require.
- clrscode.sty: this is not part of standard distribution but can be added yourself. It is used by the Cormen, Leiserson, Rivest, Stein Algorithms textbook. However, they changed it from 2nd edition to 3rd.
Code Listing
\usepackage{listings}
This package supports syntax highlighting of many languages, and it has both in-line style code as well as code blocks. It is much better than using verbatim or backslash escape sequences for writing code.
Page Size and Layout
Document Class
\documentclass{article}
: this is the generic article, but by default it has wide margins. My suggestion:+
\usepackage{fullpage}
: this sets the margins to some reasonable sizes (about 1 inch on each side).