Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Defining a new log-like function in LaTeX

Use the \mathop command, as in:

\newcommand{\diag}{\mathop{\mathrm{diag}}}

Subscripts and superscripts on \diag will be placed below and above the function name, as they are on \lim. If you want your subscripts and superscripts always placed to the right, do:

\newcommand{\diag}{\mathop{\mathrm{diag}}\nolimits}

AMSLaTeX (in its amsopn package, which is automatically loaded by amsmath) provides a command \DeclareMathOperator that takes does the same job as the first definition above. To create our original \diag command, one would say:

\DeclareMathOperator{\diag}{diag}

\DeclareMathOperator* declares the operator always to have its sub- and superscripts in the “\limits position”.

The amsopn command \operatorname allows you to introduce ad hoc operators into your mathematics, so

\[ \operatorname{foo}(bar) \]

typesets the same as

\DeclareMathOperator{\foo}{foo}
...
\[ \foo(bar) \]

As with \DeclareMathOperator there’s a starred version \operatorname* for sub- and superscripts in the limits position.

(It should be noted that “log-like” was reportedly a joke on Lamport’s part; it is of course clear what was meant.)

amsopn.sty
Distributed as part of the AMSLaTeX distribution macros/latex/required/amslatex (or browse the directory); catalogue entry


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=newfunction

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.