emad-elsaid / xlog

💥 Personal knowledge management application. One binary HTTP server. works in any Markdown directory. autolinks pages, hashtags, auto preview images link, screenshare, screenshot, camera recording and audio recording embedded in the note. and fast search through the KB
https://xlog.emadelsaid.com
MIT License
154 stars 15 forks source link

fix mathjax extension #54

Closed juanolon closed 4 months ago

juanolon commented 5 months ago

This changes load mathjax on the page only once. Also, it adds missing fonts, which doesn't allow to render math correctly

emad-elsaid commented 5 months ago

Thanks, How can I verify the files you added to public/js directory? I need to make sure they match the source

juanolon commented 5 months ago

Hey, i got them from the official compiled repository from mathjax: https://github.com/mathjax/MathJax/tree/master, from the folder /es5/output

emad-elsaid commented 5 months ago

I verified the files are accurate. and tried to build a project with this branch and found the embedded filesystem is not exported on build.

We'll need to explicitly Regiser every file to be exported.

emad-elsaid commented 5 months ago

Can you show me a screenshot of your page without the fonts? because on my machine it load the fonts, maybe I have them on my system already and this is why I didn't see the issue

juanolon commented 5 months ago

image

and this are with the fixes: image

I can see the wrong rendering also on the xlog website (https://xlog.emadelsaid.com/Features%20Test/) image

Also, i get a lot of erros on the web-console, which are gone with the fixes image

one of the errors is about the fonts not existing: https://xlog.emadelsaid.com/js/output/chtml/fonts/woff-v2/MathJax_Zero.woff (which is a 404)

emad-elsaid commented 4 months ago

The only way i found to add the script only if mathjax syntax is used is to append the script as I did before. That comes with the cost of including it multiple times. but not loading the script multiple times.

juanolon commented 4 months ago

mh what about having a flag on the page, to see if mathjax is required? like

window.mathjax_loaded = false;
function require_mathjax() {
  if !mathjax_loaded {
    ... add <script src... to DOM
  }
}

and at the end of each mathjax object, we can call require_mathjax(). This way, the script is loaded only once (similar to this: https://docs.mathjax.org/en/latest/web/configuration.html#configuring-and-loading-in-one-script). The function require_mathjax will be present on each page, but i think that should be not much of a problem.