Math Equations
Markdown-OS supports mathematical equations using KaTeX, a fast math typesetting library. You can write equations in LaTeX syntax with both inline and display modes.Inline Math
Inline equations are wrapped in single dollar signs:$...$
Example:
Inline math flows with surrounding text and uses KaTeX’s
displayMode: false rendering.Display Math
Display equations are wrapped in double dollar signs:$$...$$
Example:
KaTeX Integration
Equations are rendered using KaTeX with custom Marked.js extensions:Inline Math Extension
Display Math Extension
Both extensions store the original LaTeX source in
data-math-source attributes, which is used for editing and re-rendering.Rendering Process
Math equations are rendered during document decoration:1
Parse Markdown
Marked.js detects
$...$ and $$...$$ patterns using custom extensions2
Generate HTML
Extensions create
.math-inline or .math-display elements with source stored in data attributes3
Render with KaTeX
renderMathEquations() finds math elements and calls katex.render() on each4
Add Controls
Display equations get edit and copy buttons for interaction
Render Implementation
Interactive Features
Copy LaTeX
Display equations have a copy button that copies the raw LaTeX source:The copy button temporarily shows a checkmark after successful copy, then reverts to the copy icon after 1.5 seconds.
Edit Equations
Click the edit button to modify an equation:Edit Modal
Edit Modal
The editor opens a modal with:
- Title: “Edit display equation” or “Edit inline equation”
- Textarea with current LaTeX source
- Save and Cancel buttons
- Keyboard shortcuts (Enter saves, Escape cancels)
Saving Changes
Saving Changes
After editing:
- New source is stored in
data-math-sourceattribute - Element text content is updated
renderMathEquations()is called to re-render- Change event is emitted for auto-save
Error Handling
Invalid LaTeX syntax is handled gracefully:Inline Math Errors
KaTeX Configuration
KaTeX is configured for safety and compatibility:Configuration Options
throwOnError: false- Renders error messages instead of throwing exceptionsdisplayMode- Controls centered block layout vs inline flowoutput: "htmlAndMathml"- Generates accessible MathML alongside HTML
Supported LaTeX Commands
KaTeX supports most standard LaTeX math commands:Common Commands
- Greek letters:
\alpha,\beta,\gamma,\Delta,\Omega - Operators:
\sum,\int,\prod,\lim,\frac - Relations:
\leq,\geq,\neq,\approx,\equiv - Arrows:
\rightarrow,\Rightarrow,\leftrightarrow - Sets:
\in,\notin,\subset,\cup,\cap - Logic:
\land,\lor,\neg,\forall,\exists
Advanced Features
- Matrices:
\begin{matrix}...\end{matrix} - Cases:
\begin{cases}...\end{cases} - Aligned equations:
\begin{aligned}...\end{aligned} - Colors:
\textcolor{red}{text},\colorbox{yellow}{text} - Sizing:
\large,\Large,\huge,\tiny
For a complete list of supported commands, see the KaTeX documentation.
Example Equations
Calculus
Linear Algebra
Statistics
Physics
Markdown Serialization
When saving, math elements are converted back to markdown:The original LaTeX source is preserved in data attributes, ensuring perfect round-trip serialization.
Best Practices
Performance: KaTeX is much faster than MathJax, rendering equations instantly even with many equations on a page.