]> gitweb.michael.orlitzky.com - mjotex.git/blob - mjo-proof_by_cases.tex
Use the calc package to ignore \baselinestretch around case labels.
[mjotex.git] / mjo-proof_by_cases.tex
1 %
2 % A proof-by-cases environment. This gives you a nicely-indented list
3 % of cases for use in proofs.
4 %
5 % Example:
6 %
7 % Case 1 (x >= 0): herp.
8 %
9 % Case 2 (x < 0): derp.
10 %
11
12 % Used below to define pcases.
13 \usepackage{enumitem}
14
15 % Needed to perform division in the definition of \singleblskip.
16 \usepackage{calc}
17
18 % A \baselineskip without the \baselinestretch scaling factor. Even
19 % though \baselinestretch defaults to 1.0, it doesn't really have that
20 % value. Thus to avoid division by zero, we need to do the ``is this
21 % thing empty?'' hack.
22 %
23 % If we use \baselineskip instead of \singleblskip in our list, things
24 % get real ugly when the text is e.g. double-spaced.
25 %
26 \newlength{\singleblskip}
27 \setlength{\singleblskip}{
28 \baselineskip / \real{
29 \if\relax\detokenize{\baselinestretch}\relax
30 \baselinestretch%
31 \else
32 1%
33 \fi}
34 }
35
36 % Using the enumitem package, we define a new type of list, called
37 % ``pcases'' (proof by cases). Each case has a label with an arabic
38 % numeral (the case number), but also a \thiscase identifier. The
39 % macro \thiscase is defined below by the \case command, and gives the
40 % name or conditions or whatever that distinguish one case from
41 % another.
42 \newlist{pcases}{enumerate}{1}
43 \setlist[pcases]{
44 label=\textbf{Case~\arabic*}:~\protect\thiscase\textbf{.},
45 ref=\arabic*,
46 align=left,
47 leftmargin=0pt,
48 listparindent=\parindent,
49 parsep=\parskip,
50 itemsep=\singleblskip}
51
52 % The optional argument here gets stuffed into the \thiscase macro, to
53 % be called by pcases when it creates this list item. The \hfill is a
54 % hack intended to force the proof to start on a new line, rather than
55 % right after the colon. A \newline where the \hfill is does not work,
56 % so we consume the rest of the line instead.
57 \newcommand{\case}[1][]{
58 \def\thiscase{#1}%
59 \item \hfill\par\vspace{\singleblskip}
60 }