delimiterText function
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,
};
}
// Typed double angle brackets, and fullwidth and CJK brackets: the math
// delimiter they stand for.
const wide = {
'⟪': '⟪', '⟫': '⟫', '(': '(', ')': ')', '[': '[', ']': ']', //
'{': '{', '}': '}', '|': '∣', '<': '⟨', '>': '⟩', '〈': '⟨', '〉': '⟩',
'《': '⟪', '》': '⟫', '「': '⌜', '」': '⌟', '〚': '⟦', '〛': '⟧', '〔': '⦗',
'〕': '⦘', '【': '〖', '】': '〗', '〖': '〖', '〗': '〗', '⦅': '⦅', '⦆': '⦆',
};
final folded = wide[text];
if (folded != null) return folded;
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;
}