Skip to content

LaTeX views not rendered in images and PDFs #71

@tobitech

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)
			}
		}
	}
}

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