# \ketbra

Used for outer products or bra-ket operators in Dirac notation, combining a ket and a bra in one construct.

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

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Physics: bra-ket](https://texform.dev/latex/topics/physics-braket) |
| Packages | braket, physics |
| Allowed mode | math |
| Tags |  |
| Commonality | low |
| Kind | prefix |

## Syntax

### braket

Argument specification: `m m`

Used for outer products or bra-ket operators in Dirac notation, combining a ket and a bra in one construct.

### physics

Argument specification: `s m g`

Used for ket-bra operators and projectors in quantum mechanics, e.g. |\psi\rangle\langle\phi| or |\psi\rangle\langle\psi|.

## Examples

```latex
\ketbra a b
```

[Open in Playground](https://play.texform.dev/?input=%5Cketbra+a+b)

```latex
\ketbra{a}
```

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

```latex
\ketbra*{a}
```

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

```latex
\ketbra{a}{b}
```

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

```latex
\ketbra*{a}{b}
```

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

## Package variants

| Package | Argument specification | Allowed mode | Description |
| --- | --- | --- | --- |
| braket | m m | math | Used for outer products or bra-ket operators in Dirac notation, combining a ket and a bra in one construct. |
| physics | s m g | math | Used for ket-bra operators and projectors in quantum mechanics, e.g. \|\psi\rangle\langle\phi\| or \|\psi\rangle\langle\psi\|. |

## Renderer support

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

## In TeXForm

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

### Expands to (braket)

```latex
\ketbra{#1}{#2}
```

→

```latex
{\vert {#1} \rangle\langle {#2} \vert}
```

Both arguments are read with GetArgument, so each can be a single token without braces.

### Expands to (physics)

```latex
\ketbra{#1}{#2}
```

→

```latex
\left\vert{#1}\middle\rangle\!\middle\langle{#2}\right\vert
```

This is the unstarred two-argument branch. If the second argument is omitted, MathJax reuses #1 in its place; the starred form instead reparses \vert{#1}\rangle\!\langle{#2}\vert without \left/\middle/\right sizing.

## Equivalent forms

```latex
{\vert {#1} \rangle\langle {#2} \vert}
```

exact. 

```latex
\outerproduct{#1}{#2}
```

exact. Same MathJax parser behavior, including the optional star and the omitted-second-argument default to the first argument.

```latex
\dyad{#1}{#2}
```

exact. Same MathJax parser behavior, including the optional star and the omitted-second-argument default to the first argument.

```latex
\op{#1}{#2}
```

exact. Same MathJax parser behavior, including the optional star and the omitted-second-argument default to the first argument.

## See also

- [\\bmod](https://texform.dev/latex/commands/bmod)
- [\\bmqty](https://texform.dev/latex/commands/bmqty)
- [\\boxed](https://texform.dev/latex/commands/boxed)
- [\\bra](https://texform.dev/latex/commands/bra)
- [\\Bra](https://texform.dev/latex/commands/Bra)
- [\\dyad](https://texform.dev/latex/commands/dyad)
- [\\flatfrac](https://texform.dev/latex/commands/flatfrac)
- [\\iff](https://texform.dev/latex/commands/iff)
- [\\imathbb](https://texform.dev/latex/commands/imathbb)
- [\\imathbfbb](https://texform.dev/latex/commands/imathbfbb)
- [\\impliedby](https://texform.dev/latex/commands/impliedby)
- [\\implies](https://texform.dev/latex/commands/implies)
- [\\itextbb](https://texform.dev/latex/commands/itextbb)
- [\\itextbfbb](https://texform.dev/latex/commands/itextbfbb)
- [\\jmathbb](https://texform.dev/latex/commands/jmathbb)
- [\\jmathbfbb](https://texform.dev/latex/commands/jmathbfbb)
- [\\jtextbb](https://texform.dev/latex/commands/jtextbb)
- [\\jtextbfbb](https://texform.dev/latex/commands/jtextbfbb)
- [\\ket](https://texform.dev/latex/commands/ket)
- [\\Ket](https://texform.dev/latex/commands/Ket)
- [\\Ketbra](https://texform.dev/latex/commands/Ketbra)
- [\\LaTeX](https://texform.dev/latex/commands/LaTeX)
- [\\mathstrut](https://texform.dev/latex/commands/mathstrut)
- [\\matrixdeterminant](https://texform.dev/latex/commands/matrixdeterminant)
- [\\mdet](https://texform.dev/latex/commands/mdet)
- [\\mod](https://texform.dev/latex/commands/mod)
- [\\op](https://texform.dev/latex/commands/op)
- [\\outerproduct](https://texform.dev/latex/commands/outerproduct)
- [\\pmb](https://texform.dev/latex/commands/pmb)
- [\\pmod](https://texform.dev/latex/commands/pmod)
- [\\pmqty](https://texform.dev/latex/commands/pmqty)
- [\\Pmqty](https://texform.dev/latex/commands/Pmqty)
- [\\pod](https://texform.dev/latex/commands/pod)
- [\\qc](https://texform.dev/latex/commands/qc)
- [\\qcomma](https://texform.dev/latex/commands/qcomma)
- [\\Residue](https://texform.dev/latex/commands/Residue)
- [\\sbmqty](https://texform.dev/latex/commands/sbmqty)
- [\\skew](https://texform.dev/latex/commands/skew)
- [\\smdet](https://texform.dev/latex/commands/smdet)
- [\\spmqty](https://texform.dev/latex/commands/spmqty)
- [\\sPmqty](https://texform.dev/latex/commands/sPmqty)
- [\\stackbin](https://texform.dev/latex/commands/stackbin)
- [\\stackrel](https://texform.dev/latex/commands/stackrel)
- [\\substack](https://texform.dev/latex/commands/substack)
- [\\svmqty](https://texform.dev/latex/commands/svmqty)
- [\\TeX](https://texform.dev/latex/commands/TeX)
- [\\textbf](https://texform.dev/latex/commands/textbf)
- [\\textit](https://texform.dev/latex/commands/textit)
- [\\textnormal](https://texform.dev/latex/commands/textnormal)
- [\\textrm](https://texform.dev/latex/commands/textrm)
- [\\textsf](https://texform.dev/latex/commands/textsf)
- [\\texttt](https://texform.dev/latex/commands/texttt)
- [\\textup](https://texform.dev/latex/commands/textup)
- [\\varinjlim](https://texform.dev/latex/commands/varinjlim)
- [\\varliminf](https://texform.dev/latex/commands/varliminf)
- [\\varlimsup](https://texform.dev/latex/commands/varlimsup)
- [\\varprojlim](https://texform.dev/latex/commands/varprojlim)
- [\\vmqty](https://texform.dev/latex/commands/vmqty)
- [\\zeromatrix](https://texform.dev/latex/commands/zeromatrix)
- [\\zmat](https://texform.dev/latex/commands/zmat)

## Test cases

### braket

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \ketbra{a}{b} | Positive: baseline | Pass | Fail | Fail |
| \ketbra a{b} | Positive: bare[0] | Pass | Fail | Fail |
| \ketbra{a}b | Positive: bare[1] | Pass | Fail | Fail |

### physics

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