How can I capture math mode with regex?

With version 0.12 the regex treatment has improved, but I still can’t capture the content with math mode.

I leave a simple example of what I want to capture.

#show regex("=+/?(.+)"): it => {
    it.fields()
  }

=? $display(x^2 -4x +4 = 0)$

You can see that the mathematical function is not captured.

image

Not a perfect solution, but you can move =? inside the math call and use show math.equation instead

#show math.equation: it => {
  [#if it.body.children.at(0).has("text") and it.body.children.at(0).text == "?=" {
    text(red, it)
  } else {
    text(blue, it)
  }]
}
$x^2 -4x +4 = 0$ \
$"?=" x^2 -4x +4 = 0$

Solution

If you’re trying to filter out certain equations, maybe try labeling it:

$ x^2 - 4 x  + 4 = 0 $ <marked-eq>

Then select it by using:

#show <marked-eq>: set text(fill: red)

Possible issue

However, currently one element can have at most one label, which would cause problems when you try to use this method together with other show rules that handle labels.