How to creat a selector that only choose text without math equation inline?

#show text: it => {
// keep this  format
  show "11":"22"
  it
}

11 $11$

I want show rules won’t be used to 11 in math.equation.

More specifically, how to make this code work

#let en2ch_point_dict = (
  "\\.\\s*": "。",
  "\\,\\s*": ",",
)

#let auto_chinese_point_text(it) = {
  for (pat, replacement) in en2ch_point_dict {
    it = {
      show regex(pat): replacement
      it
    }
  }
  it
}

#let auto_chinese_point(doc) = {
  show par: it => {
    show text: it => {
      show: auto_chinese_point_text
      it
    }
    it
  }

  show list: it => {
    if it.has("label") and it.label == <processed> {
      return [1] //it
    }
    show text: it => {
      show: auto_chinese_point_text
      it
    }
    it
  }
  show enum: it => {
    if it.has("label") and it.label == <processed> {
      return it
    }
    show text: it => {
      show: auto_chinese_point_text
      it
    }
    it
  }
  doc
}
#show: auto_chinese_point
$3.4$
3.4

$3.4$ should show 3.4(don’t use show rule), 3.4 should show 3。4(use show rule).

1 Like

I know it doesn’t help you, but maybe someone smarter than me can take inspirations from this:

You can do the opposite of what this question is about, only changing text within math.equation, like so:

#show math.equation: it => {
  show "11": "22"
  it
}

11 $11$

You can mark equations using state, and use that to branch in the show rule… however, you cannot replace the text with itself (for some reason it will then replace it it again with the non-math replacement text), so we have to add a label to to mark non-replaced text:

#let is-equation = state("is-equation", false)
#show math.equation: it => {
  is-equation.update(true)
  it
  is-equation.update(false)
}
#show text: it => {
  if it.has("label") and it.label == <processed> {
    it
  } else {
    show regex("\\.\\s*"): itt => context {
      if is-equation.get() [#itt<processed>] else { "。" }
    }
    show regex("\\,\\s*"): itt => context {
      if is-equation.get() [#itt<processed>] else { "," }
    }
    it
  }
}

3.4 $3.4$

a,b $a,b$

image

(Note: I don’t think that you need the special show rules for list and enum, show: text should be enough)