delimiterText function

String? delimiterText(
  1. String text
)

The Unicode delimiter for text (a command or a character), or null if it is not a delimiter. . means "no delimiter".

Implementation

String? delimiterText(String text) {
  const chars = {
    '(', ')', '[', ']', '<', '>', '/', '|', '.', //
    '⟨', '⟩', '⌊', '⌋', '⌈', '⌉', '‖', '∣', '∥', '⟦', '⟧', '⟮', '⟯', '⎰',
    '⎱', '⦃', '⦄', '⌜', '⌝', '⌞', '⌟', '↑', '↓', '↕', '⇑', '⇓', '⇕', '⎪', '{',
    '}',
  };
  if (chars.contains(text)) {
    return switch (text) {
      '<' => '⟨',
      '>' => '⟩',
      '|' => '∣',
      _ => text,
    };
  }
  const commands = {
    r'\backslash': r'\',
    // fontmath.ltx's extensible pieces, usable as delimiters.
    r'\arrowvert': '∣',
    r'\Arrowvert': '∥',
    r'\bracevert': '⎪',
    r'\vert': '∣',
    r'\Vert': '∥',
    r'\|': '∥',
    r'\uparrow': '↑',
    r'\downarrow': '↓',
    r'\updownarrow': '↕',
    r'\Uparrow': '⇑',
    r'\Downarrow': '⇓',
    r'\Updownarrow': '⇕',
    r'\lt': '⟨',
    r'\gt': '⟩',
  };
  final command = commands[text];
  if (command != null) return command;
  final info = mathSymbols[text];
  if (info != null &&
      (info.atom == AtomType.open || info.atom == AtomType.close)) {
    return info.text;
  }
  return null;
}