All Projects → talyssonoc → React Katex

talyssonoc / React Katex

Display math in TeX with KaTeX and ReactJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Katex

Jekyll Spaceship
🚀 A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, emoji, video, audio, youtube, vimeo, dailymotion, soundcloud, spotify, etc.
Stars: ✭ 196 (-43.19%)
Mutual labels:  latex, math, katex
Remark Math
remark and rehype plugins to support math
Stars: ✭ 129 (-62.61%)
Mutual labels:  latex, math, katex
Katex
Fast math typesetting for the web.
Stars: ✭ 14,623 (+4138.55%)
Mutual labels:  latex, math, katex
Mdmath
LaTeX Math for Markdown inside of Visual Studio Code.
Stars: ✭ 675 (+95.65%)
Mutual labels:  latex, math, katex
Upmath.me
Markdown and LaTeX online editor - create text for web with equations and diagrams
Stars: ✭ 234 (-32.17%)
Mutual labels:  latex, math
Csharpmath
LaTeX. in C#. (ported from the wonderful iosMath project).
Stars: ✭ 205 (-40.58%)
Mutual labels:  latex, math
Qilin App
Fully hackable text editor developed for exact sciences with built-in KaTeX and AsciiMath support. Extensible via plugins and themes. Exportable as HTML, PDF and GFM.
Stars: ✭ 336 (-2.61%)
Mutual labels:  latex, katex
showdown-katex
Math typesetting for showdown
Stars: ✭ 32 (-90.72%)
Mutual labels:  math, katex
react-katex
Display math in TeX with KaTeX and ReactJS
Stars: ✭ 135 (-60.87%)
Mutual labels:  math, katex
Wpf Math
.NET library for rendering mathematical formulae using the LaTeX typsetting style, for the WPF framework
Stars: ✭ 339 (-1.74%)
Mutual labels:  latex, math
hfmath
Render LaTeX math with Hershey Fonts
Stars: ✭ 76 (-77.97%)
Mutual labels:  latex, math
purple-pi
💜 LaTeX math wherever you want
Stars: ✭ 31 (-91.01%)
Mutual labels:  latex, katex
Nerdamer
a symbolic math expression evaluator for javascript
Stars: ✭ 322 (-6.67%)
Mutual labels:  latex, math
Flutter tex
A Flutter Package to render Mathematics, Physics and Chemistry Equations based on LaTeX
Stars: ✭ 161 (-53.33%)
Mutual labels:  latex, katex
Texme
Self-rendering Markdown + LaTeX documents
Stars: ✭ 1,970 (+471.01%)
Mutual labels:  latex, math
augmath
Interactive Computer Algebra System. Augmenting how we *do* mathematics using computers
Stars: ✭ 41 (-88.12%)
Mutual labels:  math, katex
Angourimath
Open-source symbolic algebra library for C# and F#. One of the most powerful in .NET
Stars: ✭ 266 (-22.9%)
Mutual labels:  latex, math
Spmathkit
Render math exercises for your view. Contains the rendering of mathematical formulas and mathematical graphics, as well as the general text
Stars: ✭ 81 (-76.52%)
Mutual labels:  latex, katex
Mathbin
Math pastebin with LaTeX and Markdown support
Stars: ✭ 83 (-75.94%)
Mutual labels:  latex, math
react-latex-next
Render LaTeX in React apps
Stars: ✭ 18 (-94.78%)
Mutual labels:  latex, katex

react-katex

Build Status Code Climate Coverage Status

Display math expressions with KaTeX and React

Installation

  $ npm install react-katex
  # or
  $ yarn add react-katex

Usage

import 'katex/dist/katex.min.css';
import { InlineMath, BlockMath } from 'react-katex';

InlineMath

Display math in the middle of the text.

  var InlineMath = ReactKaTeX.InlineMath;

  ReactDOM.render(<InlineMath math="\\int_0^\\infty x^2 dx"/>,
                document.getElementById('math'));

  // or

  ReactDOM.render(<InlineMath>\int_0^\infty x^2 dx</InlineMath>,
                document.getElementById('math'));

It will be rendered like this:

Inline math

BlockMath

Display math in a separated block, with larger font and symbols.

  var BlockMath = ReactKaTeX.BlockMath;

  ReactDOM.render(<BlockMath math="\\int_0^\\infty x^2 dx"/>,
                document.getElementById('math'));

  // or

  ReactDOM.render(<BlockMath>\int_0^\infty x^2 dx</BlockMath>,
                document.getElementById('math'));

It will be rendered like this:

Block math

Note:
Don't forget to import KaTeX CSS file.

import 'katex/dist/katex.min.css';

Error handling

Default error message

By default the error rendering is handled by KaTeX. You can optionally pass errorColor (defaults to #cc0000) as a prop:

var BlockMath = ReactKaTeX.BlockMath;

ReactDOM.render(
  <BlockMath
    math={'\\int_0^\\infty x^2 dx \\inta'}
    errorColor={'#cc0000'}
  />, document.getElementById('math'));

This will be rendered like so:

KaTeX error

Custom error message

It's possible to handle parse errors using the prop renderError. This prop must be a function that receives the error object and returns what should be rendered when parsing fails:

var BlockMath = ReactKaTeX.BlockMath;
  
ReactDOM.render(
  <BlockMath
    math="\\int_{"
    renderError={(error) => {
      return <b>Fail: {error.name}</b>
    }}
  />,
  document.getElementById('math'));

// The code above will render '<b>Fail: ParseError</b>' because it's the value returned from `renderError`.

This will render <b>Fail: ParseError</b>:

renderError

Escaping expressions

In addition to using the math property, you can also quote as a child allowing the use of { } in your expression.

ReactDOM.render(<BlockMath>{"\\frac{\\text{m}}{\\text{s}^2}"}</BlockMath>,
                document.getElementById('math'));

Or Multiline

ReactDOM.render(<BlockMath>{`\\frac{\\text{m}}
{\\text{s}^2}`}</BlockMath>,
                document.getElementById('math'));

However, it can be annoying to escape backslashes. This can be circumvented with the String.raw tag on a template literal when using ES6.

ReactDOM.render(<BlockMath>{String.raw`\frac{\text{m}}{\text{s}^2}`}</BlockMath>,
                document.getElementById('math'));

Backticks must be escaped with a backslash but would be passed to KaTeX as \`. A tag can be created to replace \` with `

const latex = (...a) => String.raw(...a).replace("\\`","`")
ReactDOM.render(<BlockMath>{latex`\``}</BlockMath>,
                document.getElementById('math'));

You can even do variable substitution

const top = "m";
const bottom = "s";
ReactDOM.render(<BlockMath>{String.raw`\frac{\text{${top}}}{\text{${bottom}}^2}`}</BlockMath>,
                document.getElementById('math'));
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].