I'm creating a list with common math commands that I use, but \newcommand and \DeclareMathOperator both add a space after the symbol I just defined. For example, comparing the two commands defined below,
\DeclareMathOperator{\dd}{d}
% Derivartive in Leibniz notation d{#1}/d{#2}
\newcommand{\deriv}[2]{ \frac{\mathrm{d}}#1 }{ \mathrm{d}#2^} }
\newcommand{\dderiv}[2]{ \frac{\dd #1 }{ \dd #2 } }
\deriv{f}{x} gives me the usual
while \dderiv{f}{x} is compiled to
I'm using Overleaf. Is there any way to avoid this?
Best Answer
The
\DeclareMathOperator
command gives the string\mathop
spacing, like the\log
or\cos
operators.To get
\mathord
(ordinary math atom) spacing, wrap it in braces:The
\mathord{\dd}
command will also work, so it’s up to you whether this overcomplicates things or makes it easier to understand why you are wrapping\dd
.So, for a MWE:
You might, however, want operator-like spacing on the left but ordinary spacing on the right of
\dd
, for use cases like\dd x \dd y
For example:ETA:
Several commenters thought the second example added excessive space, so I’ll reprint Henri Menke’s tweak from the comments: