RaTeX-CMP
0.1.12indexedCross-end UI math typesetting and LaTeX rendering with Compose components, reusable parsed DisplayList caching, synchronous parsing helper for inline layout, and prebuilt native runtimes.
Cross-end UI math typesetting and LaTeX rendering with Compose components, reusable parsed DisplayList caching, synchronous parsing helper for inline layout, and prebuilt native runtimes.
English | 简体中文
✨ RaTeX-CMP is a math formula rendering project for multi-platform UI scenarios, built with Kotlin Multiplatform and Compose Multiplatform. Its core rendering capability is powered by RaTeX.
It allows the same formula rendering engine to be reused across Android, iOS, JVM Desktop, JS, and Wasm, making it easier to integrate consistent mathematical typesetting and display into Compose Multiplatform applications.
This repository is maintained as an independent project. It can continue evolving as a library while also serving as a sample project and integration reference.
| Android | iOS | JVM Desktop |
|---|---|---|
If you are using Maven Central, make sure your project repositories include:
repositories {
mavenCentral()
}
If you want to validate locally first, you can also use:
repositories {
mavenLocal()
mavenCentral()
}
Use RaTeX-CMP 0.1.16 for the KMP library and any JVM Desktop native runtime dependencies.
implementation("io.github.darriousliu:ratex:0.1.16")
In a Kotlin Multiplatform project, you would typically add it to commonMain:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.darriousliu:ratex:0.1.16")
}
}
}
If you want to run on JVM Desktop, you also need to add the native runtime dependency for the current platform:
kotlin {
sourceSets {
jvmMain.dependencies {
implementation("io.github.darriousliu:ratex:0.1.16")
runtimeOnly("io.github.darriousliu:ratex-native-darwin-aarch64:0.1.16")
}
}
}
Available Desktop native coordinates:
io.github.darriousliu:ratex-native-darwin-aarch64io.github.darriousliu:ratex-native-darwin-x86-64io.github.darriousliu:ratex-native-linux-aarch64io.github.darriousliu:ratex-native-linux-x86-64io.github.darriousliu:ratex-native-windows-x86-64In this repository, Desktop native libraries are published as separate submodules; the sample app automatically selects the matching runtime dependency for the current host platform.
The simplest usage is to pass a LaTeX string directly:
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp
import io.ratex.compose.RaTeX
@Composable
fun FormulaSample(modifier: Modifier = Modifier) {
RaTeX(
latex = """\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}""",
modifier = modifier,
fontSize = 28.sp,
displayMode = true,
color = Color(),
)
}
If you want inline math, set displayMode = false:
RaTeX(
latex = """e^{i\pi}+1=0""",
fontSize = 20.sp,
displayMode = false,
)
If you want the formula color to follow the current Material text color, you can omit color and the composable will use LocalContentColor.current.
If you want to parse first and reuse the resulting DisplayList in multiple places, you can use rememberRaTeXDisplayList:
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.unit.sp
import io.ratex.compose.RaTeX
import io.ratex.compose.rememberRaTeXDisplayList
@Composable
fun ParsedFormulaSample(latex: String) {
parseResult rememberRaTeXDisplayList(
latex = latex,
displayMode = ,
color = MaterialTheme.colorScheme.primary,
)
RaTeX(
displayList = parseResult?.getOrNull(),
fontSize = sp,
)
}
Text with inlineContentTo mix an inline formula into Text, parse it synchronously with rememberBlockingRaTeXDisplayList, then create InlineTextContent from the measured result:
Note: JS/Wasm browser targets must explicitly call RaTeXEngine.initialize() from a coroutine
before any parsing. After initialization, rememberRaTeXDisplayList / RaTeX(latex = ...) load
fonts and parse asynchronously. Before using rememberBlockingRaTeXDisplayList, also preload fonts
asynchronously with RaTeXFontLoader.ensureLoaded(); the synchronous helper is therefore intended
mainly for Android, iOS, and JVM Desktop.
library: core library moduledesktop-native/*: publishing modules for JVM Desktop native librariesgit clone https://github.com/darriousliu/RaTeX-CMP.git
cd RaTeX-CMP
git submodule update --init --recursive
If you have already cloned the repository but have not initialized submodules, you can simply run the last command.
Recommended tools:
Depending on the platform, you may also need:
cargo-ndk and Python 3 (for ELF alignment verification)nightly-2026-08-16 with rust-src (installed by the preparation script)cargo-zigbuild and zigBefore running or building for a platform for the first time, it is recommended to install the required Rust targets for that platform.
Android:
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
iOS:
rustup toolchain install nightly-2026-08-16 --profile minimal --component rust-src
rustup target add --toolchain nightly-2026-08-16 aarch64-apple-ios aarch64-apple-ios-sim
JVM Desktop:
rustup target add manuallyIf this is your first time running the project, or if you changed the underlying Rust code, you will usually need to prepare the corresponding local artifacts first.
Android:
bash prepare-android-rust.sh
iOS:
bash prepare-ios-rust.sh
Following upstream RaTeX 0.1.15, the script rebuilds the iOS standard library with
-Z build-std=std,panic_abort and checks that unwind metadata does not reference
_rust_eh_personality before copying each archive. Set RATEX_IOS_RUST_TOOLCHAIN
to test another nightly. The Android preparation script verifies 16 KB alignment
of ELF LOAD/GNU_RELRO segments for arm64-v8a and x86_64.
JVM Desktop:
bash prepare-jvm-rust.sh
macOS KMP (macosArm64):
bash prepare-jvm-rust.sh darwin-aarch64
This prepares the library/native/darwin-aarch64/libratex_ffi.a static library
required by Kotlin/Native cinterop and framework linking, along with the .dylib used by Desktop.
Prepare all Desktop Rust artifacts supported by the current machine:
bash prepare-jvm-rust.sh --all
If you are only working on the Kotlin / Compose layer and usable artifacts already exist in the repository, run these commands only when needed instead of every time.
JVM Desktop sample:
./gradlew :example:run
On Windows:
.\gradlew.bat :example:run
Android debug package:
./gradlew :androidApp:assembleDebug
On Windows:
.\gradlew.bat :androidApp:assembleDebug
For iOS development, it is recommended to open iosApp/iosApp.xcodeproj on macOS for debugging.
Web sample:
./gradlew :example:jsBrowserDevelopmentRun
./gradlew :example:wasmJsBrowserDevelopmentRun
After upgrading the core, run the shared regressions and verify the Android artifact:
./gradlew :library:jvmTest :library:iosSimulatorArm64Test :library:macosArm64Test
./gradlew :library:jsBrowserTest :library:wasmJsBrowserTest
# Requires a connected Android device or emulator
./gradlew :library:connectedAndroidDeviceTest
./gradlew :library:bundleAndroidMainAar
python3 external/RaTeX/scripts/verify_android_elf.py library/build/outputs/aar/library.aar
The 0.1.15 regressions cover \slashed, \centernot, inherited geometry colors,
and recovery after macro, layout, and \char limit errors. ELF checks do not
replace ZIP alignment verification of the final application APK.
The 0.1.16 regressions cover text labels, label macro expansion, whitespace after
\tag*, multi-digit automatic numbers, and label depth limits. Labels now use
text mode; wrap math in $...$, for example replacing \tag{x^2} with
\tag{$x^2$}. The 0.1.16 Showcase group includes text labels, mixed math labels,
and multi-row numbering examples.
build-logicexternal/RaTeX only when you need to coordinate with the lower-level engineInitialize submodules:
git submodule update --init --recursive
Run the Desktop sample:
./gradlew :example:run
Build the Android sample:
./gradlew :androidApp:assembleDebug
Run the Web sample:
./gradlew :example:jsBrowserDevelopmentRun
./gradlew :example:wasmJsBrowserDevelopmentRun
Prepare Android Rust artifacts:
bash prepare-android-rust.sh
Prepare iOS Rust artifacts:
bash prepare-ios-rust.sh
Prepare Desktop Rust artifacts:
bash prepare-jvm-rust.sh
Prepare all Desktop Rust artifacts supported by the current machine:
bash prepare-jvm-rust.sh --all
Publish the library to Maven Central:
Make sure your publishing credentials and signing configuration are ready before publishing.
On macOS, prepare the macosArm64 Rust artifacts before publishing the :library KMP main library:
bash prepare-jvm-rust.sh darwin-aarch64
Publish all artifacts supported by the current machine to Maven Local:
./gradlew publishToMavenLocal
This publishes:
:libraryThis is also the recommended local verification path. If it succeeds, both the main library and the Desktop native libraries supported by the current machine will be published to your local Maven repository.
For example:
arm64 macOS, it also publishes ratex-native-darwin-aarch64, , , and Publish all artifacts supported by the current machine to Maven Central:
./gradlew publishAndReleaseToMavenCentral
Publish only the KMP main library:
./gradlew :library:publishKotlinMultiplatformPublicationToMavenCentralRepository
This publishes KMP targets including macosArm64; the macOS target uses the static Rust library prepared above.
Publish all JVM Desktop native libraries supported by the current machine:
./gradlew publishSupportedDesktopNativePublicationsToMavenCentralRepository
Publish all JVM Desktop native libraries supported by the current machine to Maven Local:
./gradlew publishSupportedDesktopNativePublicationsToMavenLocal
This task automatically:
prepare-jvm-rust.sh <target> inside each submoduleThese Desktop native submodules share the same precompiled script plugin from build-logic; each module only declares its target platform, file name, artifactId, and supported host OS set.
For example:
arm64 macOS, it publishes darwin-aarch64, darwin-x86-64, , and Thanks to the RaTeX project for providing the core capabilities and open-source foundation.
Thanks also to Kotlin Multiplatform, Compose Multiplatform, Rust, and the related open-source communities for making this cross-platform project possible and helping it continue to evolve in a more unified way across platforms.
| Platform | Architectures / Targets | Notes |
|---|
| Android | arm64-v8a, armeabi-v7a, x86_64, x86 | x86 is currently untested |
| iOS | iPhone / Simulator | Integrated via Kotlin Multiplatform Framework |
| JVM Desktop | Windows x86_64, macOS x86_64 / arm64, Linux x86_64 / arm64 | Desktop native libraries are built and published based on what the current machine supports |
| Web | js(IR), wasmJs | Both targets share webMain and load WASM through the ratex-wasm npm package |

![]() |
![]() |
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.sp
import io.ratex.compose.RaTeX
import io.ratex.compose.rememberBlockingRaTeXDisplayList
import io.ratex.measure
fun InlineFormulaText() {
val formula = """E = mc^2"""
val formulaId = "energy"
val formulaFontSize = 18.sp
val density = LocalDensity.current
val parseResult = rememberBlockingRaTeXDisplayList(
latex = formula,
displayMode = false,
)
val displayList = parseResult.getOrNull()
val fontSizePx = with(density) { formulaFontSize.toPx() }
val measured = remember(displayList, fontSizePx) {
displayList?.measure(fontSizePx)
}
val placeholderWidth = with(density) {
(measured?.widthPx ?: fontSizePx).toSp()
}
val placeholderHeight = with(density) {
(measured?.totalHeightPx ?: fontSizePx).toSp()
}
val inlineContent = mapOf(
formulaId to InlineTextContent(
placeholder = Placeholder(
width = placeholderWidth,
height = placeholderHeight,
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter,
),
) {
RaTeX(
displayList = displayList,
fontSize = formulaFontSize,
)
},
)
Text(
text = buildAnnotatedString {
append("The mass–energy equation ")
appendInlineContent(formulaId, formula)
append(" describes the relationship between mass and energy.")
},
inlineContent = inlineContent,
)
}
example: shared sample module, including the Desktop, JS/Wasm entry points and the new RaTeXShowcasePageandroidApp: Android sample appiosApp: iOS sample projectbuild-logic: shared Gradle convention plugins for Desktop native publishingexternal/RaTeX: upstream RaTeX submodulebash prepare-jvm-rust.sh --all, the script automatically selects all targets supported by the current machine and runs rustup target add as neededarm64 macOS, it builds darwin-aarch64, darwin-x86-64, linux-aarch64, and linux-x86-64, but does not attempt windows-x86-64ratex-native-darwin-x86-64ratex-native-linux-aarch64ratex-native-linux-x86-64Linux, it also publishes ratex-native-linux-aarch64 and ratex-native-linux-x86-64Windows, it also publishes ratex-native-windows-x86-64linux-aarch64linux-x86-64Linux, it publishes linux-aarch64 and linux-x86-64Windows, it publishes windows-x86-64Surfaced from shared tags and platforms — no rankings paid for.