isMathBody function

bool isMathBody(
  1. String tex
)

Whether tex — the inside of \(…\) or \[…\] — is a formula.

Not when it is empty, or nothing but punctuation and spaces: \(\) and \[\\\] are escaped brackets in prose, and a "formula" of only symbols is almost always that.

Implementation

bool isMathBody(String tex) {
  for (var i = 0; i < tex.length; i++) {
    final c = tex.codeUnitAt(i);
    if (c != _space && c != _tab && c != 0x0A && !isAsciiPunctuation(c)) {
      return true;
    }
  }
  return false;
}