# physics/matrixel-expand

Expand matrix elements to explicit angle-bracket and bar fences.

https://texform.dev/rules/physics/matrixel-expand

## Metadata

| Field | Value |
| --- | --- |
| Key | physics/matrixel-expand |
| Level | faithful |
| Fidelity | render |
| Enabled by packages | physics |
| Profiles | Faithful, Corpus, Equiv |

## Rewrite patterns

### matrixel-auto-sized

From:

```latex
\matrixel{#1}{#2}{#3}
```

To:

```latex
\left\langle #1 \right\vert #2 \left\vert #3 \right\rangle
```

### matrixel-fixed-size

From:

```latex
\matrixel*{#1}{#2}{#3}
```

To:

```latex
\langle #1 \vert #2 \vert #3 \rangle
```

### matrixel-middle-sized

From:

```latex
\matrixel**{#1}{#2}{#3}
```

To:

```latex
\left\langle #1 \middle\vert #2 \middle\vert #3 \right\rangle
```

## Examples

Examples show the rule in isolation, not a complete normalization profile.

### Matrix element operator

Before:

```latex
\matrixel{n}{\hat{x}}{m}=x_{nm}
```

After this rule:

```latex
\left\langle n \right\vert \hat{x} \left\vert m \right\rangle=x_{nm}
```

Packages: base, physics.

Rendering verified with the declared packages.

### Matrix element star fixed size

Before:

```latex
\matrixel*{n}{\hat{x}}{m}
```

After this rule:

```latex
\langle n \vert \hat{x} \vert m \rangle
```

Packages: base, physics.

Rendering verified with the declared packages.

### Matrix element double star middle sized

Before:

```latex
\matrixel**{n}{\hat{x}}{m}
```

After this rule:

```latex
\left\langle n \middle\vert \hat{x} \middle\vert m \right\rangle
```

Packages: base, physics.

Rendering verified with the declared packages.

## Triggers

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

## Eliminates

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

## Produces

- [\\left](https://texform.dev/latex/commands/left)
- [\\middle](https://texform.dev/latex/commands/middle)
- [\\right](https://texform.dev/latex/commands/right)

## Same family

- [physics/expectation-expand](https://texform.dev/rules/physics/expectation-expand): Expand expectation-value helpers to explicit angle brackets.
- [physics/physics-bra-expand](https://texform.dev/rules/physics/physics-bra-expand): Expand bra to an explicit angle-bracket and bar fence form.
- [physics/physics-braket-expand](https://texform.dev/rules/physics/physics-braket-expand): Expand braket to an explicit angle-bracket form with a middle bar.
- [physics/physics-ket-expand](https://texform.dev/rules/physics/physics-ket-expand): Expand ket to an explicit bar and angle-bracket fence form.
- [physics/commutator-expand](https://texform.dev/rules/physics/commutator-expand): Expand commutators to explicit square-bracket fences.
- [physics/poisson-bracket-expand](https://texform.dev/rules/physics/poisson-bracket-expand): Expand poisson brackets to explicit brace fences.

## Notes

Covers both star levels from the shared braket output helper: single star suppresses automatic sizing, double star uses middle bars with outer automatic fences.

## Disable this rule

```python
TransformEngine(profile="corpus", disable_rules=["physics/matrixel-expand"])
```

```javascript
new TransformEngine({ profile: 'corpus', disableRules: ['physics/matrixel-expand'] })
```

[Open in Playground](https://play.texform.dev/?input=%5Cmatrixel%7Bn%7D%7B%5Chat%7Bx%7D%7D%7Bm%7D%3Dx_%7Bnm%7D)
