SwiftMath icon indicating copy to clipboard operation
SwiftMath copied to clipboard

\\textcolor{...}{...} Causes Crash

Open swiftly-viper opened this issue 7 months ago • 0 comments

Hello,

Upon experimenting with \color, I encountered the same issue as @OskarPersson in issue #15. The solution, \textcolor{...}{...} (#16), has consistently caused my test SwiftUI project to crash. I have examined the source code with that of Oskar's merge request and have not been able to locate the issue. There is no example on SwiftMathDemo for me to compare to.

I find the behaviour odd since it seems like I am the first to experience it, and it does not seem like the code of the original merge request solving issue 15 has changed.

Below is the code from my XCode to reproduce the crash.

I have tried change labelMode to .text and removing uiView.textColor. Neither solved the issue.

struct MathView: UIViewRepresentable {
    
    var equation: String
    var fontSize: CGFloat
    var color: UIColor
    
    func makeUIView(context: Context) -> MTMathUILabel {
        let view = MTMathUILabel()
        
        return view
    }
    
    func updateUIView(_ uiView: MTMathUILabel, context: Context) {
        let latexEquation = "\\textcolor{red}{\(equation)}"
        
        uiView.latex = latexEquation
        uiView.labelMode = .display
        uiView.textAlignment = .left
        uiView.contentInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
        uiView.font = MTFontManager().latinModernFont(withSize: fontSize)
        uiView.textColor = color
    }
}

swiftly-viper avatar Jul 26 '24 01:07 swiftly-viper