From b05ea8139c03b72773b6d0e6c74cbe5a7fc89b08 Mon Sep 17 00:00:00 2001 From: Michael Randolph Date: Thu, 6 Aug 2015 15:14:39 -0400 Subject: [PATCH] KaTeX definitions --- katex/katex-tests.ts | 18 ++++++++++++++++++ katex/katex.d.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 katex/katex-tests.ts create mode 100644 katex/katex.d.ts diff --git a/katex/katex-tests.ts b/katex/katex-tests.ts new file mode 100644 index 0000000000..9829fcddf7 --- /dev/null +++ b/katex/katex-tests.ts @@ -0,0 +1,18 @@ +/// + +import katexLib = require('katex'); + +class KatexTest { + constructor() { + katexLib.render('My Latex String', document.createElement('div')); + + try { + let options: katexLib.KatexOptions = { breakOnUnsupportedCmds: true }; + let value: string = katexLib.renderToString('My Latex String', options); + } catch (error) { + if (error instanceof katexLib.ParseError) { + //do something with this error + } + } + } +} \ No newline at end of file diff --git a/katex/katex.d.ts b/katex/katex.d.ts new file mode 100644 index 0000000000..6d139ded13 --- /dev/null +++ b/katex/katex.d.ts @@ -0,0 +1,33 @@ +// Type definitions for KaTeX v.0.5.0 +// Project: http://khan.github.io/KaTeX/ +// Definitions by: Michael Randolph +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "katex" { + interface KatexOptions { + displayMode?: boolean; + breakOnUnsupportedCmds?: boolean; + errorColor?: string; + } + + class ParseError implements Error { + constructor(message: string, lexer: any, position: number); + name: string; + message: string; + position: number; + } + + /** + * Renders a TeX expression into the specified DOM element + * @param tex A TeX expression + * @param element The DOM element to render into + * @param options KaTeX options + */ + function render(tex: string, element: HTMLElement, options?:KatexOptions): void; + /** + * Renders a TeX expression into an HTML string + * @param tex A TeX expression + * @param options KaTeX options + */ + function renderToString(tex: string, options?:KatexOptions): string; +} \ No newline at end of file