%
% \iffalse meta-comment
%
% Copyright (C) 1995, 1999 American Mathematical Society.
% Copyright (C) 2016-2026 LaTeX Project and American Mathematical Society.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is the LaTeX Project.
%
% \fi
%
%\iffalse
%<*driver>
\documentclass{amsdtx}
\def\MaintainedByLaTeXTeam#1{%
\begin{center}%
\fbox{\fbox{\begin{tabular}{@{}l@{}}%
This file is maintained by the \LaTeX{} Project team.\\%
Bug reports can be opened (category \texttt{#1}) at\\%
\url{https://latex-project.org/bugs/}.\end{tabular}}}\end{center}}
\let\savedarg\arg
\usepackage{amsopn}
\let\arg\savedarg
\GetFileInfo{amsopn.sty}
\begin{document}
\title{The \pkg{amsopn} package}
\author{Michael Downes}
\date{Version \fileversion, \filedate}
\DocInput{amsopn.dtx}
\end{document}
%</driver>
%\fi
%
% \maketitle
% \MaintainedByLaTeXTeam{amslatex}
%
% \MakeShortVerb\|
%
% \section{Introduction}
%
%    The \pkg{amsopn} package provides a command
%    \cn{DeclareMathOperator} for defining new `math operator names'
%    similar to the standard function names \cn{sin}, \cn{lim},
%    \cn{max}, etc.
%
% \MaybeStop{}
%
%    Standard file identification.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
[1994/12/01]% LaTeX date must December 1994 or later
\ProvidesPackage{amsopn}[2022/04/08 v2.04 operator names]
%    \end{macrocode}
%
%    What \cs{nolimits@} does is keep a \cn{limits} typed by the user
%    from having any effect. This is used for operatornames whose
%    standard usage is never to have limits.
%    \begin{macrocode}
\def\nolimits@{\@ifnextchar\limits{\nolimits\@gobble}{\nolimits}}
%    \end{macrocode}
%
%    In operator names, it is sometimes desired to have text-mode
%    punctuation characters such as |*-/:'|.
%    Because the body of an
%    operator name is set in math mode, these few punctuation
%    characters will not come out right (wrong symbol and/or wrong
%    spacing). The purpose of \cs{newmcodes@} is to make them act like
%    their normal text versions.
%
%    Where practical, we use decimal numbers to cut down main mem
%    usage (\qc{\"} not needed).
%    Use |\Umathcodedefnum| with xetex and LuaTeX to avoid problems
%    using |\mathcode| if |-| has already been defined using |\Umathcode|.
% \changes{v2.02}{2016/03/08}{Unicode TeX version of \cs{newmcodes@}}
%    \begin{macrocode}
\begingroup \catcode`\"=12
\ifx\Umathcode\@undefined
\gdef\newmcodes@{\mathcode`\'39\mathcode`\*42\mathcode`\."613A%
%    \end{macrocode}
%    Define \cs{std@minus} for \cs{relbar} use; otherwise there are
%    problems with arrows constructed with relbar.
%    \begin{macrocode}
  \ifnum\mathcode`\-=45 \else
    \mathchardef\std@minus\mathcode`\-\relax
  \fi
  \mathcode`\-45\mathcode`\/47\mathcode`\:"603A\relax}
%    \end{macrocode}
%    \begin{macrocode}
\else
%    \end{macrocode}
%    \begin{macrocode}
\gdef\newmcodes@{\mathcode`\'39\mathcode`\*42\mathcode`\."613A%
  \ifnum\Umathcodenum`\-=45 \else
    \Umathcharnumdef\std@minus\Umathcodenum`\-\relax
  \fi
  \mathcode`\-45\mathcode`\/47\mathcode`\:"603A\relax}
%    \end{macrocode}
%    \begin{macrocode}
\fi
\endgroup
%    \end{macrocode}
%
%    The command \cs{operatorname} prints its argument as a `math
%    operator' like \cs{sin} or \cs{det}, with proper font and spacing.
%    \begin{macrocode}
\DeclareRobustCommand{\operatorname}{%
  \@ifstar{\qopname\newmcodes@ m}%
          {\qopname\newmcodes@ o}}%
%    \end{macrocode}
%    In the interior of the \cs{mathop} we need a null object (we choose
%    a zero kern for minimum waste of main mem) in order to guard
%    against the case where \arg{3} is a single letter; \tex/ will seize
%    it and center it on the math axis if there is nothing else inside
%    the \cs{mathop} atom.
%    \begin{macrocode}
\DeclareRobustCommand{\qopname}[3]{%
  \mathop{#1\kern\z@\operator@font#3}%
  \csname n#2limits@\endcsname}
%    \end{macrocode}
%
%  \begin{macro}{\DeclareMathOperator}
%    The command \cn{DeclareMathOperator} defines the first argument to
%    be an operator name whose text is the second argument. The star
%    form means that the operator name should take limits (like \cn{max}
%    or \cn{lim}).
%    \begin{macrocode}
\newcommand{\DeclareMathOperator}{%
  \@ifstar{\@declmathop m}{\@declmathop o}}
%    \end{macrocode}
%  \end{macro}
%
%    In the basic set of operator names (below) we did not use
%    \cn{DeclareRobustCommand} because of the hash table cost. But we
%    use it here to minimize the chances of trouble, since we are
%    producing a user-defined command.
%    \begin{macrocode}
\long\def\@declmathop#1#2#3{%
  \@ifdefinable{#2}{%
    \DeclareRobustCommand{#2}{\qopname\newmcodes@#1{#3}}}}
%
\@onlypreamble\DeclareMathOperator
\@onlypreamble\@declmathop
%    \end{macrocode}
%
% \changes{v2.04}{2022/04/08}{Make operators \cs{protected} (gh/123)}
%    \begin{macrocode}
\protected\def\arccos{\qopname\relax o{arccos}}
\protected\def\arcsin{\qopname\relax o{arcsin}}
\protected\def\arctan{\qopname\relax o{arctan}}
\protected\def\arg{\qopname\relax o{arg}}
\protected\def\cos{\qopname\relax o{cos}}
\protected\def\cosh{\qopname\relax o{cosh}}
\protected\def\cot{\qopname\relax o{cot}}
\protected\def\coth{\qopname\relax o{coth}}
\protected\def\csc{\qopname\relax o{csc}}
\protected\def\deg{\qopname\relax o{deg}}
\protected\def\det{\qopname\relax m{det}}
\protected\def\dim{\qopname\relax o{dim}}
\protected\def\exp{\qopname\relax o{exp}}
\protected\def\gcd{\qopname\relax m{gcd}}
\protected\def\hom{\qopname\relax o{hom}}
\protected\def\inf{\qopname\relax m{inf}}
\protected\def\injlim{\qopname\relax m{inj\,lim}}
\protected\def\ker{\qopname\relax o{ker}}
\protected\def\lg{\qopname\relax o{lg}}
\protected\def\lim{\qopname\relax m{lim}}
\protected\def\liminf{\qopname\relax m{lim\,inf}}
\protected\def\limsup{\qopname\relax m{lim\,sup}}
\protected\def\ln{\qopname\relax o{ln}}
\protected\def\log{\qopname\relax o{log}}
\protected\def\max{\qopname\relax m{max}}
\protected\def\min{\qopname\relax m{min}}
\protected\def\Pr{\qopname\relax m{Pr}}
\protected\def\projlim{\qopname\relax m{proj\,lim}}
\protected\def\sec{\qopname\relax o{sec}}
\protected\def\sin{\qopname\relax o{sin}}
\protected\def\sinh{\qopname\relax o{sinh}}
\protected\def\sup{\qopname\relax m{sup}}
\protected\def\tan{\qopname\relax o{tan}}
\protected\def\tanh{\qopname\relax o{tanh}}
%    \end{macrocode}
%
% \begin{macro}{\operator@font}
% \begin{macro}{\operatorfont}
%    This command is provided to allow the document styles to decide in
%    which way math operators like `max' or `log' are typeset. The
%    default is to set them in \meta{math group} zero of the current
%    math version. The original name was \cs{operator@font}, retained
%    for compatibility; the second name was added to make it
%    more accessible so that users can call this font for use in special
%    constructs that are not ordinary operator names but conceptually
%    related.
%
%    \cs{operator@font} is also declared by the \LaTeX{} kernel (for
%    at least 14 years), thus defining it here effectively means
%    ``resetting it'' to the kernel value, which is counterproductive
%    in situations where the user (or a class) has altered its
%    definition and at a later point \pkg{amsopn} got added.
% \changes{v2.03}{2022/01/20}{Do not reset \cs{operator@font} it is
%    already defined in the LaTeX kernel (gh/734)}
%    \begin{macrocode}
%\def\operator@font{\mathgroup\symoperators} % commented out in 2.03
\def\operatorfont{\operator@font}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    For backwards compatibility we keep this old command name for the
%    time being:
%    \begin{macrocode}
\def\operatornamewithlimits{\operatorname*}
%    \end{macrocode}
%
%    These macros use \cs{mathpalette}s so that they will change size
%    in script and scriptscript styles, though it's hard to imagine they
%    will ever be used there (the arrows, particularly, look bad in
%    subscript sizes). Notice that the use of \cs{ex@} means that the
%    vertical spacing may not be optimal in script and scriptscript
%    sizes. Unfortunately \tex/ provides no easy way to do math mode
%    vertical spacing that varies with current math style like mu units.
% \changes{v2.04}{2022/04/08}{Make operators \cs{protected} (gh/123)}
%    \begin{macrocode}
\protected\def\varlim@#1#2{%
  \vtop{\m@th\ialign{##\cr
    \hfil$#1\operator@font lim$\hfil\cr
    \noalign{\nointerlineskip\kern1.5\ex@}#2\cr
    \noalign{\nointerlineskip\kern-\ex@}\cr}}%
}
\protected\def\varinjlim{%
  \mathop{\mathpalette\varlim@{\rightarrowfill@\textstyle}}\nmlimits@
}
\protected\def\varprojlim{%
  \mathop{\mathpalette\varlim@{\leftarrowfill@\textstyle}}\nmlimits@
}
\protected\def\varliminf{\mathop{\mathpalette\varliminf@{}}\nmlimits@}
\def\varliminf@#1{\@@underline{\vrule\@depth.2\ex@\@width\z@
   \hbox{$#1\m@th\operator@font lim$}}}
\protected\def\varlimsup{\mathop{\mathpalette\varlimsup@{}}\nmlimits@}
\def\varlimsup@#1{\@@overline{\hbox{$#1\m@th\operator@font lim$}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\nmlimits@\displaylimits
\DeclareOption{namelimits}{\let\nmlimits@\displaylimits}
\DeclareOption{nonamelimits}{\let\nmlimits@\nolimits}
\ProcessOptions\relax
%    \end{macrocode}
%
%    If we don't load the \pkg{amsgen} package then the use of \cs{ex@}
%    in \cs{varlim@} will lead to trouble.
%    \begin{macrocode}
\RequirePackage{amsgen}\relax
%    \end{macrocode}
%
%    The usual \cs{endinput} to ensure that random garbage at the end of
%    the file doesn't get copied by \fn{docstrip}.
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
% \changes{v1.2a}{1995/02/20}{Fixed operatorname
%   (shouldn't have same limits behavior as operatorname*)}
%
% \Finale
