I have made several math operators in my preamble, but now I want to make a minor change (in the output). I will use the gradient operator as an example in the following. The MWE below shows my gradient definition including a small example of usage.
\documentclass{memoir}
\usepackage{amsmath}
\usepackage{mathtools}
\DeclarePairedDelimiter\parentheses{\lparen}{\rparen}
\newcommand{\grad}[1]{\operatorname{grad} \parentheses*{#1}}
\begin{document}
\begin{align}
\grad{\vec{x}} = \grad{2y}
\end{align}
\begin{align}
\sin x = \sin (2y)
\end{align}
\end{document}
Currently, I always get parentheses in the ouput:
The problem is that I would like the left-hand side without parentheses, but still have parentheses on the right-hand side---depending on whether there is a single or multiple inputs/parameters, as exemplified for the sine:
I would like to change this globally based on the above example without having to correct any operator notation throughout my document. Is that possible? Or optimal? And how is it best done in general (from scratch)?
(I would prefer automatic scaling of the parentheses.)
\vec{x}
andx
cases show. If you expect that a “single” argument to\grad
is always of the form\vec{...}
, then something can be devised. By the way, it's a very bad idea to automatically use the*
form of the delimiters; I know it's handy, but it's wrong nonetheless.\grad
arguments can be of any kind, not just\vec{...}
. Are you saying that it is not possible to make such a command? (At least not without making use of exotic stuff.)sin 2y
doesn't need them and neither does\grad \vec x
(naturally not using the\grad
definition as in OP). The spacing is indicative enough.grad/gradp
orsin/sinp
and you, the human, who decides which one to use has much for it in this case. Naturally egreg, Manuel, Mico and others interested can explain how to do it automatically if the criterion is completely explicit.