LaTeX tips

TeX and LaTeX

TeX and LaTeX are free software professional typesetting packages which are, sadly, little known in the world of Windows computing but are almost ubiquitous in Unix environments and especially in scientific publishing.

I first started using LaTeX (the most common interface to the plain TeX rendering system) for project reports in my 3rd year undergraduate work and immediately wished I'd discovered it earlier. If you've ever experienced the pain of trying to maintain coherent header and paragraph formatting in MS Word for documents over ~30 pages long you'll know what I mean. I won't even attempt to describe how nasty Word is when it comes to equation typesetting or the numbering and positioning of tables and figures!

LaTeX is especially nice for typesetting mathematical work it has beautiful maths fonts and extremely powerful tools for handling tables of contents/figures/etc, citations, bibliographies and indices. The interface is more like programming than the Word-like "WYSIWYG" approach but the initial learning curve isn't too steep and is worth the effort.

Here's some TeX-related links that might be of interest:

*, the main TeX/LaTeX user site      * MikTeX is a free Windows LaTeX distribution      * CTAN, the

repository for LaTeX packages * Cambridge-based frontend to CTAN with a better search system * UK TeX FAQ an excellent resource for TeX and LaTeX frequently asked questions * kile is a free LaTeX environment that's part of KDE (and available through Fink for Mac OS X) * LyX a WYSIWYM (sic) editor producing TeX output

I'll chuck a link to the "Not So Short Guide to LaTeX" on here sometime it's a good initial reference. For more advanced features, the standard books on LaTeX (as well as TeX and Metafont) are:

* The TeXbook  Donald Knuth      * The Metafont Book  Donald Knuth      * LaTeX, a document preparation system

Leslie Lamport * The LaTeX Companion Goosens et al * The LaTeX Graphics Companion Goosens et al * The LaTeX Web Companion Goosens et al

There's plenty of others but these are the ones I've used in the past and found to be useful. I'm told that the Kopka and Daly "A Guide to LaTeX" book is the best of the lot, though... LaTeX / BibTeX style files

There wouldn't be any point in me having this page if I didn't supply anything other than TeX-sycophancy, so here's a few LaTeX style files and other random things that I've been using for recent bits of work. Writing your own packages is quite easy and very worthwhile. One not-so-obvious trick is to set the TEXINPUTS and BIBINPUTS environment variables to include both the current directory (.) and the location of these packages and BibTeX reference files. Both are standard Unix colon-delimited path set strings... i.e. something that looks like /path/to/number/1:/path/to/number/2:..

TEXINPUTS is the search path for the kpathsea library used to carry out the TeX/LaTeX path resolution. Personally, I just have a standard texmf/tex/latex/ directory tree with subdirectories containing each non-standard class and package and I tell kpathsea to recursively search this directory by putting a double-slash (//) on the end of the search path. The same goes for the BIBINPUTS and BSTINPUTS variables, where the tree paths are typically texmf/bibtex/bib/ and texmf/bibtex/bst/ for BibTeX ".bib" database files and ".bst" style files respectively. The variable names match up to file types precisely as you'd expect! export TEXINPUTS=".:/path/to/texinputs//"; export LATEXINPUTS=$TEXINPUTS; export BIBINPUTS=".:/path/to/bibinputs//"; export BSTINPUTS=".:/path/to/bstinputs//";

Anyway, here's those packages: agbpresent class

(click here to download)

agbstd package

(click here to download)

agbhep package

(click here to download)

agbmath package

(click here to download)

Useful TeX packages

Here's a list of the most useful standard LaTeX packages (in my experience) and what they do:

* bm  `proper' handling of bold maths symbols      * draftcopy      * color / xcolor      * boxedminipage      *

braket * a4wide * xspace * tabularx * url * verbatim and fancyvrb * fancyhdr * axodraw (see also Jaxodraw Java program) and feynmf * amsmath * SIunits * chem * timing * slashed / cancel * cite * citesort * graphicx modern LaTeX (at least pdflatex) supports PNG and JPEG images

I've also written a bunch of LaTeX packages specifically for high-energy physics (though several are of more general use). I'll document them soon: you might want to take a look at in case I forget to update this page. Writing LaTeX macros, packages and classes

One of the most powerful features of LaTeX is its customisability: you can write your own macros to enforce consistency through your documents and improve the source code readability (as well as the benefits of single-source macros definitions when it comes to redefinitions). These macros can then be stored in "style" packages for convenience and you can define entire document classes which automatically set the document appearance as required and provide appropriate macro definitions. Hiding all the mechanics of this makes for much more elegant LaTeX source.

Anyway, here's a few hints and tips on how this sort of thing can be done consistently and flexibly:

* Don't be afraid to write your own packages (*.sty files): you'll only need to know a few extra commands to make

them robust and the encapsulation is well worth it. * Use \xspace and \ensuremath round most things that you might ever want to put in a math environment. Remember that math mode ignores spaces, so if you want to combine the two (which is such an idiom that you may want to define a macro wrapper for it) you'll need something like this, \newcommand{\goesto}{\ensuremath{\to}\xspace} i.e. so the \xspace is outside the \ensuremath scope. * Use the amsmath package for its \text macro, which will appropriately match the font of text in math mode to the surrounding paragraph text. Putting your macros which do this in a package which requires amsmath means that you don't need to remember to include the \usepackage{amsmath} in your own documents. * Other things: \providecommand, personal macros as derived from generic macros, \renewcommand, \renewenvironment, \let and recursion problems, \AtBeginDocument, passing parameters to the class, executing at the end of the class defn, specifying a LaTeX version and a package version, \ProvidesPackage, landscape idiom, \RequirePackage

LaTeX tips

This will be a list of LaTeX fine details and other tips that I'll put together as I encounter and remember them.

The best places to look for info on TeX and LaTeX are the UK TEX User Group FAQ, then the Cambridge University Engineering Department LaTeX sub-site. Google in general is always good, but I usually have difficulty finding anything technical: I think LaTeX's syntax matches some statistical criteria that lead to it being automatically excluded from Google results. However, Google's interface to the newsgroups, especially comp.text.tex, is excellent. Genuine technical (TeXnical?) issues are most likely to be solved either by searching the newsgroup archive or by asking a question on the newsgroup (in my opinion).

* Italics in typesetting maths. Upright maths conventions: the d's in "d by dx" etc. How to typeset group names?

Group and set operators? Real and imaginary part operators? Vectors? abmath package (unreleased... needs tidying and will appear eventually. * Imaginary i? Try \imath, which has no dot. I like it, and tend to re-define it as \I for convenience. * ! Missing { inserted. --- put {} round macros otherwise they expand and give nastiness * \noindent can be useful for suppressing indents. Otherwise \setlength{parindent}{0cm} if you want to kill all indents. * \cancel for Feynman slash notation * \ensuremath and \xspace interaction * \if, \ifx etc. for conditionals rather than the ifthen package * \the * \@ifpackageloaded * \makeatletter, \makeatother * Use \let to avoid recursion loops * Useful to be aware of the expansion behaviour of LaTeX as a macro language: no significant scoping etc. Though there are the \begingroup and \endgroup commands... * Define semantic macros whenever possible, even when you think you're only going to use it once or twice! * Definition commands: \newcommand, \renewcommand, \providecommand, \DeclareRobustCommand * \bar versus \overline * xrightarrow, substack and other advanced maths handiness * phantoms in superscripts: see article on typesetting CKM unitarity relations * what the \begin{foo} and \end{foo} commands actually do: translation to a pair of function definitions called \foo and \endfoo. But something else happens, too, as you'll find if you decide to try and wrap the book class' \mainmatter and \backmatter commands in an environment: the wrapping will lead to section numbering being discarded for no obvious (to me) reason. (I discovered this while trying to fix a bug in my hepthesis class: my fix for a small bug ended up being to re-define the interaction between appendices and the backmatter section of a thesis. * % at the end of lines continues on to the first non-space character on the next line * \intertext, \shortintertext * hyperref hacking * use unnecessary braces "semantically"... safety and makes conversion to macros very easy e.g. $\Delta{M}$ is equivalent to $\Delta M$ but is much easier to convert if you made a \DeltaOf macro which handles the spacing more carefully: $\DeltaOf{M}$. Note this is also more semantically clean since here the Delta is an operator (a "width operator" or "spread operator", I guess) rather than just a symbol. * \expandafter, with \csname and \endcsname and \let for defining e.g. starred commands. * \typeout useful for e.g. debugging or denoting that a macro is deprecated * When defining new macros, always wrap the numbered hash-n arguments in braces when you use them, unless they might contain a \ (newline) sequence in a table structure. That might make no sense now, but you'd soon run into trouble if you applied the first argument in a macro for typesetting a matrix and you decided to just take one argument including the two required linebreaks!