# \DeclareMathOperator

Defines a custom named math operator once, so later uses like \foo behave as proper operators (e.g. for custom operators such as argmax, rank, or Res).

https://texform.dev/latex/commands/DeclareMathOperator

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Functions and operators](https://texform.dev/latex/topics/functions) |
| Packages | ams |
| Allowed mode | math |
| Tags | invisible, newdefine |
| Commonality | medium |
| Kind | prefix |

## Syntax

### ams

Argument specification: `s m:N m:O`

Defines a custom named math operator once, so later uses like \foo behave as proper operators (e.g. for custom operators such as argmax, rank, or Res).

## Examples

```latex
\DeclareMathOperator{foo}{foo}
```

[Open in Playground](https://play.texform.dev/?input=%5CDeclareMathOperator%7Bfoo%7D%7Bfoo%7D)

```latex
\DeclareMathOperator*{foo}{foo}
```

[Open in Playground](https://play.texform.dev/?input=%5CDeclareMathOperator*%7Bfoo%7D%7Bfoo%7D)

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| ams | full | none | none |

## In TeXForm

TeXForm parses this entry as prefix syntax; the package determines its argument specification.

### Expands to (ams)

```latex
\DeclareMathOperator{\cs}{op}
```

→

```latex
\newcommand{\cs}{\operatorname{op}}
```

The starred form \DeclareMathOperator* expands to \operatorname* instead. This is a runtime macro definition that creates a new command.

## Test cases

### ams

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \DeclareMathOperator{a}{b} | Positive: baseline | Pass | Fail | Fail |
| \DeclareMathOperator*{a}{b} | Positive: vary:s[0] | Pass | Fail | Fail |
| \DeclareMathOperator a{b} | Positive: bare[1] | Pass | Fail | Fail |
| \DeclareMathOperator{a}b | Positive: bare[2] | Pass | Fail | Fail |
| \DeclareMathOperator{\alpha}{a} | Negative: neg:N[1] | Pass | Fail | Fail |
