LaTeXing Multiple Equations

In mathematics and the (hard) sciences it’s important to be able to write documents with lots of equations, lots of figures and lots of references efficiently. This can be done in, for example, Microsoft Word, but the mathematics and theoretical physics community heavily prefer \TeX (and in particular \LaTeX), so the bottom line is if you want to get papers published you’re going to have to get good at it.

There are a lot of resources for learning \LaTeX on the web, and a lot of people teach themselves from this (I know I did), but this can get you into some bad habits. For instance eqnarray gets the spacing around the equals signs all wrong. (I typeset my thesis using exclusively eqnarray and didn’t notice this until it was pointed out to me). So a lot of people advocate align from AMSTeX, but align has it’s limitations too; it only comes with one alignment tab &. If you want to make a comment at the end of multiple equations (like “for x \in X“) or you want to have two equations and the second one breaks over two lines you can’t line the equations up properly; but there is a solution – IEEEeqnarray (which is an external class, IEEEtrantools, available from the IEEE). Stefan Moser has written an excellent paper covering everything I’ve said and much more, showing good ways to typeset equations.

An interesting thing he points out is that \TeX sometimes typesets + as a binary operator, as in {} + a or as a unary (sign) operators as in + a (note the extra spacing between the + and the a in the first example). The most common example of where + is typeset as a binary operator is when the thing following the + is a mathematical operator “\…” e.g. $+ \sin(x)$ as opposed to $+ {\sin(x)}$.

You can do some fiddling to trick \LaTeX; indeed that’s how I produced the output above. Inserting an invisible character {} before the + sign makes \TeX treat + as a binary operator with more spacing preceding it. Encapsulating an operator in curly braces, like {\sin(x)}, means if + is the first thing on the line it is treated as a unary operator. But these fixed aren’t perfect in particular the invisible character trick isn’t good if we’re trying to break an equation over multiple lines (see Moser’s paper for more details); ${} + {\sin(x)}$ = ${} + \sin(x)$ is different to $+ \sin(x)$ – try it.

Some readers may think I’m being overly pedantic about a small space (1/2 of a quad), but \TeX advocates market it on its consistency in typesetting – these examples fail this and help you typeset inferior documents if you’re not careful.

There are many Integrated Development Environments for \TeX programs (like TeXworks) but the only one I know that lets you preview equations (it does a little compile of just the equations) is emacs with auctex.

Incidentally there are other addons to \TeX around – e.g. ConTeXt which appears to allow you to customise the layout of your document more easily than \LaTeX (which could be very useful in some situations; for instance if you want to wrap text around a figure), but at the cost of the author having to put more effort in laying out the document. As it happens, the standard way of producing multiple equations in ConTeXt seems to be as good as IEEEeqnalign. But while most scientific journals are still using \LaTeX so will most scientific authors.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to LaTeXing Multiple Equations

  1. Stephen Wade says:

    I like that trick regarding the unary/binary operators, never thought of that. What do you mean about the align environment only having the one tab, &? There are other environments that come with ams that sort of fill some gaps – ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf

    • physjam says:

      I’m sort of lying. In align it seems the first & correctly aligns all the terms, but a second & creates a large space (eqns 2.7 and 2.8 in the guide you linked).
      What I want is for the &s to give an even alignment (like the matrix environments give you, without the spacing) – IEEEeqnarray does this, and as far as I’ve been able to discern none of the AMS packages do.

      To give you a concrete example see equations 28-30 in http://moser.cm.nctu.edu.tw/docs/typeset_equations.pdf. I like this style of alignment and I’ve tried to replicate it using the AMS packages but can’t.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s