# Cases with square brackets

How can I subdivide in cases with square brackets?

I mean I want to write:

⌈ 2_i        if ...
rank (q, l) = | 2_i + 1    if ...
⌊ ....

with square brackets, not braces.

• I tried to rewrite your question so that it is more easily understood. I hope I understood it correctly. If not, please change it back. Feb 26 '11 at 22:43
• thanks for the correction, the only thing is that I do not know if the tags are corrent Feb 26 '11 at 22:49
• Usually $\{$ means "and", and $[$ means "or" --- so it is strange that the option with $[$ is not included in "cases" env. Jan 14 '19 at 19:19
• @AntonPetrunin, I think, this was a common notation in Soviet school of mathematics, but you don't commonly see that in American books. Dec 7 '19 at 10:02

You could patch the cases environment, the way Thorsten showed or using the etoolbox package and \patchcmd. However, it could be better to preserve the original cases environment and to define a new one for that purpose. Here is a way, very similar to the original definition, but also using \lbrack instead of \lbrace, I calles the new environment sqcases:

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\rank}{rank}
\makeatletter
\newenvironment{sqcases}{%
\matrix@check\sqcases\env@sqcases
}{%
\endarray\right.%
}
\def\env@sqcases{%
\let\@ifnextchar\new@ifnextchar
\left\lbrack
\def\arraystretch{1.2}%
}
\makeatother
\begin{document}
$\rank(q, l) = \begin{sqcases} 2_i & \text{if \ldots} \\ 2_i+1 & \text{if \ldots} \end{sqcases}$
\end{document}

Though it looks a bit complicated, it's very straightforward: I took the original cases definition of amsmath.sty, wrote sqcases instead and replaced \lbrace by \lbrack. I had to use \makeatletter and \makeatother because of the @ symbol in the original amsmath commands.

For completeness, heres the way using patching:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\env@cases}{\lbrace}{\lbrack}
\makeatother

After loading etoolbox, the respective internal amsmath macro is changed to use \lbrack instead of \lbrace. It's a bit hazardous to patch internal commands, but it's a quick way and may even work after changes in amsmath while our new definition could become different to cases then. At least it's good to know such methods.

It only requires a slight modification.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\def\env@cases{%
\let\@ifnextchar\new@ifnextchar
\left\lbrack
\def\arraystretch{1.2}%
}
\makeatother

\begin{document}
$\begin{cases} 0 \\ 1 \\ 2 \end{cases}$
\end{document}

This is the original code from amsmath where only \lbrace has been replaced by \lbrack.

• Are you sure? doing so does not work Feb 26 '11 at 22:54
• Works fine for me as is. Feb 26 '11 at 22:57
• @Thorsten: Maybe you could add an explanation so that people who are not well versed with the internals of LaTeX can understand what that does. Feb 26 '11 at 22:57
• Did you copy the code from Thorsten's example? It works as advertised. Are you getting an error? Feb 26 '11 at 22:58
• @Caramdir: I added a short (but hopefully sufficient) explanation. Feb 26 '11 at 23:02

A Plain "extension" to support such constructs:

\catcode@=11
\def\caseswithdelim#1#2{\left#1\,\vcenter{\normalbaselines\m@th
\ialign{\strut$##\hfil$&\quad##\hfil\crcr#2\crcr}}\right.}% you might like it without the \strut
\catcode@=12
%
\def\bcases#1{\caseswithdelim[{#1}}
\def\vcases#1{\caseswithdelim|{#1}}
%
$$\displaylines{ rank (q,l) = \cases{2_i& if \ldots\cr 2_i + 1&if \ldots\cr\ldots} \cr rank (q,l) = \bcases{2_i& if \ldots\cr 2_i + 1&if \ldots\cr\ldots} \cr rank (q,l) = \vcases{2_i& if \ldots\cr 2_i + 1&if \ldots\cr\ldots} }$$\bye

In addition to the answers above I would like to present another comprehensible solution to the problem.

\begin{align}
\left[
\begin{array}{ll}
x = 1 & a > 0 \\
x = 2 & \text{otherwise}
\end{array}
\right .
\end{align}
• Welcome to the TeX.SE. Then, do you have given an answer for the old question where all the answers are right? Can you explain your criticism, please? Nov 5 '20 at 20:47
• @Sebastiano the accepted answer produces an error because it is using an outdated matrix environment. Nov 5 '20 at 20:49
• What is the specific error, please? Nov 5 '20 at 20:53
• @Sebastiano hm, seems to be working now. It was complaining Package amsmath Error: Old form `\matrix' should be \begin{matrix}. \end{align} Nov 5 '20 at 20:55
• Sorry, but I am not agree with you. Nov 5 '20 at 20:57