Search code examples
jquerymarkdowneofkatex

Expected EOF error in KaTeX


I'm using the KaTeX JavaScript library to parse and render LaTeX. It mostly works but much the time, seemingly randomly there's an EOF (end of file) error.

What my script tries to do is go through an array of raw LaTeX code and print out the literal string next to the rendered LaTeX. Here it is in a nutshell:

<div id='math-constructs'>
<script>
    $(document).ready(function() {
            $.each([
                    'frac{abc}{xyz}',
                    'overline{abc}',
                    'overrightarrow{abc}',
                    'underline{abc}',
                    'overleftarrow{abc}',
                    'sqrt{abc}',
                    'widehat{abc}',
                    'overbrace{abc}',
                    'sqrt[n]{abc}',
                    'widetilde{abc}',
                    'underbrace{abc}'
            ], function(i, char) {
                try {
                    $('#math-constructs').append('<div><code>\\' + char + '</code>' + katex.renderToString('\\' + char) + '</div>');
                } catch (err) {
                    $('#math-constructs').append('<div>' + err + '</div>');
                }
        });
    });
</script>
</div>

The code to catch the error appended on the end returns the same thing every time it runs into one.

ParseError: KaTeX parse error: Expected 'EOF', got '\overrightarrow' at position 15: \overrightarrow̲{abc}

ParseError: KaTeX parse error: Expected 'EOF', got '\widehat' at position 8: \widehat̲{abc}

I figure that there's some weird escaping of characters happening of here, and for that reason it might be worth mentioning that I'm writing this inline within markdown (specifically GFM).

Here's the LaTeX documentation I'm referencing: http://www.auburn.edu/~tamtiny/Symbols.pdf


Solution

  • This is an unfortunate way of saying that the function in question is not supported. #538 kind of covers this case as well.

    KaTeX only supports a certain subset of what LaTeX does. That subset is growing by developer contributions. \overrightarrow is tracked as #402 and \widehat is #407.