Skip to content

Duplicate characters are rendered when \left and \right are used #66

@RenGate

Description

@RenGate

I'm observing characters duplication when \left and \right operators are used. Maybe there are other operators that cause this issue too. In the following sample, an equation is rendered with two CRω at the top and CLω² at the bottom.

Image

Here is a sample code that demonstrates this issue:

let latex = #"""
    \phi = \arctan\left(\frac{-C R \omega}{1 - C L \omega^2}\right)
"""#

#Preview {
    VStack {
        SwiftUILaTeXView(
            latexString: latex,
            textColor: .blue
        )
        Spacer()
    }
}

struct SwiftUILaTeXView: UIViewRepresentable {
    let latexString: String
    let textColor: UIColor
    let textAlignment: MTTextAlignment = .center
    
    func makeUIView(context: Context) -> MTMathUILabel {
        let view = MTMathUILabel()
        return view
    }
    
    func updateUIView(_ uiView: MTMathUILabel, context: Context) {
        if latexString != uiView.latex {
            uiView.latex = latexString
        }
        if textColor != uiView.textColor {
            uiView.textColor = textColor
        }
        if textAlignment != uiView.textAlignment {
            uiView.textAlignment = textAlignment
        }
    }
    
    func sizeThatFits(_ proposal: ProposedViewSize, uiView: MTMathUILabel, context: Context) -> CGSize? {
        if let width = proposal.width, width.isFinite, width > 0 {
            uiView.preferredMaxLayoutWidth = width
            let size = uiView.sizeThatFits(CGSize(width: width, height: .greatestFiniteMagnitude))
            return size
        }
        return nil
    }
}

When mentioned operators are not used, equation is rendered correctly:
\phi = \arctan(\frac{-C R \omega}{1 - C L \omega^2})

Image

Library version: latest commit from main branch (48ff188).
iOS version: 26.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions