Jwrede / Anki-KaTeX-Markdown

Creates a new Basic and a new Cloze Note Type that support Markdown and KaTeX
75 stars 5 forks source link

Dollar sign in code block issues #24

Open nicole-ptr opened 2 years ago

nicole-ptr commented 2 years ago

The below in JavaScript causes issues at it triggers katex:

This is a ${variable}.

also ${here}

pilgrimlyieu commented 2 years ago

Emmm, a complicated issue.

I have an indirect solution.

First you need to clone the origin markdown template to prevent the modified code from being covered.

Then search the following code.

    function renderMath(ID) {
        let text = document.getElementById(ID).innerHTML;
        text = replaceInString(text);
        document.getElementById(ID).textContent = text;
        renderMathInElement(document.getElementById(ID), {
            delimiters:  [
                {left: "$$", right: "$$", display: true},
                {left: "$", right: "$", display: false}
            ],
            throwOnError : false
        });
    }

Modify delimiters in both side.

Maybe \( and \) like {left: "\\(", right: "\\)", display: false}.

Or [katex] like {left: "[katex]", right: "[katex]", display: false}

Jwrede commented 2 years ago

Thanks pilgrimlyieu, this is exactly how to fix it, I know about this issue but fixing it would require to write a parser which understands whether you want $ to trigger the math mode or just a simple $. Since I don't have the time to maintain this addon I've thought about updating it s.t. changes in the original card types are not overwritten anymore, what do you think about this? This would mean that I will not be able to update the add on easily but it would be alot easier for you to change the card code