modifySpecialStrings static method

String modifySpecialStrings(
  1. String tex
)

Implementation

static String modifySpecialStrings(String tex) {
  var shouldAddFiller = (tex == r'\over' ||
      tex == r'\overline' ||
      tex == r'\sqrt' ||
      tex == r'\sqrt{' ||
      tex.endsWith('_') ||
      tex.endsWith('^') ||
      tex.endsWith('dot'));

  if (shouldAddFiller) {
    tex += r'{\quad}';
  }

  if (tex == r'\substack') {
    tex = r'\quad';
  }

  if (tex.isEmpty) {
    tex = r'\quad';
  }

  if (tex.startsWith(r'\\')) {
    tex = tex.replaceAll(r'\\', r'\quad\\');
  }

  var numLefts = [
    for (var s in withoutFirst(tex.split(r'\left')))
      if (s.isNotEmpty && r'(){}[]|.\'.contains(s[0])) s
  ].length;

  var numRights = [
    for (var s in withoutFirst(tex.split(r'\right')))
      if (s.isNotEmpty && r'(){}[]|.\'.contains(s[0])) s
  ].length;

  if (numLefts != numRights) {
    tex = tex.replaceAll(r'\left', r'\big');
    tex = tex.replaceAll(r'\right', r'\big');
  }

  tex = removeStrayBraces(tex);

  return tex;
}