[Tex/LaTex] Log-like operator with math inside (e.g. p-lim)

math-modemath-operatorssymbols

I am looking to make a log-like operator that looks the same as $p \text{-lim}$.

The best way so far I found to do this is

  • \DeclareMathOperator*{\plim}{\text{$p$-lim}}

Question: Is this the best way to do this?

It seems like a bit of a hack. If I remove \text{...} then it doesn't work.

(Also, I know I can use \operatorname* to give a more flexible implementation like

  • \newcommand{\plog}[1]{\operatorname*{\text{$#1$-lim}}

where now I can change the p to, say, a p+q when needed.)

Best Answer

The argument to \DeclareMathOperator is processed in math mode, but with special settings to make hyphens not come out as minus signs. However letters will appear in roman upright type. But we have all the math mode tools available:

\DeclareMathOperator*{\plim}{\mathnormal{p}\mkern2mu-lim}

(the \mkern2mu is because the p would be too near to the hyphen.

The "variable argument" version could be

\newcommand{\plim}[1]{\operatorname*{\mathnormal{#1}\mkern2mu-lim}}

If you need also a real minus sign in the argument, then you have to restore its mathcode:

\AtBeginDocument{\edef\minusmathcode{\the\mathcode`- }}
\newcommand{\restoreminusinop}{\mathcode`-=\minusmathcode\relax}
\newcommand{\plim}[1]{%
  \operatorname*{\mathnormal{\restoreminusinop#1}\mkern2mu-lim}
}
Related Question