# \xmat

Short alias from the physics package for generating constant-entry matrices or indexed symbolic vectors/matrices without typing every cell manually, typically inside matrix-like environments.

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

## Metadata

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

## Syntax

### physics

Argument specification: `s m m:I m:I`

Short alias from the physics package for generating constant-entry matrices or indexed symbolic vectors/matrices without typing every cell manually, typically inside matrix-like environments.

## Examples

```latex
\xmat*{b}{1}{1}
```

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

```latex
\xmat*{b}{2}{1}
```

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

```latex
\begin{matrix}\xmat*{b}{1}{3}\end{matrix}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bmatrix%7D%5Cxmat*%7Bb%7D%7B1%7D%7B3%7D%5Cend%7Bmatrix%7D)

```latex
\begin{matrix}\xmat{b}{3}{2}\end{matrix}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bmatrix%7D%5Cxmat%7Bb%7D%7B3%7D%7B2%7D%5Cend%7Bmatrix%7D)

```latex
\begin{matrix}\xmat*{b}{2}{2}\end{matrix}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bmatrix%7D%5Cxmat*%7Bb%7D%7B2%7D%7B2%7D%5Cend%7Bmatrix%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
\xmat{element}{rows}{cols}
```

→

```latex
element & element & ... \\ element & element & ... (rows×cols grid)
```

Without star: repeats element literally. With star: adds subscript indices (single index for vectors, double indices for matrices).

## Equivalent forms

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

exact. Same parser method and semantics for the unstarred form.

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

exact. Same parser method and semantics for the starred form.

## See also

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

## Test cases

### physics

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \xmat{a}{1}{1} | Positive: baseline | Pass | Fail | Pass |
| \xmat*{a}{1}{1} | Positive: vary:s[0] | Pass | Fail | Pass |
| \xmat a{1}{1} | Positive: bare[1] | Pass | Fail | Pass |
| \xmat{a}1{1} | Positive: bare[2] | Pass | Fail | Pass |
| \xmat{a}{1}1 | Positive: bare[3] | Pass | Fail | Pass |
| \xmat{a}{a}{1} | Negative: neg:I[2] | Fail | Fail | Fail |
| \xmat{a}{1}{a} | Negative: neg:I[3] | Fail | Fail | Fail |
