Skip to content

Commit b05ea81

Browse files
author
Michael Randolph
committed
KaTeX definitions
1 parent 3d29161 commit b05ea81

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

katex/katex-tests.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="katex.d.ts" />
2+
3+
import katexLib = require('katex');
4+
5+
class KatexTest {
6+
constructor() {
7+
katexLib.render('My Latex String', document.createElement('div'));
8+
9+
try {
10+
let options: katexLib.KatexOptions = { breakOnUnsupportedCmds: true };
11+
let value: string = katexLib.renderToString('My Latex String', options);
12+
} catch (error) {
13+
if (error instanceof katexLib.ParseError) {
14+
//do something with this error
15+
}
16+
}
17+
}
18+
}

katex/katex.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Type definitions for KaTeX v.0.5.0
2+
// Project: http://khan.github.io/KaTeX/
3+
// Definitions by: Michael Randolph <https://github.com/mrand01>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare module "katex" {
7+
interface KatexOptions {
8+
displayMode?: boolean;
9+
breakOnUnsupportedCmds?: boolean;
10+
errorColor?: string;
11+
}
12+
13+
class ParseError implements Error {
14+
constructor(message: string, lexer: any, position: number);
15+
name: string;
16+
message: string;
17+
position: number;
18+
}
19+
20+
/**
21+
* Renders a TeX expression into the specified DOM element
22+
* @param tex A TeX expression
23+
* @param element The DOM element to render into
24+
* @param options KaTeX options
25+
*/
26+
function render(tex: string, element: HTMLElement, options?:KatexOptions): void;
27+
/**
28+
* Renders a TeX expression into an HTML string
29+
* @param tex A TeX expression
30+
* @param options KaTeX options
31+
*/
32+
function renderToString(tex: string, options?:KatexOptions): string;
33+
}

0 commit comments

Comments
 (0)