8

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

3
  • You could just do \DeclareMathOperator*{\plim}{-lim} and use it in math mode as p\plim and (p+q)\plim. (Not very logic markup like …) Sep 19, 2012 at 17:17
  • @Qrrbrbirlbel, this will put too much of a space between "p" and "-lim". The is also the trouble with $p\text{-}\lim$, except now the space is on the other side. Another issue with both is that in display mode the subscript is centered below -lim (or lim) and not under p-lim.
    – Jason Rute
    Sep 19, 2012 at 17:35
  • Borrow from egreg's answer \DeclareMathOperator*{\plim}{\mkern-1mu-lim} and adjust. I didn't thought about a subscript, though. For that you still need the full operator without the need to manually align the subscript. Sep 19, 2012 at 17:48

2 Answers 2

13

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}
}
2
  • Thanks! I didn't know about mathnormal. Also your spacing looks best. I also realize from your explanation that one needs to be careful if a minus sign is in the argument. It will show as a dash. (Luckily, my application doesn't use "p-q" as an argument to the limit.)
    – Jason Rute
    Sep 19, 2012 at 17:43
  • 1
    @JasonRute I've added a trick for getting a real minus sign in the argument.
    – egreg
    Sep 19, 2012 at 18:11
2

You can achieve the same as in egreg's answer, without amsmath nor AtBeginDocument trick:

\documentclass{article}

\newcommand\plim{\mathop{p\mkern2mu\mathrm{\mathchar"702D lim}}}

\begin{document}
$\plim_{a\to\infty}$

$\displaystyle\plim_{a\to\infty}$
\end{document}

Sometimes the math alphabet command \mathrm does not use the same font as would be used in operator names. So the following slightly more complicated solution does it:

\makeatletter
\newcommand\plim{\mathop{p\mkern2mu{\operator@font\mathchar"702D lim}}}
\makeatother

And regarding the hardcoding of the text hyphen slot, ... well one can complicate the code if one wishes to go around this problem. By the way I am not sure I correctly understood the OP, as here I tried my best to use the hyphen slot (ascii code 45) from the a text font (shorter usually than a minus sign), and not a \textendash which looks more like a minus sign.

(Sorry I got slightly confused in my explanations, as the math symbol font operators (used - if it has not been modified - by \operator@font) is not necessarily 'the' document 'text' font, not is it necessarily the font used by \mathrm (although it is in the default set-up) but it is at any rate 'a' font, hence my striking out edit in the paragraph above.)

2
  • The purpose of \minusmathcode is avoiding to hardwire a number which might not be correct: family 0 usually refers to the text font, but it is not always true.
    – egreg
    Oct 26, 2012 at 6:43
  • In the initial font set-up in math mode for TeX/LaTeX, there are 4 fonts: the operators (digits, uppercase Greek, the plus sign, ..., used for log-like names), the letters (Latin letters, lowercase Greek), the symbols (includes the calligraphic alphabet), and the large symbols (\sum, delimiters). And the minus sign $-$ is slot 0 is the symbols font. Slot 45 of the operators font gives a hyphen-like character, shorter. Slot 43 of the operators font is the plus sign $+$. Notice the awkwardness of this: slot 43 of one font must match in length slot 0 of another font!
    – user4686
    Oct 26, 2012 at 7:41

You must log in to answer this question.

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