A couple people have asked me recently how to properly format integrals in \(\LaTeX\), be it controlling where the limits are displayed or adding half spaces before the differentials (a formatting standard that too many don’t even know about). This isn’t the first time those questions have been raised, so I’m going to address some of them here.

This is also my first post using MathJax. I may write a short article soon about MathJax, as I’ve found that integrating it into this site is ridiculously easy. MathJax allows for vector-based and \(\LaTeX\)/MathML-based math rendering on webpages, instead of the raster graphics you find on many sites having math content. Basically, I’m a big fan.

Proper Spacing inside Integrals

First, I’ll give an example of an improperly written improper integral. (That’s a pun.) The code in \(\LaTeX\) that most would write looks like this:


When rendered by \(\LaTeX\) that code snippet produces the following:


What’s wrong with this? The answer is that there should be a half space between the integrand and the \(dx\). That is, we should have something more like


which will appear as


This is a very tiny difference. (There is a half space added between the \(f(x)\) and the \(dx\).) But, it is a matter of anal professionalism that many mathematicians follow. Look in any modern calculus text and you’ll notice that the half spaces are included. Look on a graduate TA’s calc II final, and the half spaces will probably not be included.

Display Styles

Most of those writing \(\LaTeX\) know the difference between inline and display modes. The same integral written inline will appear differently than when written in display mode. As an example, consider the inline integral \(\int_0^2x^2\,dx\), which in display mode appears as


Sometimes, for various reasons, we may want to force \(\LaTeX\) to use display mode in inline text. We may force the display mode version \(\displaystyle\int_0^2x^2\,dx\) in place of the inline version \(\int_0^2x^2\,dx.\) We do this using the displaystyle command, as in:

We may force the display mode version $\displaystyle\int_0^2x^2\,dx$ in place...

If you tinker around with this a bit, you discover that \(\LaTeX\) will descend to inline mode inside a nested sequence of commands in display mode. For instance, if we write

f(x) = \frac{\int_0^1g(x)\,dx}{\int_0^1h(x)\,dx}

then we would get

$$f(x) = \frac{\int_0^1g(x)\,dx}{\int_0^1h(x)\,dx}.$$

I don’t particularly like the way this looks, so I’ll use

f(x) = \frac{\displaystyle\int_0^1g(x)\,dx}{\displaystyle\int_0^1h(x)\,dx}

instead, which gives me

$$f(x) = \frac{\displaystyle\int_0^1g(x)\,dx}{\displaystyle\int_0^1h(x)\,dx}.$$

Moving Limits

One thing you’ll notice is that the integration limits are placed differently between inline and display modes in \(\LaTeX\). In display mode, the default is to place the limits of integration at a southeast and northeast location relative to the integral sign. Sometimes we wish to place the limits directly under (or directly over) the integral instead. Notice how the limits command is used in the following:

\int\limits_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy
= \int\limits_{\theta=0}^{2\pi}\ \int\limits_{r=0}^R f(r\cos\theta,r\sin\theta) r\,dr\,d\theta

This produces the output:

$$\int\limits_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy
= \int\limits_{\theta=0}^{2\pi}\ \int\limits_{r=0}^R f(r\cos\theta,r\sin\theta) r\,dr\,d\theta.$$

OK. I cheated a bit by putting the extra space between the two integral signs, but any experienced \(\LaTeX\) user knows that sometimes the typesetting has to be coerced a bit. :-)

The iso646.h header file in the C standard library isn’t found in many texts on C. It was added to the standard library in 1995 as an amendment to the C90 standard. It is one of the more basic library header files, allowing for (1) international non-QWERTY keyboards to more easily write C without digraphs and trigraphs, and (2) bitwise and logical operators in more natural language. The only job of the header is to convert macros (on the left in the below table) to C tokens (on the right).

and     &&
and_eq  &=
bitand  &
bitor   |
compl   ~
not     !
not_eq  !=
or      ||
or_eq   |=
xor     ^
xor_eq  ^=

Interestingly, these are all operator keywords in C++. There is a ciso646 header for C++ which may be included for consistency, yet it has no effect because it is empty.

Posted in C