Debian Codegraph @

texmf-dist/doc/latex/cases/cases.tex

raw
1 \documentclass[DIV=9, pagesize=auto]{scrartcl}
2
3 \usepackage{lmodern}
4 \usepackage[T1]{fontenc}
5 \usepackage{textcomp}
6 \usepackage{amsmath}
7 \usepackage{cases}
8 \usepackage{microtype}
9 \usepackage{shortvrb}
10 \usepackage[colorlinks]{hyperref}
11 \MakeShortVerb"
12 \newcommand*\kp[1]{\kern#1pt}
13 \newcommand*{\fancybreak}{%
14 \par \medbreak \vspace{0pt plus 1cm}\penalty 500 \vspace{0pt plus -1cm}%
15 }
16 \newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}}
17 \newcommand*{\pkg}[1]{\textsf{#1}}
18 \newcommand*{\cmd}[1]{\texttt{\string#1}}
19 \newcommand*{\env}[1]{\texttt{#1}}
20 \newcommand*{\meta}[1]{\textlangle\textsl{#1}\textrangle}
21 \newcommand*{\opt}[1]{\texttt{[#1]}}
22
23 %\addtokomafont{title}{\rmfamily}
24
25 \title{The \pkg{cases} package%
26 \textnormal{\thanks{~~This manual corresponds to \pkg{cases}~v3.2, dated 2020/03/29.}}}
27 \author{Donald Arseneau\\\mail{[email protected]}}
28 \date{Mar 2020}
29
30
31 \begin{document}
32
33 \maketitle
34
35 \begin{small}
36 \noindent
37 Copyright \textcopyright~1993, 1994, 1995, 2000, 2002, 2020 by Donald Arseneau, \mail{[email protected]}.
38 These macros may be freely transmitted, reproduced, or modified
39 provided that this notice is left intact. Sub-equation numbering
40 is based on \pkg{subeqn.sty} by Stephen Gildea; parts are based
41 on \LaTeX's \env{eqnarray} by Leslie Lamport and the \LaTeX3 team;
42 and some on amsmath.sty by the American Mathematical Society.
43 \par
44 \end{small}
45
46 \section*{Description}
47
48 The \pkg{cases} package provides a \LaTeX\ environment \env{numcases} to produce
49 multi-case equations with a separate equation number for each case. There is
50 also \env{subnumcases} which numbers each case with the overall equation
51 number plus a letter [8a, 8b, etc.]. The syntax is
52 %
53 \begin{flushleft}
54 "\begin{numcases}{"~\meta{left side}~"}"\\
55 \quad \meta{case 1\kp1} "&" \meta{explanation 1\kp1} "\\" \\
56 \quad \meta{case 2\kp2} "&" \meta{explanation 2\kp2} "\\" \\
57 \quad .~.~.\\
58 \quad \meta{case $n$} "&" \meta{explanation $n$} \\
59 "\end{numcases}"
60 \end{flushleft}
61 %
62 Each \meta{case} is a math formula, to be typeset in display-math mode, like
63 in a regular numbered equation. Each \meta{explanation} is a piece of lr-mode
64 text (which may contain math mode in "\("\,\dots"\)" or "$"\,\dots"$"). The explanations
65 are optional. Equation numbers are inserted automatically, just as for
66 the \env{eqnarray} environment. In particular, the \cmd{\nonumber} command suppresses
67 an equation number and the \cmd{\label} command allows reference to a particular
68 case. In a \env{subnumcases} environment, a \cmd{\label} in the \meta{left side} of the
69 equation gives the overall equation number, without any letter.
70
71 To use this package,
72 include "\usepackage{cases}" after \cmd{\documentclass}, and also after
73 "\usepackage{amsmath}" if you are using that.
74
75 \fancybreak
76
77 \noindent \emph{Question:} Is there a \env{numcases*} environment for
78 unnumbered cases?\\
79 \emph{Answer:} That would have the natural name \env{cases}, and it is
80 provided by \AmS-\LaTeX\ (\pkg{amsmath} package), or by this package given
81 the \opt{cases} option. It can also be achieved by using an ordinary \LaTeX\ array
82 between `"\left\lbrace\ "' and `"\right."'.
83
84 Speaking of \pkg{amsmath} and package options, there are differences between the
85 style used for this package and the cases done by \pkg{amsmath} (see below), but cases.sty
86 has options to increase compatibility. Here is the full list of options for
87 this package.
88 \begin{description}
89 \item[\opt{subnum}] Force all \env{numcases} environments to be treated as
90 \env{subnumcases}.
91 \item[\opt{amsstyle}] For compatibility with \pkg{amsmath}'s \env{cases}, make \env{numcases}
92 use cramped math style (\cmd{\textstyle}), and put explanations in the same math style.
93 \item[\opt{casesstyle}] Change \pkg{amsmath}'s \env{cases} environment to work in the text/math style
94 of \env{numcases}.
95 \item[\opt{cases}] Define a \env{cases} environment for use without \pkg{amsmath}. (This
96 is actually the same as the \opt{casesstyle} option.)
97 \item[\opt{fleqn}] Flush-left equation alignment, indented by \cmd{\mathindent}
98 or \cmd{\mathmargin}. (Usually inherited from the \cmd{\documentclass} options.)
99 \item[\opt{leqno}] Left-side equation numbering (usually inherited from the \cmd{\documentclass}
100 options). This looks silly with numbered cases!
101 \end{description}
102
103 \section*{Examples}
104
105 A simple example is:
106 %
107 \begin{verbatim}
108 \begin{numcases} {|x|=}
109 x, & for $x \geq 0$\\
110 -x, & for $x < 0$
111 \end{numcases}
112 \end{verbatim}
113 %
114 Giving:
115 %
116 \begin{numcases} {|x|=}
117 x, & for $x \geq 0$\label{x}\\
118 -x, & for $x < 0$\label{-x}
119 \end{numcases}
120
121 \fancybreak
122 \noindent
123 Another example, employing sub-numbering, is calculating the square root
124 of a complex number $c+id$. First compute
125 \begin{subnumcases} {\label{weqn} w\equiv}
126 0 & for $c = d = 0$\label{wzero}\\
127 \sqrt{|c|}\,\sqrt{\frac{1 + \sqrt{1+(d/c)^2}}{2}} & for $|c| \geq |d|$ \\
128 \sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} & for $|c| < |d|$
129 \end{subnumcases}
130 Then, using $w$ from eq.~(\ref{weqn}), the square root is
131 \begin{subnumcases}{\label{sqrteqn} \sqrt{c+id}=}
132 0\,, \label{aaa} & $w=0$ (case \ref{wzero})\\
133 w+i\frac{d}{2w}\,, & $w \neq 0$, $c \geq 0$ \\
134 \frac{|d|}{2w} + iw\,, & $w \neq 0$, $c < 0$, $d \geq 0$ \\
135 \frac{|d|}{2w} - iw\,,\label{ddd} & $w \neq 0$, $c < 0$, $d < 0$
136 \end{subnumcases}
137 These equations, eq.~(\ref{weqn}) and (\ref{sqrteqn}), were produced by:
138 \begin{small}
139 \begin{verbatim}
140 Another example, employing sub-numbering, is calculating the square root
141 of a complex number $c+id$. First compute
142 \begin{subnumcases} {\label{weqn} w\equiv}
143 0 & for $c = d = 0$\label{wzero}\\
144 \sqrt{|c|}\,\sqrt{\frac{1 + \sqrt{1+(d/c)^2}}{2}} & for $|c| \geq |d|$ \\
145 \sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} & for $|c| < |d|$
146 \end{subnumcases}
147 Then, using $w$ from eq.~(\ref{weqn}), the square root is
148 \begin{subnumcases}{\label{sqrteqn} \sqrt{c+id}=}
149 0\,, & $w=0$ (case \ref{wzero})\\
150 w+i\frac{d}{2w}\,, & $w \neq 0$, $c \geq 0$ \\
151 \frac{|d|}{2w} + iw\,, & $w \neq 0$, $c < 0$, $d \geq 0$ \\
152 \frac{|d|}{2w} - iw\,, & $w \neq 0$, $c < 0$, $d < 0$
153 \end{subnumcases}
154 \end{verbatim}
155 \end{small}
156
157 \section*{Compatibilibility with amsmath}
158
159 When used in conjunction with amsmath.sty, the cases package will obey the the variant
160 commands \cmd{\tag}, \cmd{\notag}, and \cmd{\mathmargin}, however the formatting details
161 differ between \pkg{amsmath}'s \env{cases} environment and \env{numcases}.
162 For comparison, equation~(\ref{weqn}) formatted by \pkg{amsmath} and its \env{cases} environment
163 may be entered as
164 \begin{flushleft}\small
165 \begin{verbatim}
166 \begin{equation}
167 \label{wams} w \equiv
168 \begin{cases}
169 0 & \text{for}\ c = d = 0\\
170 \sqrt{|c|}\,\sqrt{\frac{1+\sqrt{1+(d/c)^2}}{2}} &\text{for}\ |c| \geq |d|\\
171 \sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} &\text{for}\ |c|<|d|
172 \end{cases}
173 \end{equation}
174 \end{verbatim}
175 \end{flushleft}
176 which produces
177 \begin{equation}
178 \label{wams} w\equiv
179 \begin{cases}
180 0 & \text{for }c = d = 0\\
181 \sqrt{|c|}\,\sqrt{\frac{1+\sqrt{1+(d/c)^2}}{2}} & \text{for}\ |c| \geq |d| \\
182 \sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} & \text{for}\ |c| < |d|
183 \end{cases}
184 \end{equation}
185 To get this more compact layout with \env{numcases} you can insert "\textstyle"
186 at the beginning of each case, as needed, or use the \pkg{cases}
187 package option \opt{amsstyle}.
188 To have the (unnumbered) \env{cases} environment give the more open layout of
189 eq.~(\ref{weqn}) you can put "\displaystyle" at the beginning of each case, or use
190 the option \opt{casesstyle} for the \pkg{cases} package. (Yes these go with the
191 \pkg{cases} package, they are not options for \pkg{amsmath}.)
192
193 Another slight difference is that the cases within \env{numcases} can be right-justified by
194 inserting \cmd{\hfill} at the beginning of each, which might be desired in rare situations,
195 like maybe the absolute value example numbered (\ref{x}) and (\ref{-x}) above.
196
197 For full disclosure, even without any relevant package options, cases.sty will
198 slightly adjust the \env{cases} environment from \pkg{amsmath}, by adding a little
199 space after the left brace.
200
201 \section*{Sub-numbering}
202 For control of the sub-equation-numbering style, see the
203 \AmS-\LaTeX\ documentation for \env{subequations}, currently
204 in section 3.11.3. If you are not using amsmath, that documentation
205 still mostly applies, except the name for regular equation numbers
206 is then `mainequation' instead of `parentequation'. Also, the
207 sub-numbering style can be controlled more easily by defining
208 \cmd{\thesubequation}. An example for capitalized letters is
209 \begin{verbatim}
210 \renewcommand\thesubequation{\themainequation.\Alph{equation}} % 13.C
211 \end{verbatim}
212 (noting that the counter to reference is `equation' not `subequation').
213
214 \end{document}