npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-math

v2.0.1

Published

Render math natively in React Native using Katex for Android and iOS

Downloads

272

Readme

react-native-math

Why this package?

There are a few other packages out there to render math equations in React Native Math. The only reason why I chose to create this package is because I could'nt find any package that supports line break inside the view, most of them reduced the width to an unreadable size when equation is too long or when there is text along with the equation. Also I wanted a way to use Math the same way we use any other components, instead of managing a WebView

PR's and issues are always welcome :)

Warning: This package does not support for iOS as of now

This package currently does not support math for iOS. Feel free to send a pull request. Katex-iOS native package: https://github.com/ianarawjo/KaTeX-iOS

Installation

$ npm install react-native-math react-native-webview

Usage


import React from 'react'
import { View } from 'react-native'
import MathText from 'react-native-math';

class MathItem extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, margin: 20 }}>
        <MathText
          content={`
            $$E = mc^2$$
            $2^{1+2}$
            Here is an inline equation: $a^2 + b^2 = c^2$
            <p>Additional HTML content can go here.</p>
          `}
          textSize={20}
          textColor={"#333"}
          style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
        />

        <MathText
          content={`Dissolve this $x=\\frac{1+y}{1+2z^2}$ using lorem ipsum dolor sit amet`}
          textSize={20}
          textColor={"#333"}
          style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
        />

        <MathText
          content={`sum of ratios =4+3=7 $=\\frac{4}{7}\\times560=320$`}
          textSize={20}
          textColor={"#333"}
          style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
        />

        <MathText
          content={`$x=\\frac{1+y}{1+2z^2}$`}
          textSize={20}
          textColor={"#333"}
          style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
        />
      </View>
    )
  }
}

Expected Output https://i.imgur.com/wwpvZKE.png

Supported Props

| Prop | Default | Type | Description | | :-------- | :-------: | :--------------: | :-------------------------------------------------------- | | style | {} | object/array | Default react native styles (Pass background color here) | | content | "" | string | Katex text (Make sure to escape \ using two \ slashes ) | | textSize | 20 | number | Font size of the math equation Ex:10 | | textColor | #000000 | hex color | Pass 6 character hex color value |

Known issues

1. The flex requirement

Native UI modules requires to have the style of the native view and all it's parents to have a style flex property of 1 or greater. The workaround is pretty simple, add flex:1 or any other value to flex property to all the parent views of the math component.