[Tex/LaTex] How to define d in integral expression for \int \dif x f(x) notation


There seems to be some consensus about defining \dif like this:


Should I \mathrm the d in my integrals?,
What is the difference of \mathop, \operatorname and \DeclareMathOperator?,
new command for the dx of intergral.,
Should I \mathrm the d in my integrals?

This looks fine in

\int f(x) \dif x

but not so much in

\int \dif x f(x)

What is the best alternative (or extension) when using the latter notation?

Here's an MWE which nicely shows the difference — the second line is even shorter than the first:

    $\int f(x) \dif x$

    $\int \dif x f(x)$

enter image description here



be a good solution? It certainly looks better.

Best Answer

You should use a different command for “improperly placed differential”:


and use it only if followed by other symbols (choose another name, if you want).

With \mathop{}\!\mathrm{d} you'd get an unwanted thin space between the integral symbol and the “d”. If you add a trailing \mathop{} you get two thin spaces between the variable and the following letter or one if a parenthesis follows. You could do


but this would be the same as just adding \,.

I see no chance of defining a command that can go either at the beginning or at the end of the integrand. Making the decision by looking at the next token would require big tables and several exceptions.

You may define a *-variant, if you prefer:


   {% * variant, we are at the beginning
   {% normal variant

and use

\[ \int f(x)\dif{x} = \int \dif*{x} f(x) \]