ceToTex function
Converts the argument of \ce to TeX.
H2O → \mathrm{H}_{2}\mathrm{O}, SO4^2- → \mathrm{SO}_{4}^{2-},
A ->[\Delta] B → an extensible arrow with the condition above it.
Anything unrecognised is kept as it is, so partial input (while it is
still being typed) converts to what has arrived so far.
Implementation
String ceToTex(String input) {
final words = _words(_chunks(input));
final out = <String>[];
for (final w in words) {
out.add(_word(w));
}
return out.where((s) => s.isNotEmpty).join(' ');
}