This question is a bit similar to Command to uppercase the first letter of each word in a sentence.
What I want is to build a new command for being used just at math mode, using the \DeclareMathOperator
command available at amsmath
package.
The new command I would like to define is the existing command \max
but with its first letter in uppercase.
Notice that the final result of \max
command depends on changes made by babel
package, for instance. In my case, I would place my \DeclareMathOperator
sentence after calling babel
.
Is there a quick way to do this?
In case it's needed, this is a simple example of using \DeclareMathOperator
:
\DeclareMathOperator{\argmax}{\arg\max}
EDIT:
What I am trying to say is that \DeclareMathOperator{\Max}{Max}
is not a valid solution for me, because what I want is the same thing produced by \max
(just with the first letter in uppercase), but taking into account that the result produced by \max
depends on the effect of other packages (for example, calling babel
with spanish
option would produce "máx" for \max
and not "max"). So, it is not so simple as it could seem…
Best Answer
Not quite a generic solution, as it assumes that the first letter is unique in the operator name. The
\relax
are perhaps a bit optional I am always confused about when I should put some or not ;-)Thanks to egreg for his comment(s). After having temporarily incorporated his simplification (of the code of my initial proposal) to the extension I am now proposing, I now return to the original thing, but also incorporate the later improvements signaled by
egreg
.The same restriction as above applies (the operator name should contain its initial letter only once).
Here is the result:
Addendum:
The above definitions make
\Xyzt
behave like\xyzt
with respect to the positions of limits, in inline as well as display style. But there is a difference:\[\sin\limits_a^b\]
or$\sin\limits_a^b$
do not put thea
andb
in limits positions, whereas\[\Sin\limits_a^b\]
and$\Sin\limits_a^b$
do. I would call this an unintended feature rather than a bug! This is illustrated by the following:Note the asymmetry of behavior of the
amsmath
operators\sin
and\min
. Whereas for the first\limits
does nothing, for the second\nolimits
does work. I will not qualify this as a bug ofamsmath
(or ratheramsopn.sty
), as there must be reasons beyond me, but I had never realized that until now.PS: obviously the above image comes from a source with
\usepackage[spanish]{babel}
but I checked that the exact same behavior is observed without any loading of babel. Note also that\sin
and\min
inamsopn.sty
are not defined via\DeclareMathOperator
, respectively\DeclareMathOperator*
, but only by some part of the code of these macros, but this is another not relevant detail.PS2: as a matter of fact the
[spanish]{babel}
defined operator names behave differently from the analogousamsmath
provided names with respect to limits.