# \commutator

Used in quantum mechanics and algebra to denote the commutator [A,B] = AB - BA of two operators or elements

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

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Physics: quantities](https://texform.dev/latex/topics/physics-quantities) |
| Packages | physics |
| Allowed mode | math |
| Tags |  |
| Commonality | medium |
| Kind | prefix |

## Syntax

### physics

Argument specification: `s m{} m`

Used in quantum mechanics and algebra to denote the commutator [A,B] = AB - BA of two operators or elements

## Examples

```latex
\commutator{A}{B}
```

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

```latex
\commutator*{A}{B}
```

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

## Renderer support

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

## In TeXForm

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

### Expands to (physics)

```latex
\commutator{A}{B}
```

→

```latex
\left[A,B\right]
```

With star: [A,B] without \left/\right. With optional \big, \Big, \bigg, or \Bigg prefix: uses corresponding \bigl[...\bigr] sizing.

## See also

- [\\acomm](https://texform.dev/latex/commands/acomm)
- [\\anticommutator](https://texform.dev/latex/commands/anticommutator)
- [\\comm](https://texform.dev/latex/commands/comm)
- [\\pb](https://texform.dev/latex/commands/pb)
- [\\poissonbracket](https://texform.dev/latex/commands/poissonbracket)

## Test cases

### physics

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \commutator{a}{b} | Positive: baseline | Pass | Fail | Pass |
| \commutator*{a}{b} | Positive: vary:s[0] | Pass | Fail | Pass |
| \commutator{a}b | Positive: bare[2] | Pass | Fail | Pass |
