LaTeXBoard is a custom iOS keyboard extension designed to make communicating with math and science easier. It instantly parses, previews, and renders LaTeX code directly within your keyboard, allowing you to copy the result as a PNG and send it in any chat application.
🚀 Currently available exclusively for iOS. An Android version is in the roadmap for future releases.
- Paste LaTeX: Paste LaTeX from the current input context and preview it instantly inside the keyboard.
- Image Export: Once your formula is ready, tap "Send" to render the preview into a high-quality
UIImageand automatically copy it to your general pasteboard (UIPasteboard). - Universal Chat Support: Works across WhatsApp, Telegram, Discord, iMessage, and any other app that supports image pasting.
- 100% Offline & On-Device: All parsing and rendering are done locally on your device. No network requests are made.
LaTeXBoardPreview.mp4
Our custom parsing engine supports a wide array of mathematical notations:
- Fractions & Roots:
\frac,\dfrac,\sqrt, nth roots, etc. - Subscripts & Superscripts:
^,_, and combined usage. - Big Operators:
\sum,\int,\prod,\bigcup(with limits). - Matrices & Environments:
matrix,pmatrix,bmatrix,array. - Brackets & Sizing:
\left,\right,\middle,\Big, etc. - Quantum Mechanics:
\bra,\ket,\braket. - Styling:
\textbf{},\mathit{},\color,\colorbox. - Extensive Symbol Map: Greek letters, arrows, relations, and operators.
Building an iOS Custom Keyboard Extension (UIInputViewController) requires operating under extremely strict system memory limits (the Jetsam limit is typically ~30-50 MB). LaTeXBoard is built from the ground up for stability and speed, featuring a completely native pipeline:
- Host App: SwiftUI-based onboarding, guide, and redirection to Settings.
- Keyboard Extension: A UIInputViewController-based interface, responsible for the entire parsing, rendering, and clipboard workflow.
- Plain TeX Normalization: Before tokenization, the parser converts Plain TeX variants (e.g.,
\over→\frac,\atop→\atopfrac) into standard LaTeX commands for consistency. - Tokenization: A single-pass tokenizer converts input into structured
LaTeXTokenenums. - Native Core Graphics Draw: We don't use web views or JavaScript engines. LaTeXBoard draws formulas directly to the screen using Core Graphics (
drawFraction,drawIntegral,drawMatrix,drawXarrow, etc.), ensuring zero input lag and memory efficiency.
iOS memory warnings or a "Jetsam" crash occur if memory usage spikes too high. We mitigate this through:
- NSCache-Based Caching: Tokens and fonts are cached (
tokenCache,fontCache) with strict count limits (maxCachedTokenCount). This prevents re-parsing the same LaTeX frequently. - Aggressive Memory Reuse: Cache is cleared immediately upon memory warnings or if
didReceiveMemoryWarningis called. NSCache automatically evicts before the system kills the process. - Strict View Recycling: UI components within the keyboard extension are recycled.
- Autorelease Pools: Memory-intensive sections of the rendering code are wrapped in
autoreleasepoolblocks to release temporary allocations immediately. - PNG Export Caps: Exported images are capped at a max size (600x400 at 2x scale) for guaranteed stability during final render.
Full Access is required to write rendered PNG output to UIPasteboard.
Why does it need "Full Access"? iOS requires "Full Access" (RequestsOpenAccess = true) for keyboard extensions to read or write to the general clipboard (UIPasteboard). LaTeXBoard uses this permission only to copy the final rendered PNG image to your pasteboard so you can paste it into your chat input.
Technical Note: This is defined in the Info.plist by setting RequestsOpenAccess to true for the NSExtensionPrincipalClass (KeyboardViewController).
- Download on the App Store
- Follow the onboarding guide to enable the keyboard in Settings > General > Keyboard > Keyboards.
- Clone the repository:
git clone https://github.com/acemoglu/LaTeXBoard.git
- Open the project in Xcode (
LaTeXBoard.xcodeproj). - Select the
LaTeXBoardscheme and build for your target device (iOS 16.0deployment target,Swift 5.0). - On your device, follow the same Settings steps to enable LaTeXBoard.
- Be sure to toggle Allow Full Access for clipboard functionality.
- Open any messaging application.
- Switch to LaTeXBoard using the globe icon.
- Tap Paste & Preview to capture text around the cursor and render supported LaTeX.
- Review the natively rendered math on the keyboard preview.
- Tap Send (PNG). The keyboard will render the equation as an image and copy it to your clipboard.
- Paste the image into the chat input and send!
- Not a full TeX distribution: LaTeXBoard uses a custom, lightweight native parser/renderer optimized for iOS keyboard extensions. Some advanced package-dependent macros (e.g., TikZ or complex custom macro stacks) may not be fully supported.
- Performance-first rendering scope: Feature support is intentionally bounded to keep latency low and memory usage stable under keyboard extension limits.
- PNG export size cap: Exported images are capped to a safe maximum size to reduce memory spikes and avoid extension crashes on lower-memory devices.
This project is licensed under the MIT License.
