Skip to content

LaTeX views not rendered in images and PDFs #71

Open

Description

@tobitech

Hello, I use LaTex in my views to display math equations but the equations are not being rendered when I want to generate an image or PDF from my SwiftUI view.

I was able to get this working in the past but for some strange reason, it's no longer working.

I'm wondering if there is a particular setup or modifier I'm missing.

Image Image

Here is a snippet of the the code looks like:

private func generateSolutionImage(
	mathResponse: MathSolution,
	originalImage: UIImage?
) async throws -> URL {
	return try await withCheckedThrowingContinuation { continuation in
		Task { @MainActor in
			do {
				// Create the content view for sharing (no ScrollView)
				let contentView = SolutionContentView(
					mathResponse: mathResponse,
					originalImage: originalImage,
					showShareButton: false,
					forSharing: true
				)
				let renderer = ImageRenderer(content: contentView)
				renderer.scale = 3.0
				// Use unspecified size to let SwiftUI determine the natural size
				renderer.proposedSize = ProposedViewSize.unspecified
				guard let image = renderer.uiImage else {
					throw ShareError.imageGenerationFailed
				}
				let url = try saveImageToTempFile(image: image)
				continuation.resume(returning: url)
			} catch {
				continuation.resume(throwing: error)
			}
		}
	}
}

Activity

  1. ShawnBaek commented on Jan 11, 2026

    @ShawnBaek

    @tobitech Could you share error information?

  2. colinc86 commented on Apr 3, 2026

    @colinc86
    Owner

    The latex image rendering has changed significantly and I don't believe will play nicely with an image renderer with the background rendering this view does.

    I've added the ability to render the UIImage/NSImage objects themselves to the v2 update. This may solve your problem if you display these instead of the latex view as a subview.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions