Skip to content

Add LaTeX math support to MarkdownText with Unicode rendering and pre…#442

Open
samrudha01codespace wants to merge 1 commit intogoogle-ai-edge:mainfrom
samrudha01codespace:samrudha01codespace
Open

Add LaTeX math support to MarkdownText with Unicode rendering and pre…#442
samrudha01codespace wants to merge 1 commit intogoogle-ai-edge:mainfrom
samrudha01codespace:samrudha01codespace

Conversation

@samrudha01codespace
Copy link
Copy Markdown

This pull request significantly enhances the MarkdownText composable in MarkdownText.kt by adding support for rendering LaTeX-style mathematical expressions within Markdown, converting them to Unicode symbols for display. It also introduces new helper functions, UI improvements, and preview examples.

LaTeX/Math Support and Processing:

  • Added a convertLatexToUnicode helper function that maps common LaTeX commands (Greek letters, math operators, superscripts, subscripts, fractions) to their Unicode equivalents, enabling basic math rendering without a LaTeX engine.
  • Updated MarkdownText to process and replace inline ($...) and block ($...$`) LaTeX expressions in the input text, displaying them as Unicode math symbols.
  • Introduced a MathExpression composable for rendering block and inline math in a styled manner, including background and font adjustments.

UI and Theming Improvements:

  • Improved code block and link styling in Markdown using RichTextStyle and TextLinkStyles, and updated color and typography handling for better readability and theme integration.
  • Replaced references to customColors with theme-aware color selection and added underline styling to links. (Fc29d3b2L

@samrudha01codespace
Copy link
Copy Markdown
Author

samrudha01codespace commented Feb 20, 2026

Markdown Enhancement

Add Lightweight LaTeX Math Rendering Support to MarkdownText


Overview

This pull request enhances the MarkdownText composable by introducing lightweight LaTeX-style mathematical rendering without requiring a full LaTeX engine.

The implementation focuses on practical, commonly used mathematical expressions while keeping the solution Compose-native and efficient.


What’s Included

1. LaTeX / Math Support

  • Support for inline math expressions using $...$.

  • Support for block math expressions.

  • New convertLatexToUnicode() helper function that maps common LaTeX commands to Unicode equivalents, including:

    • Greek letters
    • Superscripts and subscripts
    • Basic mathematical operators
    • Fractions

This enables basic math rendering directly inside Markdown without external rendering engines.


2. New Composable

  • Introduced MathExpression composable for rendering inline and block math.

  • Styled rendering with:

    • Background adjustments
    • Typography tuning
    • Improved readability

3. UI & Theming Improvements

  • Improved code block styling using RichTextStyle.
  • Enhanced link styling with underline support.
  • Replaced custom color references with theme-aware color handling.
  • Refined typography for better consistency and readability.

Why This Change

  • Enables mathematical content inside Markdown.
  • Avoids dependency on heavy LaTeX engines.
  • Improves support for technical documentation and educational content.
  • Maintains lightweight and extensible architecture.

Scope

The implementation focuses on commonly used mathematical constructs and is designed for future extensibility.

No breaking changes introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant