Alexander Soare
Alexander Soare

Reputation: 3267

How to write cases in Markdown equations

How can I write something like this in markdown?

enter image description here

Here are the specific things I don't know how to do:

Here's what I would do if I knew the right syntax:

$$
CE(p, y) = \curlytwo{-\log(p) \tab \text{if }y=1}{-\log(1-p) \tab \text{otherwise.}}
$$

where I've invented \curlytwo and \tab.

Upvotes: 5

Views: 8352

Answers (3)

bingtanghuluwa
bingtanghuluwa

Reputation: 21

I learned from here and used array.

$$
CE(p,y)=\left\{
\begin{array}{ll}
-\log(p) &\text{if }y=1 \\ 
-\log(1-p) &\text{otherwise}.
\end{array} 
\right.
$$

Upvotes: 0

Ritam Ganguly
Ritam Ganguly

Reputation: 1

\begin{equation}
(p, y) = 
\begin{cases}
    -\log(p) & \text{if }~~ y = 1 \\
    -\log(1-p) & \text{otherwise.}
\end{cases}
\end{equation}

Upvotes: 0

Andrew Li
Andrew Li

Reputation: 57982

You can use the cases environment to write cases which is supported in MathJax:

$$
\mathrm{CE}(p, y) = \begin{cases}
    -\log(p) & \text{if } y = 1 \\ % & is your "\tab"-like command (it's a tab alignment character)
    -\log(1-p) & \text{otherwise.}
\end{cases}
$$

Upvotes: 10

Related Questions