Spacing in integrals with LaTeX

It's a good habit to have a thin space in front of “dx”, which emphasizes the fact that the “d” is attached to the variable “x”, forming a single unit (which is, mathematically, what really happens).

So a savvy typist will input your formula as

\[
\int k\,dx = kx+C
\]

and, similarly,

\[
\iint\limits_{\mathbb{R}^2} e^{-x^2-y^2}\,dx\,dy
\]

Typing in the \, becomes automatic, when you think about the nature of the symbol. But

Yes, there's a caveat. Some people, not knowing what the “d” is about, think that it has the same mathematical nature as “sin” (which it hasn't, but here we're discussing opinions), so they want it to appear in upright font.1

In view of this it is convenient to add a macro for the “d” in the differential symbols; the simplest one is

\newcommand{\diff}{\mathop{}\!d}

so you type the formulas above as

\int k \diff x = kx+C

\iint\limits_{\mathbb{R}^2} e^{-x^2-y^2} \diff x \diff y

and, in case the journal editor, your supervisor or whoever asks you to turn the “d” into upright type, all you'll have to do is to change one line in your typescript

\newcommand{\diff}{\mathop{}\!\mathrm{d}}

Some packages offer similar functionality; I usually find they overdo. For instance the physics package defines \dd with three optional arguments, making for confusion rather than simplification. (The commath package, instead, makes such a mess that it is better ignoring it.)

In any case, resist the temptation to do

\renewcommand{\d}{<whatever>}

in order to have a handier macro name for the differential. Macros for accents should never be redefined to do something different. Accents appear (maybe masked out) in people's names and having the differential symbol popping out in the middle of a name in the bibliography is not the best thing to find out when you're very near a deadline.


1 Even worse, some people even go further and use Wolfram's convention that the “d” is double-struck: (they also like for Euler's number). Let's hope this ugliness won't spread.


I use this, borrowed from an answer on this side, but I can't remember as an answer to which question:

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
 \usepackage{amsmath,amsfonts,amssymb}%

\AtBeginDocument{\renewcommand*{\d}{\mathop{\kern0pt\mathrm{d}}\!{}}}

\begin{document}

\[ \int_a^b f(t)\d t \]

\end{document} 

enter image description here

Tags:

Formatting