How to use cases in docstring math mode?

I am using Documenter.jl to generate the documentation, and would like to use \cases to define piecewise functions. Currently I am adding the equation to the docstring. Something like this doesn’t seem to render as latex in the generated html file:

```math
b = \\begin{cases}
1 & a>0,\\
0 & \\text{otherwise}
\\end{cases} ```

Any suggestion on how to implement this?

I think it’s failing because you’re not escaping the line break backslashes on line 3 (you want \\, so you’d need to write \\\\ to escape them properly in a docstring). I.e.:

```math
b = \\begin{cases}
1 & a>0, \\\\
0 & \\text{otherwise}
\\end{cases}
```

However, you should actually be able to avoid the escaping altogether by using the raw"" string macro:

@doc raw"""
```math
b = \begin{cases}
1 & a>0, \\
0 & \text{otherwise}
\end{cases}
```
"""
function foo end
3 Likes

Aha thanks a lot, this works