# Spacing in QM-style integrals (differential first)

I'd like to write integrals with the differential first, the way physicists tend to: $\int dx f(x)$. The problem is that this puts an unsightly (to my eye) gap between the integral sign and the differential, and then puts the integrand much too close to the differential. I can solve this by writing something like $\int \hskip -3pt dx\ f(x)$, but that is hardly satisfactory.

What is the accepted way to do this? Where should I be looking?

• Tear down the walls of prejudice, be adventurous, follow your instincts, and simply don't write as they do. – percusse Apr 12 '13 at 22:30
• – Peter Grill Apr 12 '13 at 23:57

As a physicist, I'd like to give you this:

\newcommand*\diff{\mathop{}\!\!\mathrm{d}}
$\int \diff x f(x)$

\begin{equation}
\int \diff x f(x)
\end{equation}


Although it doesn't look good in the -environment. Please note that it has to be d x and not dx.

• But I think you don't get the space after the differential automatically. And you should care about how it looks in fractions and more. – Manuel Apr 13 '13 at 9:58

Here's a possible definition, compared with the "default" output (\displaystyle is used only for showing the result without centering the formula). Note that you need different backspace in displays and in inline formulas.

\documentclass{article}

\newcommand\pred{
\mathchoice{\mkern-6mu}{\mkern-1mu}{}{}
d#1\,
}

\begin{document}
$\displaystyle\int_a^b \pred{x} f(x)$ \quad
$\displaystyle\int_a^b dx\, f(x)$

\bigskip

$\int_a^b \pred{x} f(x)$ \quad
$\int_a^b dx\, f(x)$

\end{document} • As you wrote this command, shouldn't be better to enclose d#1 in a \mathit{d#1}? I'm not sure myself. The differential is written with two or more letters, but is one object. – Manuel Apr 13 '13 at 10:01
• @Manuel While "dx" is one object, it's still composed by two distinct symbols. – egreg Apr 13 '13 at 10:03
• If you had written it with \mathrm{d} then I should think about it as an operator and then I haven't said anything. But since you wrote it in italic I think that may be dx should be written similar to the identity function which I write as \mathit{id} instead of id. – Manuel Apr 13 '13 at 10:09
• @Manuel I don't agree with this: \mathit{id} is good because the two letters don't have a separate meaning. In this case x should be the same x as in f(x). – egreg Apr 13 '13 at 10:22

\def\Int#1#2{\int \hskip -3pt d{#1}\ {#2}}