# \expval

Used in quantum mechanics to denote expectation values of operators

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

## Metadata

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

## Syntax

### physics

Argument specification: `s s m g`

Used in quantum mechanics to denote expectation values of operators

## Examples

```latex
\expval{A}
```

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

```latex
\expval*{A}
```

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

```latex
\expval**{A}
```

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

```latex
\expval{A}{B}
```

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

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

[Open in Playground](https://play.texform.dev/?input=%5Cexpval**%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
\expval{#1}{#2}
```

→

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

Depends on star modifiers: no stars adds \left/\right, one star uses none, two stars uses \middle too. If no second argument, it's just \langle{#1}\rangle.

## Equivalent forms

```latex
\expectationvalue{A}
```

exact. Long form of \expval

```latex
\ev{A}
```

exact. Alternative short alias

## See also

- [\\ev](https://texform.dev/latex/commands/ev)
- [\\expectationvalue](https://texform.dev/latex/commands/expectationvalue)

## Test cases

### physics

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