Math & ScienceReversed cases

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Reversed cases

Post by bkarpuz »

Hi all,

I need a new cases environment with the set parenthesis horizontally flipped and on the right-hand side. How is this possible?

Thanks.
bkarpuz
Last edited by bkarpuz on Mon May 16, 2011 10:59 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

TheNinjaWizard
Posts: 7
Joined: Sun May 15, 2011 11:33 pm

Re: Reversed cases

Post by TheNinjaWizard »

If I understand correctly, I think this may be what you are looking for:
http://www.latex-community.org/forum/vi ... =46&t=5269
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Reversed cases

Post by Stefan Kottwitz »

Hi bkarpuz,

you could use a pair \left. and \right\} around an array, similar to the original cases environment, such as

Code: Select all

\left.
\begin{array}{ll}
... & ... \\
... & ...
\end{array}
\right\}
or copy the original cases environment and modify it, if it should really look very similar, regarding alignment and spacing.

Stefan
LaTeX.org admin
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Reversed cases

Post by bkarpuz »

Thank you Stefan_K.
I could do it as you gave in the codes but I want to learn the way you mention below.
I dont know where I can copy the original cases environment.
Stefan_K wrote:Hi bkarpuz,
or copy the original cases environment and modify it, if it should really look very similar, regarding alignment and spacing.
Stefan
Thanks.
bkarpuz
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Reversed cases

Post by Stefan Kottwitz »

It may look a bit difficult, since the amsmath package is quite sophisticated. However, here's a short straightforward way:
  1. Look for the original code.
  2. Copy it in your own document preamble.
  3. Replay \def, \newcommand and alike by \renewcommand or \renewcommand* and its syntax. Though you could also stay with \def, it's just TeX, not LaTeX.
  4. If there's an @ in that code, use \makeatletter before and \makeatother after.
  5. Change the definition as desired.
So, let's get on it.

1. The original code is in amsmath.sty:

Code: Select all

\renewenvironment{cases}{%
  \matrix@check\cases\env@cases
}{%
  \endarray\right.%
}
\def\env@cases{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}l@{}}%
}
2.-4. We need to redefine both macros, since the first contains the left brace, the second contains the right one. The result of the steps in your preamble can be:

Code: Select all

\makeatletter
\renewenvironment{cases}{%
  \matrix@check\cases\env@cases
}{%
  \endarray\right\rbrace%
}
\def\env@cases{%
  \let\@ifnextchar\new@ifnextchar
  \left.
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}l@{}}%
}
\makeatother
Many lines of code, but it's following the simple steps, the final modification has been just changing \lbrace to . and . to \rbrace.

Stefan
LaTeX.org admin
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Reversed cases

Post by bkarpuz »

Hi again Stefan_K, I really appreciate what you have shown me.

Thanks.
bkarpuz
Stefan_K wrote:It may look a bit difficult, since the amsmath package is quite sophisticated. However, here's a short straightforward way:
  1. Look for the original code.
  2. Copy it in your own document preamble.
  3. Replay \def, \newcommand and alike by \renewcommand or \renewcommand* and its syntax. Though you could also stay with \def, it's just TeX, not LaTeX.
  4. If there's an @ in that code, use \makeatletter before and \makeatother after.
  5. Change the definition as desired.
...
Stefan
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Reversed cases

Post by bkarpuz »

How can I define a new environment rcases (reversed cases) to use both cases and rcases in my codes?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Reversed cases

Post by Stefan Kottwitz »

Define new macros instead of redefining existing. It's very similar:

Code: Select all

\makeatletter
\newenvironment{rcases}{%
  \matrix@check\cases\env@rcases
}{%
  \endarray\right\rbrace%
}
\def\env@rcases{%
  \let\@ifnextchar\new@ifnextchar
  \left.
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}l@{}}%
}
\makeatother
Stefan
LaTeX.org admin
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Reversed cases

Post by bkarpuz »

Stefan_K wrote:Define new macros instead of redefining existing. It's very similar:

Code: Select all

\makeatletter
\newenvironment{rcases}{%
  \matrix@check\cases\env@rcases
}{%
  \endarray\right\rbrace%
}
\def\env@rcases{%
  \let\@ifnextchar\new@ifnextchar
  \left.
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}l@{}}%
}
\makeatother
Stefan
Thanks a lot Stefan it seems that we only replace \renewenvironment with \newenvironment and some of the cases with rcases. But I got the following error while running your code.

Code: Select all

! Package amsmath Error: Old form `\cases' should be \begin{cases}.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.154     \begin{rcases}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Reversed cases

Post by Stefan Kottwitz »

I see! You also have to change cases to rcases for the call to \matrix@check, modify this line:

Code: Select all

\matrix@check\rcases\env@rcases
Now I remember the mathtools package provides an rcases environment for exactly this purpose. So, instead of our redefinition, loading mathtools is sufficient:

Code: Select all

\usepackage{mathtools}
Stefan
LaTeX.org admin
Post Reply