[Tex/LaTex] Spacing after derivative operator in the commath package

math-operatorsspacing

I am using the commath package to typeset the derivative operator "D" with the command \Dif. This work well unless I want to add subscripts or superscripts. In this case, the spacing after operator is too small and the exponent / index "touches" the operator:

enter image description here

where the first operator is created via \Dif and the second one via \mathrm{D} (full MWE see below).

Is there some way to "redefine" the \Dif command in order to fix the spacing?


\documentclass{article}
\usepackage{commath}

\begin{document}

\begin{align*}
  \Dif^2_x f(x) \\
  \mathrm{D}^2_x f(x)
\end{align*}

\end{document}

Best Answer

The definition of \Dif in commath.sty is

\DeclareMathOperator{\Dif}{D \!}

which is simply wrong. The \! backspace is the cause of your problem. It's not the only part in commath that I consider wrong, so I can't recommend using the package.

A more correct definition would be

\newcommand{\Dif}{\mathop{}\!D}

that you can add to your document (with \renewcommand if you insist in using commath).

Related Question