How to use the katex.renderToString function in katex

To help you get started, we’ve selected a few katex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tylingsoft / markdown-core / markdown-core-new.js View on Github external
mdc.renderer.rules.code_inline = function(tokens, idx) {
  var code = tokens[idx].content;
  if(code.startsWith('$') && code.endsWith('$')) { // inline math
    code = code.substr(1, code.length-2);
    try{
      return katex.renderToString(code);
    } catch(err) {
      return '<code>' + err + '</code>';
    }
  }
  return '<code>' + code + '</code>'; // not math
}
github talyssonoc / react-katex / test / sharedExamples.js View on Github external
it('renders correctly', () =&gt; {
      const math = shallow({ integralFormula });

      expect(math.html()).to.equal(
        `&lt;${wrapperTag}&gt;${ KaTeX.renderToString(integralFormula, { displayMode }) }`
      );
    });
github zzish / react-latex / lib / Latex.js View on Github external
var renderLatexString = function(s){
        var renderedString;
        try {
            renderedString = katex.renderToString(s, options);

        } catch (err){
            console.error('couldn`t convert string', s);
            return s;
        }
        return renderedString;
    };
github K3D-tools / K3D-jupyter / js / src / providers / threejs / objects / Text2d.js View on Github external
update: function (config, changes, obj) {
        if (typeof(changes.text) !== 'undefined' && !changes.text.timeSeries) {
            obj.domElement.innerHTML = katex.renderToString(changes.text, {displayMode: true});

            changes.text = null;
        }

        if (typeof(changes.position) !== 'undefined' && !changes.position.timeSeries) {
            obj.position.set(changes.position[0], changes.position[1], changes.position[2]);
            obj.updateMatrixWorld();

            changes.position = null;
        }

        if (areAllChangesResolve(changes)) {
            return Promise.resolve({json: config, obj: obj});
        } else {
            return false;
        }
github gitlabhq / gitlabhq / app / assets / javascripts / notebook / cells / markdown.vue View on Github external
let matches = regex.exec(katexString);
      if (matchLocation > 0) {
        numInline += 1;

        while (matches !== null) {
          try {
            const renderedKatex = katex.renderToString(deHTMLify(matches[0].replace(/\$/g, '')));
            text = `${text.replace(matches[0], ` ${renderedKatex}`)}`;
          } catch {
            numInline -= 1;
          }
          matches = regex.exec(katexString);
        }
      } else {
        try {
          text = katex.renderToString(deHTMLify(matches[2]));
        } catch (error) {
          numInline -= 1;
        }
      }
    }
  }
  return [text, numInline > 0];
}
renderer.paragraph = (t) => {
github pubpub / pubpub / src / components / AtomTypes / LaTeX / LaTeXViewer.jsx View on Github external
generateHTML(text) {
		const inlineHTML = katex.renderToString(text, {displayMode: false, throwOnError: false});
		const displayHTML = katex.renderToString(text, {displayMode: true, throwOnError: false});
		return {inlineHTML, displayHTML};
	},
github probmods / webppl / src / index.js View on Github external
replace: function(text, group) {
        try {
          return katex.renderToString(group);
        } catch (e) {
          return group;
        }
      }
    }
github substance / texture / src / article / editor / InlineFormulaComponent.js View on Github external
render ($$) {
    const node = this.props.node
    const texMath = node.textContent
    const el = $$('span').addClass('sc-math')
    if (!texMath) {
      el.append('???')
    } else {
      try {
        el.append(
          $$('span').html(katex.renderToString(texMath))
        )
        let blockerEl = $$('div').addClass('se-blocker')
        el.append(blockerEl)
      } catch (error) {
        el.addClass('sm-error')
          .text(error.message)
      }
    }
    return el
  }
}
github ACGN-stock / acgn-stock / client / utils / helpers.js View on Github external
const outputKatexHTML = text.replace(/¨D¨D((.|\n)*?)¨D¨D/g, function(match, capture) {
      const text = capture.replace(/&amp;/g, '&amp;').replace(/&lt;/g, '&lt;').replace(/"/g, '"').replace(/\n/g, '\r\n');
      let html = katex.renderToString(text);

      if (text.search('\n') !== -1) {
        html = `<br>${html}`;
      }

      return html;
    });
github remarkjs / remark-math / specs / rehype-katex.spec.js View on Github external
const processor = remark()
    .use(math)
    .use(remark2rehype)
    .use(rehypeKatex, {
      errorColor: 'orange',
      macros: macros
    })
    .use(stringify)

  const targetText = '$\\RR$'

  const result = processor.processSync(targetText)
  const renderedAst = parseHtml(result.toString())

  const expectedInlineMathChildren = parseHtml(
    katex.renderToString('\\RR', {macros: macros})
  ).children

  expect(renderedAst).toEqual(
    u('root', {data: {quirksMode: false}}, [
      h('p', [h('span', {className: 'inlineMath'}, expectedInlineMathChildren)])
    ])
  )
})