Native Desktop Rendering (PyQt5)
Omni-MDX provides a unique solution for rendering rich text and interactive layouts in native desktop applications without the overhead of a heavy WebEngine (Chromium) component. By mapping the Rust-generated AST directly to native PyQt5 widgets, you get a lightweight, high-performance UI that feels native to the OS.
The Rendering Engine
The desktop rendering is managed by the OmniMDX class located in omni_mdx.engine. It acts as a coordinator between the Rust parser and the Qt widget factory.
Basic Implementation
To render MDX in a Qt window, you simply pass the parsed nodes to the render_qt method:
Native Math Rendering
One of the most powerful aspects of the Qt renderer is its handling of mathematical equations. Instead of relying on CSS/JS (KaTeX), the Python engine uses Matplotlib as a backend to convert LaTeX strings into high-quality images (QPixmap).
- Inline Math: Rendered as small, baseline-aligned images inside text flows.
- Block Math: Rendered as centered, high-resolution images between paragraphs.
This ensures that complex formulas like $$E_k = \frac{1}{2}mv^2$$ look perfect regardless of the user’s screen resolution or installed fonts.
Custom Component Mapping
Just like in React, you can map MDX JSX tags to custom Python/Qt logic. This allows you to insert complex interactive widgets (like custom buttons, data tables, or media players) directly into your text flow.
Architecture Overview
The rendering pipeline follows a strict path to ensure stability:
parser.py: Calls the Rust binary to get the raw AST.ast.py: Converts the result into typed PythonAstNodeobjects.math_render.py: Handles the LaTeX-to-QPixmap conversion using Matplotlib.qt_renderer.py: Iterates through the AST and instantiates the correspondingQLabel,QVBoxLayout, or custom widgets.