Search code examples
markdownmathjax

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:

  • The big curly brace with two lines
  • If it's required after I know the above, the tab separation within the two lines

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.


Solution

  • 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}
    $$