Skip to content

[Bug]: Inline LaTeX shows an opaque white fallback in SwiftUI List #171

Description

@xshengcn

Summary

Inline LaTeX can render with an opaque white rectangle (or a generic document-like placeholder) behind the formula when the Markdown document is hosted in a SwiftUI List. The same content renders correctly in a ScrollView. The issue is intermittent and can disappear after leaving the screen and opening it again.

Minimal markdown input

- \(a, b, c\): coefficients in \(ax^2 + bx + c = 0\).
- If \(b^2 - 4ac > 0\), the equation has two distinct real roots.
- \(\sqrt{b^2 - 4ac}\) is the square root of the discriminant.

Platform

iOS

Expected behavior

Inline formulas should render with their configured text color and a transparent background in both containers. The rendering should remain stable when List rows are reused, when scrolling, and after navigation.

Actual behavior

In Light mode on iOS, the inline math attachment sometimes displays an opaque white rectangle behind the formula. With a custom attachment UTI, the same artifact becomes a generic white file/document icon, which suggests that TextKit is drawing the NSTextAttachment fallback image when the LaTeX view provider is not attached or is being reused. Setting MTMathUILabel.isOpaque = false, clearing its background, or setting its alpha to 0 did not remove the white region, so the label itself does not appear to be the source.

This is most reproducible for inline math inside a SwiftUI List; the equivalent content in a ScrollView does not show the artifact. Navigating away and back can make it disappear temporarily. Block/display math was not affected in this reproduction.

Validation

Environment:

Reproduction:

  1. Render the minimal Markdown in a List using the package's normal iOS renderer.
  2. Use Light appearance.
  3. Scroll through the list and/or navigate away and back.
  4. Compare with the same Markdown rendered in a ScrollView.

The issue was reproduced with both static and streaming document rendering. As a local experiment, changing the inline attachment to a custom NSTextAttachment that returns a transparent fallback image removed the artifact in the List, including after scrolling and re-entering the screen. The Demo built and ran successfully against the cloned local package.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions