colinc86 / LaTeXSwiftUI

A SwiftUI view that renders LaTeX.
MIT License
201 stars 35 forks source link

Displaying Math Equations from ChatGPT Responses #40

Open tobitech opened 3 months ago

tobitech commented 3 months ago

Hello, I got a response from ChatGPT and tried to display it with LaTexSwiftUI but it didn't work:

Here is the response:

To solve the equation \(3x + 5 = 4\), follow these steps:
what format is this string of text:
1. Subtract 5 from both sides of the equation to isolate the term with \(x\):
   \[
   3x + 5 - 5 = 4 - 5
   \]
   Simplifying this, we get:
   \[
   3x = -1
   \]
2. Divide both sides by 3 to solve for \(x\):
   \[
   x = \frac{-1}{3}
   \]
So, the solution to the equation \(3x + 5 = 4\) is:
\[
x = -\frac{1}{3}
\]

When I tried it I get an error: Undefined control sequence \( I don't know what I need to do to be able to display this type of response.

RedPug commented 3 months ago

if you're pasting it all into a string, you should double up the "\" character. The backslash is an escape character and acts in a nasty way if you use it incorrectly.

so instead of "(3x + 5 = 4)" you would do "\(3x + 5 = 4\)"