28

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

  • What do you mean by \Null? – Lover of Structure Jul 4 '13 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. – Loop Space Jul 4 '13 at 12:31
25

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.

  • TeX in space?! Something new every day.. – Martin Tapankov Mar 4 '11 at 12:31
  • 14
    \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 '11 at 12:40
  • @Seamus see my post below for font. – Yiannis Lazarides Mar 4 '11 at 12:49
  • 10
    @Seamus \operatorname* is the variant you need if you want to have limits. – cefstat Mar 4 '11 at 12:57
  • 1
    You can even try this [\operatornamewithlimits{K}_{k=0}^\infty\frac{a_k}{b_k}\] – Yiannis Lazarides Mar 5 '11 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?

  • 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'. – barbara beeton Mar 4 '11 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. – Hendrik Vogt Mar 5 '11 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! – Yiannis Lazarides Mar 5 '11 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. – Yiannis Lazarides Mar 5 '11 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! – Hendrik Vogt Mar 5 '11 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.