#show "√": it => {
set text(red)
it
}
$√123$
Since the function Roots Functions – Typst Documentation can not be targeted by a show rule, you have to write a custom square root function.
The example below wraps everything in red text and then overrides the text color of the body back to black. This also works with a body that is already colored since Typst always uses the first color that is applied.
#let rsqrt(body) = text(red, $sqrt(#text(black, $body$))$)
$rsqrt(a^2) + rsqrt(a^2 + b^2) + rsqrt(#text(blue, $c$) + d)$
1 Like
Note that if/when Support multiple fonts in math by mkorje · Pull Request #6365 · typst/typst · GitHub is merged, the show rule above will work :)
1 Like
If you want to color a full equation, setting text.fill
in a context
might be better.
#let rsqrt(body) = context text(red, math.sqrt(text(text.fill, body)))
#text(purple, $rsqrt(#text(blue, $c$) + d)$)
Full code
= Previous
#[
#let rsqrt(body) = text(red, $sqrt(#text(black, $body$))$)
#text(purple, $rsqrt(#text(blue, $c$) + d)$)
]
= New
#[
#let rsqrt(body) = context text(red, math.sqrt(text(text.fill, body)))
#text(purple, $rsqrt(#text(blue, $c$) + d)$)
]