parseToLatex
Converts maths typed in plain shorthand, such as x^2/4 or sqrt(2), into LaTeX that KaTeX can render.
@internote/canvas-sdk/reactOn this page
import { parseToLatex } from '@internote/canvas-sdk/react';A reader types what they would write by hand and sees it set as maths. No parser, just ordered substitution, which is what makes it forgiving enough to run on every keystroke of a half-finished expression. The shorthand it reads:
- Greek letters by name or as the Unicode letter:
piandπto\pi. inforinfinityto\infty, and+-to\pm.- Roots:
sqrt(x)to\sqrt{x},3rt(x)to\sqrt[3]{x}. - Fractions:
2/3to\frac{2}{3},x/(a+b)to\frac{x}{a+b}. - Powers and subscripts:
x^2tox^{2},x_(n+1)tox_{n+1}. - Functions set upright:
sin(x)to\sin(x),ln(x)to\ln(x). *to\times.
Powers are braced before fractions are read, because powers bind tighter than division: x^2/4 is (x^2)/4.
#Signature
(input: string): string#Parameters
inputThe shorthand as typed.
#Example
<Maths>{parseToLatex(typed)}</Maths>Declared in packages/canvas-sdk/src/react/math/parseToLatex.ts:205.