rothsandro / eleventy-notes

A template for Eleventy to publish your personal notes or docs.
https://eleventy-notes.sandroroth.com/
140 stars 17 forks source link

MathJax support #37

Closed asterixpound closed 1 year ago

asterixpound commented 1 year ago

For me, it is important in a note-taking application to have support for mathematical equations.

I tried adding eleventy-plugin-mathjax to my clone of eleventy-notes but I get the following error:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble writing to "dist/404.html" from "../.app/pages/404.njk" (via EleventyTemplateError)
[11ty] 2. Transform `mathjax` encountered an error when transforming ../.app/pages/404.njk. (via EleventyTransformError)
[11ty] 3. Can't find handler for document (via Error)

Any idea what might be going on here?

Is there interest in adding MathJax support to eleventy-notes by default?

rothsandro commented 1 year ago

The error is caused by html attributes starting with a special char, like :aria-label and @click which are used for Alpine. These are valid attribute names but for some reason mathjax cannot parse the HTML document if such attributes are present. You can report this problem on the MathJax repo and maybe they will fix it.

As a workaround you can use the longhand syntax of Alpine by replacing :foo with x-bind:foo and @bar with x-on:bar. It works if the colon is in the middle and not at the beginning. Here is a diff.patch with the relevant changes.

At the moment I don't have any plans to add MathJax by default.

asterixpound commented 1 year ago

Thanks for your help, @rothsandro. Your patch worked for me. With eleventy-plugin-mathjax installed, equations are now rendered correctly without error.

I have also shared the issue with eleventy-plugin-mathjax at https://github.com/tsung-ju/eleventy-plugin-mathjax/issues/6.

rothsandro commented 1 year ago

Great, thanks for your feedback. I'll close this issue as MathJax should fix their parser.

synesthesia commented 1 year ago

For the benefit of other readers, an alternative is to use markdown-it-mathjax3 - I appreciate you have no plans to merge but could supply a PR if that is of use

rothsandro commented 1 year ago

@synesthesia Thanks for the recommendation, good to know for other users 👍 I don't plan to add this to the template atm.