LaTeX notes


Useful references

Making nice PDFs (including from old .ps files)

If possible, use pdflatex over latex for hassle-free PDF generation. Include \usepackage{microtype} and get more sophisticated typesetting for free.

For normal latex, the newest recommended tool for making pdf seems to be dvipdfmx, however that won’t work with all packages. The switches I used to use with dvips are below. These avoid bitmap fonts, ensure ligatures don’t turn into pound-sterling symbols and force the page size to A4.

dvips -Ppdf -G0 -o "${1%.dvi}" "$1" ;
ps2pdf -sPAPERSIZE=a4 "${1%.dvi}" "${1%.dvi}".pdf;

You may find that the above mangles some of your colour figures, as it might jpeg compress them (sometimes aggressively). The following switches to ps2pdf:

-dAutoFilterColorImages=false -sColorImageFilter=FlateEncode

losslessly compresses your images. You may experience an increase in file size.

What if you no longer have the .tex or .dvi source? If you have a document made with an old version of tex/latex, it is still possible to make a decent .pdf as long as you have a .ps file made by dvips:

pkfix will now have Type 1 fonts, and can be converted to a good PDF with ps2pdf. The pkfix-helper man page says how to check and tweak the font substitutions.

Making small PDF files

pdfsizeopt is a tool that can rewrite graphics, compress your PDF stream, and dramatically cut down the overhead of your fonts. Although it’s sensible to compress graphics once, before TeXing. It’s pdfsizeopt’s font handling I find really useful: documents made with pdflatex can now be as small or smaller than those from xelatex and lualatex.

Here are the arguments I use. --do-unify-fonts=false --do-unify-pages=false infile.pdf

The first option is important: several of my PDFs are horribly corrupted without it. The second option prevents a (benign?) error message with some PDFs in xpdf/poppler. The following options are implicitly set and can be changed to false if you don’t have the required helper program:

--use-pngout=true --use-jbig2=true --use-multivalent=true

Fonts will still be reorganized if any of these options are set to false.

Spacing issues

Somehow I missed out on knowing this stuff for a long time. lacheck and chktex are programs that will point out problems in your LaTeX markup (possibly with a load of false positives). Those tools know about these issues.

Italic issues

As explained above, use \textit{...} for italic text, not {\it ...}. However, you might not really want italic text. A long block of special text, for example a theorem statement, can be hard to read in italic. Consider using slanted Roman text, \textsl{...}, which is often easier to read, and mathematics stands out better.

Math mode should not be used to write words. For example, $a_{arg}$ looks awful, as the subscript is rendered as “a times r times g”. Instead use $a_\text{arg}$ or $a_\mathrm{arg}$. If you really want italic text, then use $a_\mathit{arg}$.

More spacing issues — hitting page limits

Here are some notes on tricks for squeezing a paper to within conference page limits. There’s always PSSQ, but I like to stay more within the rules than that. Many “9 page” papers can be squashed into 8 pages without changing the font size or main spacing parameters.

Recommended packages

The following are packages I use regularly, some of which I didn’t discover for a long time:

hyperref problems

I have wasted a lot of time pinning down problems when using the hyperref package. Partly because I didn’t RTFM, which it turns out is more important than normal for this package.

If you have problems with a particular package see if hyperref’s README file says how to deal with it.

Upside-down slides

If dvips produces upside-down slides, put this in your document’s preamble:

% This for broken installs that flip page wrong way
\special{! TeXDict begin /landplus90{true}store end }

This doesn’t seem to do any harm in general.

Centering stuff vertically within a line

I currently use:


when I want graphics or other over-sized oddities to be vertically centered. Normally all objects have their baselines at the same height. Alternatives include fiddling with the baseline or using \raisebox.

I still haven’t got around to working out why plain \vcenter doesn’t work in LaTeX.

Gaps to match

To create an empty box with the same size as some particular text use the \phantom command. Horizontal or vertical struts of the same width or height are made with \hphantom and \vphantom. See p178 of the TeXbook and more help on alignment with boxes.


It’s easiest to stick with using Computer Modern. But alternatives are good, especially for those that don’t like ‘modern’ typefaces.

I often do \usepackage{palatino} as a quick way of having something different, but there are other options. See The LaTeX Font Catalogue, and maybe this older survey of TeX fonts.

For non-math documents, I’m currently playing with “Linux Libertine”, with xelatex:

\setromanfont [Ligatures={Common}]{Linux Libertine O}

One could also try getting the font in pdflatex with:


The PDF file will be bigger (which is fixable), and the typesetting isn’t quite the same as xelatex’s.

Embedding LaTeX text in diagrams

fragmaster will make .eps and .pdf files from a .eps file with plain text placeholders and a separate file with LaTeX markup. This strategy means you can create a range of diagrams in different packages and have a uniform way of typesetting text in them. It’s worked pretty well for me.

Of course many programs have their own ways of calling LaTeX. This is how I used to put LaTeX in Matlab figures (now I use fragmaster):

% The magic line is:

% Example:
legend('${\mathcal F}_1(x)$')
print(gcf, 'picture.eps', '-depsc');
system('epstopdf picture.eps');

% To get a small .eps file, convert back again:
system('pdftops -eps picture.pdf picture.eps');