Sorry to tl;dr your code, but how exactly is it based on TeX? Do you actually run Knuth's TeX code to make this work, or did you reimplement it?
Also, kind of irrelevant, do you think we'll ever get something better than (La)TeX syntax? I've been frustrated by obscure error messages from LaTeX in big documents because it's a macro language, so the interpreter doesn't actually see what you're typing. How does KaTeX handle errors?