[Tex/LaTex] Should I \mathrm the d in the integrals

best practicesmath-mode

When writing an integral, it seems like something should be done to separate the "d", as in \int f(x) dx, so as not to confuse it with a variable. I've seen it left as-is, bolded, and straightened. Even among those options there are several ways to accomplish each task; e.g., I could do a \mathrm or a \operatorname. What is the preferred method of dealing with the "d"?

Best Answer

\documentclass{article}
\usepackage{amsmath}
\newcommand*\diff{\mathop{}\!\mathrm{d}}
\newcommand*\Diff[1]{\mathop{}\!\mathrm{d^#1}}
\begin{document}

\begin{align*}
\biggl(\int_{-\infty}^\infty e^{-x^2}\diff x\biggr)^2 
  &= \int_{-\infty}^\infty\int_{-\infty}^\infty e^{-(x^2+y^2)}\diff x\diff y \\
  &= \int_0^{2\pi}\int_0^\infty e^{-r^2}r\diff r\diff\theta                  \\
  &= \int_0^{2\pi}\biggl(-{e^{-r^2}\over2}\bigg\vert_{r=0}^{r=\infty}\,\biggr)\diff\theta\\
  &= \pi                                          \tag*{q.e.d.}\\
\end{align*}
%
\[ V(\mathbf{x}) = -\int_{\mathbf{R}^3} 
   \frac{G}{|\mathbf{x}-\mathbf{y}|}\,\rho(\mathbf{y})\,\Diff3\mathbf{y} \]

\end{document}

enter image description here

Related Question