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-mathjax-editor

v0.0.2

Published

mathjax editor for react

Downloads

7

Readme

react-mathjax-editor

NPM version NPM downloads

mathjax editor for react

Note: The full documentation is available at https://github.com/Orcish-Y/react-mathjax-editor

  This library provides a user-friendly React component for visualizing mathematical formulas. Users can build the desired mathematical formulas by clicking and interacting with an intuitive input panel, and these formulas will be displayed in real-time on the interface. Additionally, by adjusting schema (configuration) parameters, you can customize the formula symbols in the input panel, making this component better suited to your project. Whether it's mathematical, chemical, or other scientific symbols, this component can provide you with a flexible and convenient formula input experience. Installing and using this component is very simple, without complex configuration or knowledge of mathjax. Simply follow the provided guidelines, and you can easily integrate this powerful mathematical formula input component into your React project.

Mathjax editor demo

Mathjax editor demo

Mathjax editor panel demo

Mathjax editor panel demo

Basic Usage

📦 Install

npm i react-mathjax-editor --save
yarn add react-mathjax-editor
pnpm add react-mathjax-editor

🔨 Usage

Mathjax Editor

import React, { useState } from 'react';
import { MathJaxEditor } from 'react-mathjax-editor';

export default () => {
  const [value, setValue] = useState<string>();
  return <MathJaxEditor value={value} onChange={setValue} />;
};

Use with forms

import { Button, Form } from 'antd';
import React from 'react';
import { MathJaxEditor } from 'react-mathjax-editor';

export default  () => {
  return (
    <Form onFinish={(value) => console.log('do something')}>
      <Form.Item label="MachJax" name="machJax" rules={[{ required: true }]}>
        <MathJaxEditor  />
      </Form.Item>
      <Form.Item>
        <Button type="primary" htmlType="submit">
          Submit
        </Button>
      </Form.Item>
    </Form>
  )

Mathjax Panel

import React, { useState } from 'react';
import { MathJax, MathJaxContext, MathJaxPanel } from 'react-mathjax-editor';

export default () => {
  const [value, setValue] = useState<string>();
  return <MathJaxPanel value={value} onChange={setValue} />;
};

Rendering formula

import React from 'react';
import { MathJax, MathJaxContext } from 'react-mathjax-editor';

export default () => {
  const methJaxString = `\\left( \\sum_{k=1}^n a_k b_k \\right)^{\\!\\!2}\\leq
\\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right) `;

  return (
    <MathJaxContext>
      <MathJax inline dynamic>
        {`$$ ${methJaxString} $$`}
      </MathJax>
    </MathJaxContext>
  )

Custom Mathjax Panel

import { Space } from 'antd';
import React from 'react';
import {
  MathJaxEditor,
  MathJaxPanel,
  cursorPosition,
  insertedPosition,
  type Schema,
} from 'react-mathjax-editor';
import symbolPicUrl from '../assets/images/symbol.png';

const exampleSchema: Schema[] = [
  {
    key: 'machJax-series1',
    label: 'machJax-series1',
    machJaxSeries: [
      {
        label: 'mathJax-set1',
        key: 'mathJax-set1',
        illustrate: symbolPicUrl,
        mathJaxGroup: [
          {
            groupName: 'demo same as value',
            mathJax: ['+', '-', '\\times', '{\\div}'],
          },
          {
            groupName: 'demo same as value',
            mathJax: [
              {
                demo: '\\mathbb{ABC}',
                mathJax: `\\mathbb{${insertedPosition}}`,
              },
              {
                demo: '\\frac{a}{b}',
                mathJax: `\\\\frac{${insertedPosition}}{${cursorPosition}}`,
              },
            ],
          },
        ],
      },
      {
        label: 'mathJax-set2',
        key: 'mathJax-set2',
        illustrate:
          'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        mathJaxGroup: [
          {
            groupName: 'mathJax-group1',
            mathJax: ['\\prec', '\\subseteq', '\\perp'],
          },
        ],
      },
    ],
  },
  {
    key: 'machJax-series2',
    label: 'machJax-series2',
    machJaxSeries: [
      {
        label: 'mathJax-set3',
        key: 'mathJax-set3',
        illustrate: '',
        mathJaxGroup: [
          {
            groupName: 'mathJax-group1',
            mathJax: [
              '\\left(x-1\\right)\\left(x+3\\right)',
              '\\sqrt{a^2+b^2}',
            ],
          },
        ],
      },
    ],
  },
  {
    key: 'machJax-series3',
    label: 'machJax-series3',
    machJaxSeries: [],
  },
];

export default () => {
  return (
    <Space direction="vertical" style={{ width: '100%' }}>
      <MathJaxEditor schema={exampleSchema} placeholder="mathJax placeholder" />
      <MathJaxPanel schema={exampleSchema} />
    </Space>
  );
};

API

MathJaxEditor API

| Parameters | Explanation | Type | Default Value | | ----------------- | ---------------------------------------------------------------------- | ------------------------ | --------------------- | | value | Input field content | string | - | | onChange | Callback when the contents of the input field change | (value?: string) => void | - | | schema | The large object that displays symbols and code in the rendering panel | Schema[] | Predefined content | | placeholder | placeholder | string | '请添加 mathJax 公式' | | className | Semantic structure class | string | - | | style | Semantic structure style | React.CSSProperties | - | | disabled | Whether to disable the state | boolean | false | | ghost | Whether to hide the border of the input border | boolean | false | | mathJaxPanelWidth | Panel width | number | string | 334 | | mathJaxSetWidth | Width of the mathJax collection popover | number | string | 334 |

MathJaxPanel API

| Parameters | Explanation | Type | Default Value | | ---------------- | ---------------------------------------------------------------------- | ------------------------ | ------------------ | | value | Input field content | string | - | | onChange | Callback when the contents of the input box change | (value?: string) => void | - | | schema | The large object that displays symbols and code in the rendering panel | Schema[] | Predefined content | | style | Semantic structure style | React.CSSProperties | - | | width | Panel width | number | string | 334 | | mathJaxSetWidth | Width of the mathJax collection popover | number | string | 334 | | autoFocusOnMount | Whether the component hangs on completion automatically gets focus | boolean | false |

better-react-mathjax API

better-react-mathjax API Please check official documentation

schema explain

/** Symbols used to customize the panel */
export type Schema = {
  key: string;
  /** The tab name on the panel */
  label: string;
  /** Panel tab data */
  machJaxSeries: {
    key: string;
    /** Collection name */
    label: string;
    /** Collection Icon */
    illustrate: string;
    /** Collection data */
    mathJaxGroup: {
      /** Group name */
      groupName: string;
      /** Grouped data */
      mathJax: (
        | string
        | {
            /** demo */
            demo: string;
            /** mathjax */
            mathJax: string;
          }
      )[];
    }[];
  }[];
}[];

schema schematic diagram

Development

# install dependencies
$ yarn install

# develop library by docs demo
$ yarn start

# build library source code
$ yarn run build

# build library source code in watch mode
$ yarn run build:watch

# build docs
$ yarn run docs:build

# Locally preview the production build.
$ yarn run docs:preview

# check your project for potential problems
$ yarn run doctor

未来计划

  1. Component internationalization
  2. Remove antd to make components more generic

LICENSE

MIT