# cases

Used for piecewise-defined expressions with a left brace and two aligned columns

https://texform.dev/latex/environments/cases

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Alignment](https://texform.dev/latex/topics/alignment) |
| Packages | ams |
| Allowed mode | math |
| Tags | matrix, nestable |
| Commonality | high |
| Body mode | math |

## Syntax

### ams

Argument specification: ``

Used for piecewise-defined expressions with a left brace and two aligned columns

## Common tasks

### How to write a piecewise function

```latex
\begin{cases} x & x\ge 0 \\ -x & x<0 \end{cases}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bcases%7D+x+%26+x%5Cge+0+%5C%5C+-x+%26+x%3C0+%5Cend%7Bcases%7D)

### How to write a piecewise definition with text

```latex
f(x)=\begin{cases} 1 & \text{if } x\in\mathbb{Q} \\ 0 & \text{otherwise} \end{cases}
```

[Open in Playground](https://play.texform.dev/?input=f%28x%29%3D%5Cbegin%7Bcases%7D+1+%26+%5Ctext%7Bif+%7D+x%5Cin%5Cmathbb%7BQ%7D+%5C%5C+0+%26+%5Ctext%7Botherwise%7D+%5Cend%7Bcases%7D)

### How to write a system as cases

A single column is enough when there is no condition to align.

```latex
\begin{cases} x+y=1 \\ x-y=0 \end{cases}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bcases%7D+x%2By%3D1+%5C%5C+x-y%3D0+%5Cend%7Bcases%7D)

## Examples

```latex
\begin{cases} x & \text{if } x > 0 \\ 0 & \text{otherwise} \end{cases}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Bcases%7D+x+%26+%5Ctext%7Bif+%7D+x+%3E+0+%5C%5C+0+%26+%5Ctext%7Botherwise%7D+%5Cend%7Bcases%7D)

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| ams | full | full | full |

## Usage frequency

1.42% of formulas in the measured corpus contain this entry, rank 10 of 31 entries with frequency data.

## In TeXForm

TeXForm reads the environment body in math mode.

## See also

- [bmatrix](https://texform.dev/latex/environments/bmatrix)
- [Bmatrix](https://texform.dev/latex/environments/Bmatrix)
- [matrix](https://texform.dev/latex/environments/matrix)
- [pmatrix](https://texform.dev/latex/environments/pmatrix)
- [smallmatrix](https://texform.dev/latex/environments/smallmatrix)
- [subarray](https://texform.dev/latex/environments/subarray)
- [vmatrix](https://texform.dev/latex/environments/vmatrix)
- [Vmatrix](https://texform.dev/latex/environments/Vmatrix)

## Test cases

### ams

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \begin{cases} a & b \\\\ c & d \end{cases} | Positive: baseline | Pass | Pass | Pass |
