obsidian-copy-as-html icon indicating copy to clipboard operation
obsidian-copy-as-html copied to clipboard

Support of Mathjax/Latex

Open Gaaruda opened this issue 2 years ago • 6 comments

The plugin you made is almost perfect but just this issue that it can parse latex properly.

What I would Like is that it converts latex to image, just like the way you are dealing with excalidraw images. there are many websites out there which deals with that is coverting latex to image.

Thanks For your Plugin. And Please support this feature, as early as possible.

Gaaruda avatar Nov 19 '22 11:11 Gaaruda

Great suggestion ! I will definitely look into this. I'd prefer to use an offline library for conversion, I'll have to do some research...

mvdkwast avatar Nov 20 '22 10:11 mvdkwast

Great suggestion ! I will definitely look into this. I'd prefer to use an offline library for conversion, I'll have to do some research...

the excalidraw in obsidian developer has also implemented the latex feature in excalidraw you may also even ask him for suggestions.

Gaaruda avatar Nov 20 '22 13:11 Gaaruda

@Gaaruda, I could not use the same approach as with Excalidraw, since the MathJax is rendered as HTML elements, not SVG. So I did my own rendering and replace the MathJax HTML nodes.

Some issues:

  • in bitmap mode, gmail and google docs don't support the vertical alignment in pixels. This may not be fixable.
  • in svg mode, it works with gmail, but the document is duplicated (gmail bug, not related to this feature)
  • quality is a bit degraded in bitmap mode (might be possible to improve this)
  • sane editors like this one render it fine.

And Please support this feature, as early as possible.

Since you're asking someone who doing this in his free time to hurry, feel free to test the above branch and provide feedback 😉

The .math-inline and .math-block can be used for styling.

mvdkwast avatar Nov 21 '22 00:11 mvdkwast

Since you're asking someone who doing this in his free time to hurry, feel free to test the above branch and provide feedback 😉

How can Test this plugin, as I am unable to see a main.js file.

Gaaruda avatar Nov 21 '22 04:11 Gaaruda

I assumed you knew how to compile a plugin since you have one in your repositories. I pushed a commit with the main.js.

mvdkwast avatar Nov 21 '22 09:11 mvdkwast

The implementation works, but adds 2MB to the plugin because it includes the entire MathJax lib and its fonts, which is kind of redundant because Obsidian should already have them.

If anyone can come up with a better implementation, I'd be glad to merge it :)

mvdkwast avatar Jan 14 '23 01:01 mvdkwast