Forcing LaTex format via gpt4o-mini

Hi folks,

We use a prompt to regulate the format of output to ensure we get LaTex formatted text for things like math equations. The reason we use a wrapper is because we also want the human readable version counter part.

For example, 1/4x+1 would be generated as:

  • <<| \frac{1}{4}x + 1 |>><<>>

The problem is from time to time, the output format would be messed up.

For example, instead of using <<| |>>, it would use something like “\( )\”. Has anyone solved issues like this before?

1 Like

To keep things simple:

  • Strengthen the prompt: Be crystal clear. Say “Always use <<| |>> for LaTeX and avoid ( ) or .”
  • Post-process: If mistakes still happen, write a small function to replace ( ) with your format.
  • Consistency: Lower the model’s temperature to make the output more predictable.

This should fix the formatting issue.

Thanks Mitchel, will give this a try!