# Writing this function on moodle using TeX Notation [duplicate]

I want to write an equation with one curly brace ({) on the right hand side and, next to the curly, two statements in two different lines. How can i do it using TeX or Latex? Thanks.

## marked as duplicate by Stefan Pinnow, CarLaTeX, Zarko, Werner, user13907 Jan 16 '17 at 19:35

I don't know about Noodle but, using the amsmath package you can simply use

$f(x) = \begin{cases} (x+2)^{2}\,, & x<-2 \\ 4-x^{2}\,, & x\ge -2 \end{cases}$

• Why using \,? – Sigur Jan 16 '17 at 17:45
• That adds a small amount of space before the comm to give some separation from the expressions. – Herb Schulz Jan 16 '17 at 18:22

I'll add a few other possibilities, defined by mathtools, an extension of amsmath which it loads, by empheq (which loads mathtools) or by the cases package. Some of them can be individually numbered:

    \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{empheq}
\usepackage{cases} %

\begin{document}

\begin{align*}
\shortintertext{With \texttt{cases} and \texttt{dcases}:}
& f(x) = \begin{cases}
(2x +1)^2& \text{if } x < - \frac{1}{2}\\
1-4x^2 & \text{if } x \ge -\frac{1}{2}
\end{cases}
&  & f(x) = \begin{dcases}
(2x +1)^2& \text{if } x < - \frac{1}{2}\\
1-4x^2 & \text{if } x \ge -\frac{1}{2}
\end{dcases}
\end{align*}

\begin{align*}
\shortintertext{With \texttt{rcases} and \texttt{drcases}:}
& f(x) = \begin{rcases}
(2x +1)^2& \text{if } x < - \frac{1}{2}\\
1-4x^2 & \text{if } x \ge -\frac{1}{2}
\end{rcases}
&  & f(x) = \begin{drcases}
(2x +1)^2& \text{if } x < - \frac{1}{2}\\
1-4x^2 & \text{if } x \ge -\frac{1}{2}
\end{drcases}
\end{align*}

With \texttt{numcases}:
\begin{subnumcases}{f(x) = }
(2x +1)^2& if $x < - \frac{1}{2}$\\
1-4x^2 & if $x \ge -\frac{1}{2}$
\end{subnumcases}

With \texttt{empheq};
\begin{subequations}
\begin{empheq}[left = {f(x) = \empheqlbrace}]{alignat = 2}
& (2x +1)^2 & \quad & \text{if } x < - \frac{1}{2}\\[1ex]
& 1-4x^2 & & \text{if } x \ge -\frac{1}{2}
\end{empheq}
\end{subequations}

\end{document}