Here I present a WebSite containing just Default.aspx.
Current snippet code has to do with coloring text in an input field of a web page. The input field is an editable DIV HTML element.
While the user writes, there is a partial post (an XMLHttpRequest) to the server. Then the code behind decides which parts of the input should be colored and which color should it be, and returns back to the client the input already formatted with color(s).
The code behind must be as fast as possible to interfere as less as possible the user input. After the formatted text is copyied to the input box (an editable DIV element) the caret position is restored and normally the user should not experience any anoying change, but when adding a line break: the caret goes to the start position.
If you to find a better solution, please let me know.
Perhaps you may want to change the Regex pattern to your needs to color words instead of math expressions: just do all the changes you want, it's up to you.