What is the best way to handle rendering of mathematical/scientific expressions returned in a GPT4o API response? I’ve iterated lots and not found any reliable solution that isn’t really bug-prone. Currently I preprocess responses to detect LaTeX using regex, preserve it for KaTeX rendering, and convert the rest to HTML using the markdown
library. On frontend, I use KaTeX for Latex rendering while Markdown and HTML styling are applied for proper display.