Openai api does not write the equation in latex format in mathjax format

Hello, openai api does not write the equation in latex format in mathjax format. Even though I entered a long prompt examples about this, the prompt skips the examples. My prompt example:

For latex expressions, use the $ symbol for LaTeX formatting. For example, if an expression is given as \(\frac{24}{18 - x}\),\[\frac{24}{18 - x}\], rewrite it as $\frac{24}{18 -x}$. Writing math formulas: You have a MathJax rendering environment.

- Any LaTeX text between single dollar sign ($) will be rendered as a TeX formula;
- Use $(tex_formula)$ in-line delimiters to display equations instead of backslash;
- The rendering environment only uses $ (single dollarsign) as a container delimiter. Example: $x^2 + 3x$ is output for "x² + 3x" to appear as TeX.`

Apart from this prompt, I added a sample answer draft on the prompt.

Note: Out of 5-6 examples, only 1 is mathjax as I want. Not all of them work, others are in latex format.

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("\\]", "$$");

The lesson is, as always, don’t fight the model.


Exactly. If you can easily conform to what the model wants to do naturally, then that’s far better than trying to instruct the model to behave differently.

1 Like