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

Escape dollar #192

Merged
merged 3 commits into from
Jun 4, 2024
Merged

Escape dollar #192

merged 3 commits into from
Jun 4, 2024

Conversation

rikhuijzer
Copy link
Owner

This makes PlutoStaticHTML escape dollar symbols when they were escaped in Pluto too. This avoids having multiple dollar symbols in one line to be interpreted as inline math. Doing these escapes are supported by at least MathJax (https://docs.mathjax.org/en/latest/input/tex/delimiters.html), but I'm quite sure KaTeX too.

@rikhuijzer rikhuijzer enabled auto-merge (squash) June 4, 2024 09:03
@rikhuijzer rikhuijzer merged commit 4e48fb9 into main Jun 4, 2024
3 checks passed
@rikhuijzer rikhuijzer deleted the rh/escape-dollar branch June 4, 2024 09:04
@rikhuijzer
Copy link
Owner Author

Note that outside Documenter, this now requires the escaped dollar symbols to be converted back to normal dollar symbols inside HTML after running KaTeX or Mathjax. This is what I have in my blog now:

<script src="/libs/katex/katex.min.js"></script>
<script src="/libs/katex/auto-render.min.js"></script>
<script>
  const options = {
    delimiters: [
      {left: "$$", right: "$$", display: true},
      {left: "$", right: "$", display: false},
      {left: "``", right: "``", display: false},
      {left: "\\begin{equation}", right: "\\end{equation}", display: true},
      {left: "\\begin{align}", right: "\\end{align}", display: true},
      {left: "\\begin{alignat}", right: "\\end{alignat}", display: true},
      {left: "\\begin{gather}", right: "\\end{gather}", display: true},
      {left: "\\(", right: "\\)", display: false},
      {left: "\\[", right: "\\]", display: true}
    ]
  };
  renderMathInElement(document.body, options);

  function replaceEscapedDollars() {
    const allElements = document.body.getElementsByTagName('p');

    for (let i = 0; i < allElements.length; i++) {
      const element = allElements[i];
      // Check if element has text content
      if (element.textContent) {
        element.textContent = element.textContent.replace(/\\\$|\$/g, '$');
      }
    }
  }
  replaceEscapedDollars();
</script>

I guess that Documenter.jl does this automatically so that's why it's only required with output that is parsed by Franklin.

@rikhuijzer
Copy link
Owner Author

It would probably be more reliable to convert dollars to double backticks:

``x = 1``

and then let KaTeX process that. For now the current approach is good enough.

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

Successfully merging this pull request may close these issues.

None yet

1 participant