Sha256: 6b506db0a22cd9901d28fd068ab3a886728e60497bad096c8fb062740bd3fffd

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

var elements = document.getElementsByTagName('script');

Array.prototype.forEach.call(elements, function (element) {
    if (element.type.indexOf('math/tex') !== -1) {
        // Extract math markdown
        var textToRender = element.innerText || element.textContent;

        // Kramdown and KaTeX workaround
        // https://github.com/rohanchandra/type-theme/issues/47
        textToRender = textToRender.replace(/%.*/g, '');

        // Create span for KaTeX
        var katexElement = document.createElement('span');

        // Support inline and display math
        if (element.type.indexOf('mode=display') !== -1) {
            katexElement.className += "math-display";
            textToRender = '\\displaystyle {' + textToRender + '}';
        } else {
            katexElement.className += "math-inline";
        }

        // Set displayMode to true to center equation
        // https://github.com/Khan/KaTeX/issues/626
        katex.render(textToRender, katexElement, {displayMode: false});
        element.parentNode.insertBefore(katexElement, element);
    }
});

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
type-on-strap-1.3.0 assets/js/partials/katex_init.js
type-on-strap-1.1.1 assets/js/partials/katex_init.js
jekyll-theme-type-on-strap-6.0.0 assets/js/partials/katex_init.js
jekyll-theme-type-on-strap-5.0.1 assets/js/partials/katex_init.js
type-on-strap-1.0.1 assets/js/partials/katex_init.js
type-on-strap-0.6.3 assets/js/partials/katex_init.js