Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
1  
since the suggested approach doesn't solve your problem, please provide a minimal working example (MWE) that shows what's wrong. –  barbara beeton Oct 18 '12 at 17:09
add comment

3 Answers 3

up vote 2 down vote accepted

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 ;-)

\documentclass{amsart}
\usepackage[english,spanish]{babel}
\makeatletter
\newcommand\Max{\@tempcnta=\mathcode`\m\relax
\mathcode`\m=\mathcode`\M\max\mathcode`\m=\@tempcnta\relax}
\makeatother

\begin{document}
  \begin{equation*}
    \max_0^\infty = \Max_0^\infty \Max\nolimits_0^\infty m M 
  \end{equation*}
\selectlanguage{english}
  \begin{equation*}
    \max_0^\infty = \Max_0^\infty \Max\nolimits_0^\infty m M
  \end{equation*}
\end{document}

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).

\documentclass{amsart}
\usepackage[english,spanish]{babel}
\pagestyle{empty}

\makeatletter

\def\Tr@nsmogrify#1#2.{\expandafter\newcommand\csname #1#2\endcsname
{\mathchardef\Tr@ns@temp=\mathcode\lccode`#1\relax
\mathcode\lccode`#1=\mathcode`#1\lowercase{\csname#1#2\endcsname}%
\mathcode\lccode`#1=\Tr@ns@temp\relax}}

\@for\x:=Sin,Cos,Max,Min,Lim,Limsup,Liminf,Inf\do{%
\expandafter\Tr@nsmogrify \x.}

\makeatother

\begin{document}

\thispagestyle{empty}
\noindent
\begin{minipage}{.5\linewidth}
  \begin{align*}
\min_0^\infty &= \Min_0^\infty\\
\min\nolimits_0^\infty &= \Min\nolimits_0^\infty\\
\max_0^\infty &= \Max_0^\infty\\
\lim_{x\to\infty} &= \Lim_{x\to\infty}\\
\liminf_{x\to\infty} &= \Liminf_{x\to\infty}\\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
\inf_{x\in A} &= \Inf_{x\in A}\\
\sin^2 x +\cos^2 x  &= \Sin^2 x +\Cos^2 x \\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
m,M,l,L&,s,S,c,C
  \end{align*}
\end{minipage}
\begin{minipage}{.5\linewidth}
\selectlanguage{english}%
  \begin{align*}
\min_0^\infty &= \Min_0^\infty\\
\min\nolimits_0^\infty &= \Min\nolimits_0^\infty\\
\max_0^\infty &= \Max_0^\infty\\
\lim_{x\to\infty} &= \Lim_{x\to\infty}\\
\liminf_{x\to\infty} &= \Liminf_{x\to\infty}\\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
\inf_{x\in A} &= \Inf_{x\in A}\\
\sin^2 x +\cos^2 x  &= \Sin^2 x +\Cos^2 x \\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
m,M,l,L&,s,S,c,C
  \end{align*}
\end{minipage}
\end{document}

Here is the result:

PNG image with english and spanish operators with first letter made uppercase

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 the a and b 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:

different behaviors of limits

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 of amsmath (or rather amsopn.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 in amsopn.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 analogous amsmath provided names with respect to limits.

examples of operator names with \limits

share|improve this answer
    
\newcommand\Max{\mathop{\mathcode`m=\mathcode`M \max}\displaylimits} is easier, isn't it? By the way, your \relax is not needed: \@tempcnta is unexpandable, so it stops the search for a number. –  egreg Oct 18 '12 at 19:46
    
@egreg: thanks. See my edited reply for an extension to my initial proposal. And what is the rôle of \displaylimits? –  jfbu Oct 18 '12 at 20:53
    
The problem with this general definition is that every new operator will receive limits above and below in display math mode, because it's the default setting for a \mathop: try \[\Sin^{2}x\]. In my suggestion \displaylimits is not really necessary; but the proper definition for \Sin would be \mathop{\mathcode`s=\mathcode`S \sin}\nolimits –  egreg Oct 18 '12 at 20:58
    
@egreg: I remember now these limits things (always found this terminology chosen by Knuth weird). Well, I will revert to using \@tempcnta then, or perhaps I can use \mathcode0. Ok, let's put it in. –  jfbu Oct 18 '12 at 21:50
1  
@VicentGiner-Bosch thank you for the problem which got me very much interested the other day! but do I deserve your vote? ;-) because now that I look closely I see that \Inf did not work, this is normal as my method in that case would have replaced i by I, but the i had already been transformed by babel into í ... –  jfbu Oct 23 '12 at 21:41
show 7 more comments

I would prefer a clean definition of \Max:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator*{\Max}{Max}

\begin{document}
\begin{gather*}
\max_0^\infty = \Max_0^\infty
\end{gather*}
\end{document}

Result

Patch solution

This example defines \Max by copying the definition from \max via package letltxmacro, because \max was defined via \DeclareRobustCommand. Then max is exchanged by Max in the internal macro via package etoolbox:

\documentclass{article}
\usepackage{amsmath}
\usepackage{letltxmacro}
\usepackage{etoolbox}

\LetLtxMacro\Max\max
\patchcmd\Max{max}{Max}{}{}

\begin{document}
\begin{gather*}
\max_0^\infty = \Max_0^\infty
\end{gather*}
\end{document}

Update: With Spanish accents

\documentclass[fleqn]{article}
\usepackage[english,spanish]{babel}
\usepackage{amsmath}

\makeatletter
\DeclareMathOperator*{\en@Max}{Max}
\DeclareMathOperator*{\es@Max}{M\es@op@ac{a}x}
\addto\es@operators{%
  \let\Max\es@Max
}
\providecommand*{\nomathspanish}{}
\addto\nomathspanish{%
  \let\Max\en@Max
}
\makeatother

\begin{document}

Spanish:
\begin{gather*}
\max_0^\infty = \Max_0^\infty
\end{gather*}

\selectlanguage{english}
English:
\begin{gather*}
\max_0^\infty = \Max_0^\infty
\end{gather*}

\end{document}

Result

share|improve this answer
    
that doesn't solve my problem, as \max doesn't produce "max" but "máx" when using babel with spanish as an option. So what I would like to achieve is a definition that is valid for all possible transformations that babel(and/or other packages) could perform on the original \max command. –  Vicent Oct 18 '12 at 16:56
    
@egreg, I'm sorry but I think I was specific enough, as I mentioned babel on my question. Anyway, I am going to edit it in order to make it clearer, if possible. –  Vicent Oct 18 '12 at 17:04
    
@VicentGiner-Bosch If you just want to get rid of the math operator redefinitions of babel's spanish: \makeatletter\let\es@operators\relax\makeatother. –  Heiko Oberdiek Oct 18 '12 at 17:05
    
no, I don't want to get rid of it, but take it into account! –  Vicent Oct 18 '12 at 17:11
add comment

There's no real possibility to simply uppercase the first letter. You have two strategies available for defining a new operator. I'll make examples for a three language document.

Strategy 1

Define a default string and auxiliary strings for the languages where the form must change.

\documentclass{article}
\usepackage{amsmath}
\usepackage[english,italian,spanish]{babel}

% the new operator
\DeclareMathOperator{\Max}{\Maxname}
% default string
\newcommand{\defaultMaxname}{Max}
\let\Maxname\defaultMaxname 
% English and Italian want "Max"
% Spanish wants a different name, "Máx"
\newcommand{\spanishMaxname}{M\acute{a}x}
\addto\extrasspanish{\let\Maxname\spanishMaxname}
\addto\noextrasspanish{\let\Maxname\defaultMaxname}
%%%

\begin{document}
Esto es $\Max$

\begin{otherlanguage}{english}
This is $\Max$
\end{otherlanguage}

\selectlanguage{italian}    
Questo \`e $\Max$

\end{document}

The output will be

Esto es Máx
This is Max
Questo è Max

However, otherlanguage* and \foreignlanguage won't change the behavior and in those contexts you'll get "Máx" as in the default language, in this case Spanish.

Strategy 2

Define explicitly the string for all languages you plan to use.

\documentclass{article}
\usepackage{amsmath}
\usepackage[english,italian,spanish]{babel}


\DeclareMathOperator*{\Max}{\Maxname}
\newcommand{\englishMaxname}{Max}
\newcommand{\italianMaxname}{Max}
\newcommand{\spanishMaxname}{M\acute{a}x}

\let\Maxname\englishMaxname % default
\addto\extrasenglish{\let\Maxname\englishMaxname}
\addto\extrasitalian{\let\Maxname\italianMaxname}
\addto\extrasspanish{\let\Maxname\spanishMaxname}

\begin{document}
Esto es $\Max$

\begin{otherlanguage*}{english}
This is $\Max$
\end{otherlanguage*}

\foreignlanguage{italian}{Questo \`e $\Max$}

\end{document}

The output will be

Esto es Máx
This is Max
Questo è Max

exactly as before, but also otherlanguage* and \foreignlanguage will respect the language setting.


share|improve this answer
    
And what if I would like to do it sort of language-independent?? –  Vicent Oct 18 '12 at 17:11
    
@VicentGiner-Bosch What do you mean? This is language independent: the behavior changes when you change the language. The Spanish module for babel defines its own version of \max. I'll edit the answer anyway. –  egreg Oct 18 '12 at 17:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.