parseColor function
Parses a colour written as a name, #rgb, #rrggbb, #rrggbbaa, bare
rrggbb hex (KaTeX accepts this) or an xcolor expression: a mix
(red!30 is 30 % red and 70 % white, red!30!blue 30 % red and 70 %
blue, and so on along the chain) or a complement (-red). defined
gives the colours a formula defined (\definecolor), which win over
the built-in names. Returns null if text is not a colour.
Implementation
LatexColor? parseColor(
String text, {
LatexColor? Function(String name)? defined,
}) {
final t = text.trim();
if (t.contains('!') || t.startsWith('-')) {
return _colorExpression(t, defined);
}
return _plainColor(t, defined);
}