# \setmainfont breaks \DeclareMathOperator

\DeclareMathOperator works fine without \setmainfont.

\documentclass[a4paper]{standalone}
\usepackage{amsmath}
\usepackage{unicode-math}
\begin{document}
$\nabla \grad f$
\end{document}


However, as soon as I include the command \setmainfont, the \DeclareMathOperator stops working.

\documentclass[a4paper]{standalone}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{texgyrebonum}
\begin{document}
$\nabla \grad f$
\end{document}


It happens with both XeLaTeX and LuaLaTeX. Why does this happen? How to fix it?

• I'm not sure \nabla should be treated as an operator. – egreg Jan 11 '16 at 13:33
• Okay. I'll do that. Doing that solves the problem. – user7013 Jan 11 '16 at 14:21
• By the way, \DeclareMathOperator is broken in unicode-math. :( – egreg Jan 11 '16 at 15:10

\newcommand*\grad[1]{\nabla\mathord{#1}} % and use like \grad{f}

If you want to ensure a small space (like before differentials, for instance) you could add \mathop{}\!
\newcommand*\grad[1]{\mathop{}\!\nabla\mathord{#1}}

Of course you can drop the argument and the \mathord{#1} part, but I think it does no harm and is convenient here.