In this answer to the question Shortcuts and/or user-defined shortcuts for math symbols in LaTeX?, it is advised to denote the gradient with \DeclareMathOperator{\grad}{grad}
.
But this is suboptimal (wrong space) compared to \mathrm{grad}
when the operator is followed by a binary operator (the same with ∇ instead of "grad"), as shown by the following MWE (where only equations ≡ 0 mod 3 are okay):
\documentclass[convert,varwidth=4cm]{standalone}
\usepackage{mathtools}
\usepackage{amssymb}
%
\DeclareMathOperator{\grad}{grad}
\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\curl}{curl}
%
\DeclareMathOperator{\nablaop}{\nabla}
%
\begin{document}
\begin{align}
\Div F & = \grad \cdot F \\
\Div F & = \grad{} \cdot F \\
\Div F & = \mathrm{grad} \cdot F \\
\curl F & = \grad \wedge F \\
\curl F & = \grad{} \wedge F \\
\curl F & = \mathrm{grad} \wedge F \\
\Div F & = \nablaop \cdot F \\
\Div F & = \nablaop{} \cdot F \\
\Div F & = \nabla \cdot F \\
\curl F & = \nablaop \wedge F \\
\curl F & = \nablaop{} \wedge F \\
\curl F & = \nabla \wedge F
\end{align}
\end{document}
Is there a way to make \DeclareMathOperator
's behavior okay when the operator is followed by a binary operator?
Best Answer
If you are sure that
\grad
will be followed by a fixed (but easily extendable) set of binary operators, this should work:If a binary operator in the list follows, we issue
{\!}
that fixes the spacing: the thin space between the operator and the empty atom is nullified by\!
and the empty atom will provide the required bit for the spacing around binary operators.A slightly different version with an interface for adding binary operators; the initial declaration
should go in the class, together with instructions such as