37

The amsmath packages helpfully define a macro \DeclareMathOperator which does what it says on the tin: it declares a mathematical operator such as \sin or \Null or whatever and typesets it all nice and dandy.

If I want to do a one-shot operator, it seems a bit of a fuss to \DeclareMathOperator it if I'm only going to use it once. So:

Is there a command that typesets its contents in the same way that \DeclareMathOperator does? (And I'd like it to be exactly how \DeclareMathOperator does since I sometimes mess with fonts and colours and would like them consistent.)

3
  • What do you mean by \Null? Jul 4, 2013 at 11:55
  • @LoverofStructure (Firstly, I'd've put that link as a comment rather than adding to the question.) I mean that I can do \DeclareMathOperator{\Null}{Null} to allow me to write \Null in the document. I generally use it for the null space of a matrix or linear transformation. As I often teach linear algebra I use it quite a lot so I use \DeclareMathOperator to define it. But sometimes there's something that I'll only use once (see my comment on Yiannis' answer), hence this question. Jul 4, 2013 at 12:31
  • 2

2 Answers 2

32

You are looking for \mathop: http://www.giss.nasa.gov/tools/latex/stackrel.html , for example \mathop{\sum \sum}_{i,j=1}^{N} a_i a_j.

If you really want to do exactly what amsmath does then \operatorname is a better choice.

5
  • 1
    TeX in space?! Something new every day.. Mar 4, 2011 at 12:31
  • 17
    \mathop doesn't seem to make its argument \mathrm as is default for operators. I think the right approach is to use \operatorname and then, if you need subscripts etc, wrap that in a \mathop
    – Seamus
    Mar 4, 2011 at 12:40
  • @Seamus see my post below for font.
    – yannisl
    Mar 4, 2011 at 12:49
  • 13
    @Seamus \operatorname* is the variant you need if you want to have limits.
    – cefstat
    Mar 4, 2011 at 12:57
  • 2
    You can even try this [\operatornamewithlimits{K}_{k=0}^\infty\frac{a_k}{b_k}\]
    – yannisl
    Mar 5, 2011 at 19:31
9

You can go back to the TeXbook and do it the Knuth way, using \mathop

\def\limsup{\mathop{\overline{\rm lim}}}

\[\limsup\]

Edit

If you really only want a one shot, you can type:

\[\mathop{\overline{lim}}_{n=1}\limits\]

I would rather have something like:

\def\oneshot#1{\mathop{\mathrm{#1}}\limits}

\[\oneshot{Diag}_{n=1}^m\]

One can extend the command \oneshot to the \nolimits version for consistency. Why I prefer a two shot approach i.e, defining it first and then using it, is that good software practice dictates that you should try and re-use code. You could stick the command in your master style file, if you have one. It will also with a shorter name make reading the LaTeX source easier.

Would you really use an operator only once in a mathematics write-up?

7
  • 3
    if you're using latex, better to use \mathrm: \def\limsup{\mathop{\overline{\mathrm{lim}}}} or just look into the file amsopn.sty and see how \DeclareMathOperator is defined. it's a bit convoluted, but you're good enough at latex innards to figure it out. do take note of the use of `\limits'. Mar 4, 2011 at 13:19
  • 1
    @Yiannis: It doesn't really make sense to wrap this in a \def (or better \newcommand): As the title says, this is about a one-shot math operator. Mar 5, 2011 at 8:39
  • 1
    @Hendrik Vogt For a one shot one can only use \overline{lim} if you are not too worried about side-effects, or \mathop{\overline{lim}}. I wouldn't use newcommand in this case as def can be overwritten much easier and is less typing. One-shot is not a recommended approach from a programming perspective, so I would recommend one takes two shots!
    – yannisl
    Mar 5, 2011 at 10:41
  • 1
    @Hendrik Vogt Only advantage is that you don't need amsmath. Another is that you do not need to define it as with the DeclareMathOperator in the preamble only. See also my edited answer for some more thoughts on the subject.
    – yannisl
    Mar 5, 2011 at 16:17
  • 1
    @Yiannis: I like your edited answer much better: You explain why you chose to not make it a one-shot. Thanks a lot! Mar 5, 2011 at 18:38

You must log in to answer this question.

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