removeStrayBraces static method

String removeStrayBraces(
  1. String tex
)

Implementation

static String removeStrayBraces(String tex) {
  var numLefts = tex.count('{') - tex.count(r'\{') + tex.count(r'\\{');
  var numRights = tex.count('}') - tex.count(r'\}') + tex.count(r'\\}');

  while (numRights > numLefts) {
    tex = '{' + tex;
    numLefts++;
  }
  while (numLefts > numRights) {
    tex = tex + '}';
    numRights++;
  }

  return tex;
}