From 56867e03deb02e5854f08759a23760fc342fcb99 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 25 Feb 2020 22:02:08 +0000 Subject: cases (25feb20) git-svn-id: svn://tug.org/texlive/trunk@53909 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/cases/cases.sty | 249 ++++++++++++++++++---------- 1 file changed, 163 insertions(+), 86 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/cases/cases.sty b/Master/texmf-dist/tex/latex/cases/cases.sty index b82f010a02a..66609ee492c 100644 --- a/Master/texmf-dist/tex/latex/cases/cases.sty +++ b/Master/texmf-dist/tex/latex/cases/cases.sty @@ -1,11 +1,12 @@ -% C A S E S . S T Y ver 2.5 May 2002 +% C A S E S . S T Y ver 3.0 Feb 2020 % -% Copyright (C) 1993,1994,1995,2000,2002 by Donald Arseneau +% Copyright (C) 1993,1994,1995,2000,2002,2020 by Donald Arseneau % asnd@triumf.ca % These macros may be freely transmitted, reproduced, or modified % provided that this notice is left intact. Sub-equation numbering % is based on subeqn.sty by Stephen Gildea; most of the rest is based -% on LaTeX's \eqnarray by Leslie Lamport and the LaTeX3 team. +% on LaTeX's \eqnarray by Leslie Lamport and the LaTeX3 team, +% and parts of amsmath.sty by the American Mathematical Society. % % This provides a LaTeX environment {numcases} to produce multi-case % equations with a separate equation number for each case. There is @@ -27,96 +28,111 @@ % case. In a subnumcases environment, a \label in the left_side of the % equation gives the overall equation number, without any letter. % -% To use this package, -% include "\usepackage{cases}" after \documentclass. You may also -% specify "\usepackage[subnum]{cases}" to force *all* numcases -% environments to be treated as subnumcases. -% -% Question: Is there a {numcases*} environment for unnumbered cases? -% Answer: There is a {cases} environment in AMS-LaTeX, but it is just as -% convenient to stick with the canonical LaTeX array: -% \[ left side = \left\{ \begin{array}...\end{array} \right. \] -% -% Speaking of AMS-math, they use an entirely different system of equation -% numbering, and this package uses ordinary LaTeX numbering. -% -% - - - - - -% A simple example is: -% \begin{numcases}{|x|=} -% x, & for $x \geq 0$\\ -% -x, & for $x < 0$ -% \end{numcases} -% -% Giving: -% / x for x > 0 (1) -% |x| = < - -% \ -x for x < 0 (2) -% -% - - - - - -% -% Another example is calculating the square root of $c+id$. First compute -% \begin{subnumcases}{\label{w} w\equiv} -% 0 & $c = d = 0$\label{wzero}\\ -% \sqrt{|c|}\,\sqrt{\frac{1 + \sqrt{1+(d/c)^2}}{2}} & $|c| \geq |d|$ \\ -% \sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} & $|c| < |d|$ -% \end{subnumcases} -% Then, using $w$ from eq.~(\ref{w}), the square root is -% \begin{subnumcases}{\sqrt{c+id}=} -% 0 & $w=0$ (case \ref{wzero})\\ -% w+i\frac{d}{2w} & $w \neq 0$, $c \geq 0$ \\ -% \frac{|d|}{2w} + iw & $w \neq 0$, $c < 0$, $d \geq 0$ \\ -% \frac{|d|}{2w} - iw & $w \neq 0$, $c < 0$, $d < 0$ -% \end{subnumcases} -% -% - - - begin definitions - - - +% For detailed description and package options, see cases.pdf (cases.tex). -\ProvidesPackage{cases}[2002/05/02 ver 2.5 ] +\ProvidesPackage{cases}[2020/02/22 ver 3.0] + +\newdimen\numc@numwid + +% copy \@@eqncr but change error message and handle \tag{} for amsmath: +\def\@@numc@cr{\let\reserved@a\relax + \ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}% + \or \def\reserved@a{&}\else + \let\reserved@a\@empty + \@latex@error{Too many columns in numcases environment}\@ehc\fi + \reserved@a \if@eqnsw\@eqnnum\stepcounter{equation}\else \iftag@ \df@tag\fi\fi + \global\@eqnswtrue\global\@eqcnt\z@\cr} + +\let\iftag@=\iffalse \newenvironment{numcases}[1]% -{$$\numc@opts \setbox\z@\hbox - {\advance\c@equation\@ne\def\@currentlabel{\p@equation\theequation}% local - $\displaystyle {#1\null}\m@th$}% - \numc@setsub +{$$\numc@opts + \refstepcounter{equation}% Needed for LHS \label + \setbox\z@\hbox {% typeset LHS + \def\@currentlabel{\p@equation\theequation}% local def + $\displaystyle {#1{}}\m@th$}% + \numc@setsub % maybe \subequations (handling \refstepcounter) + \def\@currentlabel{\p@equation\theequation}% + \global\@eqnswtrue\m@th + \def\tag##1{\def\@currentlabel{##1}\tag@in@align{##1}}% + \settowidth{\numc@numwid}{\ \advance\c@equation\tw@\numc@eqnnum}% + \@tempskipb\@centering + \ifx\numc@left\mathindent % fleqn: + \@tempskipa=\@ne\mathindent\@minus\@ne\mathindent + \ifx\numc@forcenumwid\z@ % leqno + \ifdim \numc@numwid>\mathindent % enlarge left space for equation number + \@tempskipa=\numc@numwid\@minus\numc@numwid + \fi\fi + \else % not fleqn: + \@tempskipa=\@centering + \advance\@tempskipa \numc@numwid\@minus\numc@numwid + \advance\@tempskipa \numc@numwid\@minus\numc@forcenumwid + \advance\@tempskipb \tw@\numc@numwid\@minus\tw@\numc@numwid + \advance\@tempskipb -\numc@forcenumwid\@minus-\numc@forcenumwid + \fi \setbox\tw@\vbox\bgroup - \stepcounter{equation}\def\@currentlabel{\p@equation\theequation}% - \global\@eqnswtrue\m@th \everycr{}\tabskip\numc@left\let\\\@eqncr - \halign to\dimen@ii \bgroup \kern\wd\z@ \kern14\p@ % assume width of brace - \tabskip\z@skip \global\@eqcnt\@ne $\displaystyle{##}$\hfil - &\global\@eqcnt\tw@ \skip@10\p@ \advance\skip@\tw@\arraycolsep \hskip\skip@ - ##\unskip\hfil\tabskip\@centering% \unskip removes space if no explanations - &\global\@eqcnt\thr@@\hbox to\z@\bgroup\hss##\egroup\tabskip\z@skip\cr -}{\@@eqncr \egroup % end \halign, which does not contain first column or brace - \global\advance\c@equation\m@ne -%Measure the natural width of the alignment - \unskip\unpenalty\unskip\unpenalty \setbox\z@\lastbox % grab last line - \nointerlineskip \copy\z@ % then put it back - \global\dimen@i\wd\z@ - \setbox\z@\hbox{\hskip-\numc@left\unhbox\z@}% Measure its natural width - \ifdim \wd\z@<\dimen@i \global\dimen@i\wd\z@ \fi -\egroup% end \vbox (box\tw@, box\z@ is restored to LHS) -\hbox to\dimen@ii{\m@th % assemble the whole equation - \hskip\numc@left - \hbox to\dimen@i{$\displaystyle \box\z@ % parameter #1 + \everycr{}\let\\\@eqncr \let\@@eqncr\@@numc@cr + \tabskip\@tempskipa + \halign to\dimen@ii \bgroup % white space for LHS followed by RHS + \kern\wd\z@ \kern10\p@ % assume width of brace + \global\let\iftag@=\iffalse % for amsmath (make sure this is not in if block) + \global\@eqcnt\@ne $\numc@dispstyle{##}$\hfil + \tabskip\z@skip &% explanation + \global\@eqcnt\tw@ + \numc@expstyle\quad ##\unskip\numc@expstyle\hfil % \unskip removes quad if no explanation + \tabskip\@tempskipb &% equation number + \global\@eqcnt\thr@@\hbox to\numc@forcenumwid\bgroup\hss##\egroup + \tabskip\z@skip\cr +}{% + \@@numc@cr \egroup % end \halign, which does not contain first column or brace + \global\advance\c@equation\m@ne + % Measure the natural width of the alignment + \unskip\unpenalty\unskip\unpenalty \setbox\z@\lastbox % grab last line + \nointerlineskip \copy\z@ % then put it back + \global\dimen@i\wd\z@ + \setbox\z@\hbox{\unhbox\z@}% Measure its natural width in \dimen@i + \global\dimen@i\wd\z@ + \egroup% end \vbox (\tw@) box\z@ is restored to LHS; \dimen@i is retained + \advance\dimen@i-\@tempskipa \advance\dimen@i-\wd\z@ \advance\dimen@i-10\p@ + \advance\dimen@i-\@tempskipb + % now \@dimen@i is natural width of RHS + explanation + eqno columns + \hbox to\wd\tw@{\m@th % assemble the whole equation stretched to display width + \hskip\@tempskipa + \box\z@ % LHS - parameter #1 + \hbox to10\p@{\hss$\displaystyle \dimen@\ht\tw@ \advance\dimen@\dp\tw@ % get size of brace - \left\{\vcenter to\dimen@{\vfil}\right.\n@space % make brace - $\hfil}\hskip\@centering % finished first part (filled whole line) - \kern-\dimen@ii % backspace the full width - $\vcenter{\box\tw@}$% overlay the alignment - }% end the \hbox to\dimen@ii + \ifdim\dimen@<1.5em\dimen@=1.5em\fi % don't allow really small brace + \left\lbrace\vcenter to\dimen@{\vfil}\,\right.\n@space % make brace + $\hss}% end 10pt brace box + \kern\dimen@i + \hskip\@tempskipb + }% finished first part (filled whole line) end the \hbox to\wd\tw@ + \kern-\wd\tw@ % backspace the full width + \vcenter{\box\tw@}% overlay the alignment \numc@resetsub $$\global\@ignoretrue} +% a wrapper around \subequations so it works in cases with hyperref and amsmath +\def\numc@subequations{% skip the \refstepcounter inside \subequations + \let\numc@opts\refstepcounter + \def\refstepcounter##1{\let\refstepcounter\numc@opts}% + \subequations + \refstepcounter{equation}} + \let\numc@setsub\relax \let\numc@resetsub\relax -\def\subnumcases{\let\numc@setsub\subequations - \let\numc@resetsub\endsubequations \numcases} +\def\subnumcases{% + \let\numc@setsub\numc@subequations + \let\numc@resetsub\endsubequations + \numcases} \let\endsubnumcases\endnumcases % declare subequations -- either defining them following the style of -% Gildea's subeqn.sty, or using the syntax of AMS-LaTeX if that is loaded. +% Gildea's subeqn.sty, or using the version from AMS-LaTeX if that is loaded. -\@ifundefined{c@parentequation}{% No AMS, define subequations from scratch: +\@ifundefined{c@parentequation}{% No AMS +\def\numc@eqnnum{\@eqnnum} % % These versions of subequations follow the style of Gildea's subeqn.sty, % but are thoroughly rewritten. @@ -163,21 +179,82 @@ $$\global\@ignoretrue} \def\@lab@subeqnarray#1#2{\begingroup \let\@currentlabel\themainequation #1{#2}\endgroup} % -}{}% AMS \subequations already defined +}{% AMS + +% \subequations already defined; +% use tag format +\def\numc@eqnnum{\tagform@{\theequation}} +% add little space after brace to amsmath's cases + +\def\@tempa{% + \let\@ifnextchar\new@ifnextchar + \left\lbrace + \def\arraystretch{1.2}% + \array{@{}l@{\quad}l@{}}% +} +\ifx \env@cases\@tempa % add a bit of space after brace in amsmath cases env +\def\env@cases{% + \let\@ifnextchar\new@ifnextchar + \left\lbrace\hskip 2\p@ + \def\arraystretch{1.2}% + \array{@{}l@{\quad}l@{}}% +} +\fi +}% end amsmath branch \def\numc@left{\@centering} \def\numc@opts{\dimen@ii\displaywidth} +\def\numc@forcenumwid{\numc@numwid} -\DeclareOption{subnum}{ - \let\numc@setsub\subequations - \let\numc@resetsub\endsubequations } +\DeclareOption{subnum}{% + \let\numc@setsub\numc@subequations + \let\numc@resetsub\endsubequations +} \DeclareOption{fleqn}{ - \def\numc@left{\mathindent} - \def\numc@opts{\displaywidth\linewidth - \dimen@ii\linewidth } + \let\numc@left\mathindent + \def\numc@opts{\displaywidth\linewidth + \dimen@ii\linewidth } +} + +\DeclareOption{leqno}{ + \let\numc@forcenumwid\z@ } -\ProcessOptions + +\let\numc@expstyle\@empty +\let\numc@dispstyle\displaystyle +\DeclareOption{amsstyle}{ + \def\numc@expstyle{$}% used in pairs for math-mode ($) explanation + \let\numc@dispstyle\textstyle +} + +\DeclareOption{casesstyle}{ + \newcommand\@unnc@casecr[1][\z@skip]{% + \cr \noalign{\vskip #1}% + } + \renewenvironment{cases}{% + \let\@ifnextchar\new@ifnextchar + \left\lbrace\hskip 2\p@ + \vcenter to1.3em{}% + \vcenter\bgroup + \let\\\@unnc@casecr + \openup\jot + \tabskip\z@skip + \halign \bgroup + $\numc@dispstyle{##}\m@th$\hfil + &\numc@expstyle\quad ##\unskip\numc@expstyle\hfil % \unskip removes space if no explanations + \cr + }{% + \crcr + \egroup + \egroup + \right.\n@space + } +} + +\DeclareOption{cases}{\ExecuteOptions{casesstyle}} + +\ProcessOptions \endinput -- cgit v1.2.3