Skip to content

Commit 2f2405f

Browse files
committed
Preload fixes.
1 parent c4bbc21 commit 2f2405f

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Sources/LaTeXSwiftUI/LaTeX.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,35 @@ extension LaTeX {
133133

134134
/// Preloads the view's components.
135135
///
136+
/// - Note: You must set this method's parameters the same as its environment
137+
/// or call it is ineffective and adds additional computational overhead.
138+
///
136139
/// - Returns: A LaTeX view whose components have been preloaded.
137-
@MainActor public func preload() -> LaTeX {
138-
switch blockMode {
139-
case .alwaysInline:
140-
blocksAsText(blocks, forceInline: true)
141-
case .blockText:
142-
blocksAsText(blocks)
143-
case .blockViews:
144-
blocksAsStack(blocks)
140+
@MainActor public func preload(
141+
unencodeHTML: Bool = false,
142+
parsingMode: ParsingMode = .onlyEquations,
143+
imageRenderingMode: Image.TemplateRenderingMode = .template,
144+
font: Font = .body,
145+
displayScale: CGFloat = 1.0,
146+
texOptions: TeXInputProcessorOptions = TeXInputProcessorOptions(loadPackages: TeXInputProcessorOptions.Packages.all)
147+
) -> LaTeX {
148+
// Render the blocks
149+
let preloadedBlocks = Renderer.shared.render(
150+
blocks: Parser.parse(unencodeHTML ? latex.htmlUnescape() : latex, mode: parsingMode),
151+
font: font,
152+
displayScale: displayScale,
153+
texOptions: texOptions)
154+
155+
// Render the images
156+
for block in preloadedBlocks {
157+
for component in block.components where component.type.isEquation {
158+
guard let svg = component.svg else { continue }
159+
_ = Renderer.shared.convertToImage(
160+
svg: svg,
161+
font: font,
162+
displayScale: displayScale,
163+
renderingMode: imageRenderingMode)
164+
}
145165
}
146166
return self
147167
}

0 commit comments

Comments
 (0)