InsectNation

oh, chris de burgh, chris de burgh


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!