# 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)$

$$\int \diff x f(x)$$


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[1]{
\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}}
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 1, "x-ck12": 0, "texerror": 0, "math_score": 0.8133261799812317, "perplexity": 943.8230484813873}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-34/segments/1596439737172.50/warc/CC-MAIN-20200807083754-20200807113754-00523.warc.gz"}