81

I'd like to declare some new operators using \DeclareMathOperator and some of the names are already taken by other commands (that I do not want to use). Is there an equivalent to the \renewcommand command for \DeclareMathOperator or a different way to overwrite the commands using \DeclareMathOperator?

1
  • 4
    if the names you want to re-use are names of operators or symbols, that's probably safe. but beware of command names like \span which is used "under the covers" as a structural modifier in tables and alignments. you could get some very bad surprises from redefining that command. also, redefining the single-letter commands for accents could make your (or an editor's) life miserable if such accents appear in names in a bibliography. May 5, 2014 at 12:44

1 Answer 1

95

No interface for this has been provided, which I believe is a mistake. A simple workaround is to remove the definition of the command before redeclaring it:

\let\ln\relax
\DeclareMathOperator{\ln}{log} % this is how the logarithm should be denoted

A \RedeclareMathOperator command could be defined as follows

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand\RedeclareMathOperator{%
  \@ifstar{\def\rmo@s{m}\rmo@redeclare}{\def\rmo@s{o}\rmo@redeclare}%
}
% this is taken from \renew@command
\newcommand\rmo@redeclare[2]{%
  \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
  \expandafter\@ifundefined\@gtempa
     {\@latex@error{\noexpand#1undefined}\@ehc}%
     \relax
  \expandafter\rmo@declmathop\rmo@s{#1}{#2}}
% This is just \@declmathop without \@ifdefinable
\newcommand\rmo@declmathop[3]{%
  \DeclareRobustCommand{#2}{\qopname\newmcodes@#1{#3}}%
}
\@onlypreamble\RedeclareMathOperator
\makeatother

\DeclareMathOperator{\ln}{log} % gives error
\RedeclareMathOperator{\ln}{log} % is accepted
\RedeclareMathOperator{\foo}{foo} % gives error
\RedeclareMathOperator*{\deg}{deg} % now \deg typesets limits below and above

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .