Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 2, 2022 07:51
Show Gist options
  • Save jeroen/74e2a694deed267bed96c478fee2f6c3 to your computer and use it in GitHub Desktop.
Save jeroen/74e2a694deed267bed96c478fee2f6c3 to your computer and use it in GitHub Desktop.
Validates mathjax using katex
ctx <- V8::v8()
ctx$source('https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js')
ctx$eval('function validate(s){var out = {result: "ok", warnings:[]}; try{console.warn=function(w){out.warnings.push(w);};katex.renderToString(s)} catch (e) {out.result = e.name; out.position = e.position; out.message = e.message}; return out;}')
# Parsing error
ctx$call('validate', "E(y) = \\boldmath{\\mu}")
# OK but with warnings:
ctx$call('validate', "s*ₓᵢ = sₓᵢ √(VIFₓᵢ⁻¹) √((n-1)/(n-p))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment