Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latex-parser.pegjs.js:825 "Two \\documentclass commands. The document may only declare one class" #155

Open
artistl opened this issue Aug 12, 2024 · 1 comment

Comments

@artistl
Copy link

artistl commented Aug 12, 2024

Is there any obvious reason to be getting this error in the js console? I think I'm doing everything right...? My first time calling doPandoc(), everything works. But the second+ times I get this error.
What is received back from the HTTP response is not a standalone latex doc... it has nothing like \documentclass.

<head>
  <script src="https://cdn.jsdelivr.net/npm/latex.js/dist/latex.js"></script>
</head>

...

<script>

    var isFirst = true
    
    let generator = new latexjs.HtmlGenerator({hyphenate: false})

    function doPandoc() {
        var contents = document.getElementById("in").value;

        $.post(
            "/kip/editor/pandoc",
            {markdown: contents},
            function(data) {
                generator = latexjs.parse(data, {generator: generator})
                if (isFirst) {
                    document.head.appendChild(generator.stylesAndScripts("https://cdn.jsdelivr.net/npm/latex.js@0.12.4/dist/"))
                }
                isFirst = false
                document.body.appendChild(generator.domFragment())
            }
        )
    }

</script>
@michael-brade
Copy link
Owner

Ah. Well, calling parse replaces the documentclass macro with that error. So that means you cannot use it twice on different documents. Therefore, you have to call generator.reset() first thing in your function, before latexjs.parse().

Let me know if that solves your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants