How to add colored underline in the math mode?

In that case, you might define some custom underline functions, e.g.

#let myuline(fill: black, it) = {
  set text(fill: fill)
  math.underline(it)
}

Then you can have

$ myuline(fill: #blue, A + B) = myuline(fill: #red, C + D) $

Result

2 Likes