Hello!
Would anyone know how to make this in Typst?
Specifically how to have to blocks
Kind regards
Hello!
Would anyone know how to make this in Typst?
Specifically how to have to blocks
Kind regards
Certainly, you would use the cases
function in math mode, which takes comma-separated cases. Note the &
for aligning, and the quoted "/"
and ","
since they have special meanings. Another option is escaping them like \/
and \,
or using their names slash
and comma
.
delta(r_i - r_j) = cases(
0 "," &quad r_i - r_j >= epsilon "/" 2,
1 "/" epsilon "," &quad r_i - r_j < epsilon "/" 2
)
Amazing!
How to correctly specify the gap between each line and can I get the “,” at the end in some smart way?
Kind regards
You can do the following for the spacing as described in the documentation (Cases Function – Typst Documentation)
#set math.cases(gap: 1em)
There doesn’t seem to be a simple way to achieve that effect with the comma. You could probably manually place it all with a grid, but alignment would be tricky.
Yeah, ended up doing this:
#set math.cases(gap: 1em)
$
delta(r_i - r_j) = cases(
0 "," &quad r_i - r_j >= epsilon "/" 2,
1 "/" epsilon "," &quad r_i - r_j < epsilon "/" 2
) #h(4pt) ,
$ <eq:sph2>
But weird that I cannot set gap
inside the function call, have to set it globally? Seems counterintuitive
The “,” was done through h-space
Kind regards
Manually placing just the comma does seem to be a good solution, I hadn’t thought of that. With more cases it will probably require a grid.
To make this easier you could define a custom function like so.
#set math.cases(gap: 1em)
#let commas(num) = pad(
left: 0.2em,
bottom: 1em,
grid(columns: 1, row-gutter: 1.5em, ..(",",) * num)
)
$
delta(r_i - r_j) = cases(
0 "," &quad r_i - r_j > epsilon slash 2,
1 "," &quad r_i - r_j = epsilon slash 2,
1 "/" epsilon "," &quad r_i - r_j < epsilon slash 2
) #commas(2)
$
Still kind of a workaround, but a less painful one.
You can set it in the function call by adding gap: #1em
as a named argument to cases. Function calls in math are a hybrid between math markup and code: They support named arguments, but for them to be interpreted as code rather than math, you still need to enter code mode with the hash.