Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to TeX style math blocks #5353

Merged
merged 5 commits into from
Nov 6, 2024
Merged

feat: switch to TeX style math blocks #5353

merged 5 commits into from
Nov 6, 2024

Conversation

OEvgeny
Copy link
Collaborator

@OEvgeny OEvgeny commented Nov 6, 2024

Fixes #

Changelog Entry

Changed

  • Switched math block syntax from $$ to Tex-style \[ \] and \( \) delimiters with improved rendering and error handling, in PR #5353, by @OEvgeny

Description

This PR enhances mathematical expression support in Web Chat by switching to TeX-style delimiters and introducing robust error handling.

Design

The implementation uses (\[ \] delimiters for block math, \( \) delimiters for inline) with a custom tokenizer and HTML renderer. Block math is rendered in figure tags while inline math uses span tags. Invalid expressions fall back to pre or code tags with an error state, allowing to apply styling if desired. The system uses Katex for rendering with MathML output and includes distinct styling for block and inline displays.

Specific Changes

  • Created new math extension with:
    • Custom tokenizer for block and inline math
    • HTML renderer with fallback on error
  • Updated markdown renderer to use the new math extension
  • Added support for inline math expressions
  • Enhanced CSS styles for math blocks and inline math
  • Added test cases for:
    • Basic math notation
    • Complex equations
    • Error scenarios
    • Inline vs block math
  • Updated sanitization rules to support math-related attributes

-

  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@OEvgeny OEvgeny changed the title feat: switch to Tex style math blocks feat: switch to TeX style math blocks Nov 6, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greek font is missing in the docker image, I verified it works as expected in my browser

@OEvgeny OEvgeny marked this pull request as ready for review November 6, 2024 20:37
Copy link
Contributor

@compulim compulim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can npm uninstall micromark-extension-math and may need to npm install katex.

@OEvgeny OEvgeny merged commit 8ac01bf into main Nov 6, 2024
27 checks passed
@OEvgeny OEvgeny deleted the feat/tex-style-math branch November 6, 2024 21:25
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.

2 participants