feat(ios): integrate RaTeX for LaTeX math rendering, replacing iosMath#357
Open
hryhoriiK97 wants to merge 9 commits into
Open
feat(ios): integrate RaTeX for LaTeX math rendering, replacing iosMath#357hryhoriiK97 wants to merge 9 commits into
hryhoriiK97 wants to merge 9 commits into
Conversation
eszlamczyk
approved these changes
May 28, 2026
Comment on lines
+22
to
+26
| if enable_math | ||
| s.source_files = "ios/**/*.{h,m,mm,cpp,swift}", "cpp/md4c/*.{c,h}", "cpp/parser/*.{hpp,cpp}" | ||
| else | ||
| s.source_files = "ios/**/*.{h,m,mm,cpp}", "cpp/md4c/*.{c,h}", "cpp/parser/*.{hpp,cpp}" | ||
| end |
Collaborator
There was a problem hiding this comment.
Nit: Im wondering if we shouldn't futureproof it. For example what if we add another dependency that needs swift bridge, then this code would scilently ignore this dependency when math is disabled.
Maybe something like this would be better?
Suggested change
| if enable_math | |
| s.source_files = "ios/**/*.{h,m,mm,cpp,swift}", "cpp/md4c/*.{c,h}", "cpp/parser/*.{hpp,cpp}" | |
| else | |
| s.source_files = "ios/**/*.{h,m,mm,cpp}", "cpp/md4c/*.{c,h}", "cpp/parser/*.{hpp,cpp}" | |
| end | |
| s.source_files = "ios/**/*.{h,m,mm,cpp,swift}", "cpp/md4c/*.{c,h}", "cpp/parser/*.{hpp,cpp}" | |
| if enable_math | |
| s.exclude_files = "ios/math/ENRMRaTeXBridge.swift" | |
| end |
…oapods-spm cocoapods-spm adds SWIFT_INCLUDE_PATHS on the ReactNativeEnrichedMarkdown target pointing to the build directory, which contains include/module.modulemap defining RaTeXFFI. With use_frameworks! :linkage => :dynamic, RaTeXFFI is also embedded in its XCFramework, so the compiler finds it twice and raises "redefinition of module 'RaTeXFFI'". A before-compile script phase removes the duplicate entry from the shared module map, leaving the XCFramework copy as the authoritative definition. Also adds cocoapods-spm to the example app Gemfile for local bundle exec users. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… when math is disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why?
Replace iosMath with RaTeX for iOS LaTeX math rendering, aligning iOS with the Android migration (PR #355).
iosMath only supports a limited subset of LaTeX and is no longer actively maintained. RaTeX is a modern, Rust-based, KaTeX-compatible engine that renders math natively via CoreGraphics — no WebView, no JavaScript. This gives iOS feature parity with web (KaTeX) and Android (RaTeX).
Changes
New file:
ios/math/ENRMRaTeXBridge.swift— Swift-to-ObjC bridge exposingENRMRaTeXBridge.parse()andENRMRaTeXRenderResult(width, ascent, descent, draw) to existing Objective-C code.Podspec (
ReactNativeEnrichedMarkdown.podspec):iosMathdependency.spm_dependencyfor RaTeX v0.1.9+ (requirescocoapods-spmplugin).use_frameworks!.Migrated ObjC files:
ENRMMathContainerView.m— ReplacedMTMathUILabelwith a customENRMRaTeXCanvasViewthat draws viaENRMRaTeXRenderResult. Added alignment support (center/left/right) and correct overflow scrolling.ENRMMathInlineAttachment.m— ReplacedMTMathUILabelwithENRMRaTeXBridge.parse(). Usesceil()for dimension rounding to prevent sub-pixel clipping.ENRMMathInlineAttachment+macOS.m— Same migration for macOS. Added CTM flip since RaTeX expects top-left origin (UIKit-style) butNSImage.lockFocususes bottom-left origin.ENRMMathInlineAttachmentShared.h— ReplacedMTMathListDisplayivar withENRMRaTeXRenderResult.ENRMFeatureFlags.h— Auto-detection now checks for RaTeX headers instead of iosMath.Example app & docs:
Podfile— SetsUSE_FRAMEWORKS=dynamicwhen math is enabled (required for SPM interop).LATEX_MATH.md— Updated references from iosMath to RaTeX, documenteduse_frameworks!requirement.Consumer impact
ENRICHED_MARKDOWN_ENABLE_MATH=0): No change — no RaTeX dependency, no dynamic frameworks required.Testing
Screenshots
Screen.Recording.2026-05-27.at.15.28.33.mov
PR Checklist