LaTeX notes
Contents
- Useful references
- Making nice PDFs without pdflatex
- Spacing issues
- More spacing issues — hitting page limits
- Recommended packages
- hyperref problems
- Upside-down slides
- pspresent
- Centering stuff vertically within a line
- Gaps to match
- Fonts
Useful references
- I have used this hypertext reference a lot.
- This TeX FAQ, is very good.
- For fancy math stuff with LaTeX see the AMS documentation.
- A comprehensive review of slide-making packages. Warning: huge time sink. Simple might be better.
- The TeXbook is great; see details on Knuth’s webpage or look through the source of the book.
- Kopka and Daly’s Guide to LaTeX looks like one of the better LaTeX books. But none I’ve seen look as fun or interesting as the TeXbook.
- This Plain TeX reference card is largely compatible with LaTeX.
Making nice PDFs without pdflatex
I now mainly use pdflatex. Below is the set of switches I use if going via dvi from normal latex. These avoid bitmap fonts, ensure ligatures don’t turn into pound-sterling symbols and force the page size to a4. I find that this basically always works as long as tetex and ghostscript are not ancient.
#!/bin/sh
dvips -Ppdf -G0 -o "${1%.dvi}"_pdf.ps "$1" ;
ps2pdf -sPAPERSIZE=a4 "${1%.dvi}"_pdf.ps "${1%.dvi}".pdf;
You may find that the above mangles some of your colour figures, as it jpeg compresses them (sometimes very aggressively). The following switches to ps2pdf:
-dAutoFilterColorImages=false -sColorImageFilter=FlateEncode
losslessly compresses your images. You may experience an increase in file size.
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.
- If a period (full-stop) does not end a sentence then the space needs escaping so that it does not end up too long: Hello Mr.\ Murray.
- If a sentence ends with a capital letter then you need to tell LaTeX that it really is the end of a sentence: I modeled the data with a GP\@.
- Use \textit{this is in italics} for italic text (or \emph{...} for more semantic markup). Otherwise you have to know about italic correction: {\it this is in italics\/} and {\it so is this}.
- Similarly \textbf{...} is sometimes different from {\bf ...}. Compare `{\bf f}' to `\textbf{f}' or `{\bf f\/}' (including the quote marks).
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.
- Look for suspiciously large vertical whitespaces between paragraphs. This is often due to TeX not wanting to split a paragraph over a page break, or separate it from a heading. Convincing TeX to pull some text back a page into this white space can have dramatic effects on the page count.
- There are various parameters documented in the TeXbook that make TeX more willing to do ugly things.
- If a paragraph has only a word or two on its last line try adding \looseness=-1 to the end of it. If possible TeX will reduce the length of the paragraph by a line. This won’t always work because there is a limit to how close TeX will move words.
- Moving figures around is a frustrating but often fruitful activity.
- In desperate situations negative kerns, e.g. \kern-1pt can enable words to be scrunched more than normally possible. Although rewording is probably a better option.
- bibhacks.sty makes the references heading third level and optionally scrunches the font size and spacing of references. See comments inside for more information.
- Move footnotes and short unreferenced equations into the main text. Consider turning third level headings into bold words at the beginning of a paragraph.
- It's usually pointless to engage in space scrunching until finishing the paper. And it's worth keeping a copy of the unscrunched version.
Recommended packages
The following are packages I use regularly, some of which I didn’t discover for a long time:
- booktabs — much nicer rules and spacing in tables.
- amsmath — good documentation to make a lot of common math constructs prettier and easier.
- natbib — flexible referencing system.
- subfigure — allows you to create sub-figures optionally labelled with subcaptions preceded by (a), (b), etc. Use the [tight] option for better spacing. You can \ref and \subref labels within subfigures to get links to figure 1a) and a). As instructed by the subfigure documentation I now use subfig instead. Having a recent version of the caption package (which subfig includes) is recommended.
- url — better than putting inside \texttt{...} and you don’t have to escape tildes.
- hyperref — links in pdfs for all types of cross-references. But there are issues (see below) and lots of options to read through and get right.
- artikel3 — an alternative class to article.
- parskip — a hack to get any style to have vertical space between paragraphs rather than indenting them (as artikel3 already does).
- textpos — allows absolute positioning on a page. Can be useful when press-ganging LaTeX into doing slides or a poster.
hyperref problems
I have wasted a lot of time pinning down problems with the hyperref package. Partly because I didn’t RTFM, which it turns out is more important than normal for this package.
- Links go to wrong page? Try putting \clearpage before the references section and \phantomsection before any \addcontentsline commands. (Apologies: previously I erroneously suggested using \phantompage instead of \phantomsection.)
- Complaints about footnotes? Is hyperref included after all other packages, particularly setspace? If you can not solve the problem then passing the hyperfootnotes=false option turns off footnote links.
- Complaints about duplicate entries? If it is a duplicate page then try passing plainpages=false,pdfpagelabels. If it is complaining about other objects then maybe you have altered the counters and need to be more careful somehow(?). Or maybe (again) it is due to including hyperref before other packages; try including hyperref later in your header.
- Package hyperref Warning: Token not allowed in a PDFDocEncoded string... removing `math shift' on input line XXX. Solution: provide alternative plain text for maths that will end up in links. E.g. change \section{The joy of $\pi$} to \section{The joy of \texorpdfstring{$\pi$}{pi}}.
- Include the algorithm package after hyperref, but manually include the float package (which algorithm will normally include for you) before hyperref. (This is in the README of recent hyperref versions).
- Links to figures point to the caption, so the figure itself goes off the
top of the screen. As in the hyperref README use the hypcap package:
\usepackage[all]{hypcap}
But! If you are using the subfig package make sure you have a recent version of the caption package from CTAN (subfig uses caption). Otherwise references to subfigures can go wrong.
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 }
Doesn’t seem to do any harm in general.
pspresent
If you want to do fullscreen postscript instead of pdf—which is easy to fullscreen with xpdf or acroread—I’ve found pspresent to be a neat and tiny utility, which compiled and worked first time for me.
Centering stuff vertically within a line
I currently use:
\newcommand{\myvcenter}[1]{\ensuremath{\vcenter{\hbox{#1}}}}
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.
Fonts
It’s easiest to stick with using Computer Modern. For information on using other fonts and making mathematics still look reasonable see this useful survey. \usepackage{palatino} is quite nice.