katex's notebooks

  • token - /katex/token
    Last edited 5 years ago
    let SourceLocation = require('@runkit/katex/sourcelocation/1.0.0') class Token { constructor(text, loc) { this.text = text; this.loc = loc; } range( endToken, text) { return new Token(text, SourceLocation.range(this, endToken)); } } module.exports = { Token }
  • SourceLocation - /katex/sourcelocation
    Last edited 5 years ago
    class SourceLocation { // not sure what is a lexer. a regex? or a token value? constructor(lexer, start, end) { this.lexer = lexer; this.start = start; this.end = end; } // SourceLocation.range({loc: {lexer: 'al', start: 3}}, {loc: {lexer: 'al', end: 10}}) // => SourceLocation {end: 10, lexer: "al", start: 3} static range( first, second) { // first and second are both Tokens. // { text: 'albert', loc: new SourceLocation() } if (!second) { return first && first.loc; } else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) { return null; } else { return new SourceLocation( first.loc.lexer, first.loc.start, second.loc.end); } } } module.exports = {SourceLocation}