2.0.1 • Published 4 months ago

react-autolatex v2.0.1

Weekly downloads
120
License
MIT
Repository
github
Last release
4 months ago

react-autolatex

npm.io npm.io npm.io npm.io npm.io npm.io

Auto-render LaTeX in React.

Based on KaTeX. TypeScript declaration supported.

Installation

npm install react-autolatex

Usage

Normal:

import 'katex/dist/katex.min.css';
import AutoLaTeX from 'react-autolatex';

export default () => {
  return (
    <AutoLaTeX>{'LaTeX string or HTML rich text with LaTeX like $c = \\pm\\sqrt{a^2 + b^2}$'}</AutoLaTeX>    
  );
};

With TypeScript:

import 'katex/dist/katex.min.css';
import AutoLaTeX, { RenderMathInElementOptions } from 'react-autolatex';

export default () => {
  const options: RenderMathInElementOptions = {
    delimiters: [
      { left: '$$', right: '$$', display: true },
      { left: '$', right: '$', display: false },
    ],
    errorCallback(msg: string, err: Error) {
      console.error('[Error]', msg, err);
    },
  };
  return (
    <AutoLaTeX options={options}>{'LaTeX string or HTML rich text with LaTeX like $c = \\pm\\sqrt{a^2 + b^2}$'}</AutoLaTeX>    
  );
};

Note: You may need to handle XSS before passing string to AutoLaTeX.

Props

NameTypeDefaultDescription
childrenstring, required''The string content to render
optionsRenderMathInElementOptions*see belowRender options (doc)
classNamestring''Class name for the container to render LaTeX
styleReact.CSSProperties{}Style for the container to render LaTeX

options default:

{
  delimiters: [
    { left: "$$", right: "$$", display: true },
    { left: "\\[", right: "\\]", display: true },
    { left: "$", right: "$", display: false },
    { left: "\\(", right: "\\)", display: false },
  ],
}

License

MIT

2.0.1

4 months ago

2.0.0

4 months ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago