Math

The plugin helps to work with mathematical expressions. Supports Katex and MathJax libraries.

    Click on a mathematical expression to see the button on the toolbar to edit or insert the expression using the plus button.

    Code

    <!DOCTYPE html>
    <html>
        <head>
            <title>Article Editor</title>
            <meta charset="utf-8">
    
            <!-- css -->
            <link rel="stylesheet" href="/your-article-dist-path/article-editor.css" />
        </head>
        <body>
            <!-- element -->
            <textarea id="entry">...</textarea>
    
            <!-- js -->
            <script src="/your-article-dist-path/article-editor.js"></script>
            <script src="/your-article-dist-path/plugins/math.js"></script>
    
            <!-- call -->
            <script>
            ArticleEditor('#entry', {
                plugins: ['math'],
                css: '/your-article-dist-path/',
                custom: {
                    css: ['https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css'],
                    js: ['https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js']
                },
                math: {
                    delimiters: [
                        { left: "$$", right: "$$", display: true },
                        { left: "$", right: "$", display: false },
                        { left: "\\(", right: "\\)", display: false },
                        { left: "\\[", right: "\\]", display: true }
                    ]
                }
            });
            </script>
        </body>
    </html>

    Usage

    Katex

    The plugin supports Katex library by default. To do this, as shown in the example above, you need to connect CSS and JS libraries in Article.

    By default, the plugin does not render inline expressions like $...$. To change this, run the plugin with delimiters setting like this:

    ArticleEditor('#entry', {
        plugins: ['math'],
        css: '/your-article-dist-path/',
        custom: {
            css: ['https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css'],
            js: ['https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js']
        },
        math: {
            delimiters: [
                { left: "$$", right: "$$", display: true },
                { left: "$", right: "$", display: false },
                { left: "\\(", right: "\\)", display: false },
                { left: "\\[", right: "\\]", display: true }
            ]
        }
    });

    MathJax

    To support MathJax 3.0 library, you need to run the plugin with the appropriate settings and connect the library config and JS file of the library itself.

    By default, the plugin does not render inline expressions like $...$. To change this, run the plugin with delimiters setting like this:

     ArticleEditor('#entry', {
        plugins: ['math'],
        css: '/your-article-dist-path/',
        custom: {
            js: [
                '/your-path-to/mathjax-config.js'
                'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js'
            ]
        },
        math: {
            mathjax: true,
            delimiters: [
                { left: "$$", right: "$$", display: true },
                { left: "$", right: "$", display: false },
                { left: "\\(", right: "\\)", display: false },
                { left: "\\[", right: "\\]", display: true }
            ]
        }
    });

    The library config mathjax-config.js file should look something like this:

    MathJax = {
        startup: {
            typeset: false
        },
        tex: {
            inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        svg: {
            fontCache: 'global'
        }
    };

    Note the automatic rendering of startup.typeset: false. This is a required setting for the plugin to work correctly.