Add support for Latex style blocks and inlines for Math

AI-generated summary

The discussion revolves around adding support for LaTeX-style math formatting in Discourse, particularly to convert AI-generated LaTeX into MathJax for better display. ozkn highlights the issue of AI responses often returning raw LaTeX, which is not always rendered properly, and shares a suggested solution from the OpenAI community involving a simple string replacement function to convert LaTeX delimiters to MathJax format. sam supports the idea and encourages a pull request (PR), noting the annoyance of the current behavior and the fact that GPT-4o is fine-tuned on LaTeX. Jagster offers a prompt-based workaround for users who don’t need complex formulas, instructing AI to use $...$ for inline and $$...$$ for display math. ozkn reiterates the need for a built-in solution, as prompts are unreliable. sam invites contributions, and ozkn expresses interest in helping. Finally, sam announces that native support has been added in the latest release, linking to the official announcement.

artificial intelligence gives answers in latex format. I wrote a prompt to convert this latex format to mathjax format, but the prompt is not always implemented and responds in latex format. When I wrote my problem to the openai community, the following suggestion came.

"I decided it wasn’t even worth the effort of cluttering up a system prompt, when I could just do the following on my end with the results:

    translateLaTex = (val: string): string => {
        if (val.indexOf("\\") == -1) return val;

        return val.replaceAll("\\(", "$")//
            .replaceAll("\\)", "$")//
            .replaceAll("\\[", "$")//
            .replaceAll("\\]", "$");
    }

"
Can you apply this solution in the next update?

I like this idea, agree latex can be annoying in AI replies and system prompting out if it is hard. Double so cause GPT4o is fine tuned on latex. Totally support making some sort of PR with a switch to support “latex mode” if you check a box in site settings.

I don’t know if I’m talking about same thing, but for me this worked. I don’t use any really difficult formulas, though.

You fully understand MathJax and generate it.

When presenting mathematical expressions, use the following rules:
1. For inline mathematical expressions, use single dollar signs `$...$`.
2. For display-style mathematical expressions, use double dollar signs `$$...$$`.

For example:
- Inline: The equation of mass-energy equivalence is $e=mc^2$.
- Display: 
$$
e=mc^2
$$

Can you add this feature in the next update. No matter how much I type prompt, it doesn’t always work properly. In the Openai forum, they suggest an arrangement like the one above, not prompt, as a definitive solution.

Yeah this is very annoying, PR is welcome if you want to give it a shot.

I would like to try it, I would be happy if you open a PR @sam

This is now natively supported in latest!