public static string Escape(char s) { return(TexFormulaParser.IsParserReserved(s) ? "\\" + s : new string(s, 1)); }
///Returning: 0-Not found, 1-Symbol, 2-Command, 3-Font, 4-Misc static int FindPossibleEscape(string text, int pos, out int start, out int end) { start = 0; end = 0; pos--; if (text.Length <= 0 || pos < 0 || pos >= text.Length) { return(0); } if (TexFormulaParser.IsParserReserved(text[pos])) { if (pos == 0 || text[pos - 1] != '\\') { if (pos == 0 || text[pos] != '\\') { return(0); } else if (pos < text.Length - 1) { pos++; } else { start = pos - 1; end = pos; return(4); } } else { start = pos - 1; end = pos; return(4); } } end = pos; while (true) { if (char.IsLetter(text[pos])) { pos--; if (pos >= 0) { continue; } else { return(0); } } if (text[pos] == '\\') { if (pos == 0 || text[pos - 1] != '\\') { start = pos; break; } } return(0); } while (end < text.Length && char.IsLetter(text[end])) { end++; } end--; var s = text.Substring(start + 1, end - start); if (TEXPreference.main.GetFontIndexByID(s) >= 0) { return(3); } if (TexFormulaParser.isCommandRegistered(s)) { return(2); } if (TEXPreference.main.GetChar(s) != null) { return(1); } return(4); }