SaswatPadhi / pseudocode.js

Beautiful pseudocode for the Web
https://saswatpadhi.github.io/pseudocode.js
MIT License
221 stars 33 forks source link

Support MathJax #12

Closed AtomicVar closed 4 years ago

AtomicVar commented 5 years ago

By default, the code tries to use KaTeX. If it is not available, it switches to MathJax.

I tested the code and used it in my blog:

image

image

SaswatPadhi commented 4 years ago

Any update on this? I would like to use this too, if MathJax is supported :)

Note that this PR uses the old MathJax 2.x. MathJax 3.0 is now stable; see what's new in 3.0.

tatetian commented 4 years ago

Hi guys. I am sorry that I don't have time to maintain this project. If anyone is interested in maintaining this project, I can transfer its ownership.

SaswatPadhi commented 4 years ago

Hi @tatetian,

I like this project and can help maintain it. I use MathJax regularly and an algorithm package for it, such as this one, is very useful.

Thanks!

tatetian commented 4 years ago

Hi @SaswatPadhi ,

Cool. I am glad that people find this project useful and volunteer to keep developing it. So I will transfer this project under your name. Sounds good?

SaswatPadhi commented 4 years ago

Sure, sounds good. Thanks.

tatetian commented 4 years ago

Sure, sounds good. Thanks.

I tried to transfer the project to you. But Github reported an error: "SaswatPadhi/pseudocode.js already exists". Could you remove or rename your fork first?

SaswatPadhi commented 4 years ago

Oh sorry, right, just removed my fork. I can push my local changes to a new branch once you transfer ownership.

Thanks.

tatetian commented 4 years ago

Done. Good luck

SaswatPadhi commented 4 years ago

Thank you!

leovan commented 4 years ago

Hi @SaswatPadhi , I changed to MathJax v3 recently, it got much faster rendering than before. Is there any plan to support MathJax v3?

leovan commented 4 years ago

Also, I found an easy way but may not a best way to support MathJax v3:

// MathJax
else {
    this._html.putSpan('<span>$' + text + '$</span>');
}

I'm not sure the old API MathJax.HTML.Element("span", null, ["$" + text + "$"]).outerHTML will do something with text or not.

SaswatPadhi commented 4 years ago

Hi @leovan,

I am definitely pushing MathJax v3 support within the next few days. I am currently traveling, so didn't have much time to test things locally before pushing. But I will push my changes to this branch directly -- I am building on the MathJax v2 changes proposed by @ZJUGuoShuai.

Also, yes this._html.putSpan('<span>$' + text + '$</span>') is similar to this._html.putSpan(MathJax.HTML.Element("span", null, ["$" + text + "$"]).outerHTML); but notice that the former is creating a raw HTML span element whereas the latter is creating a span with the appropriate content using the MathJax API and then grabbing its outerHTML, i.e. the final serialized HTML code.

As you noticed, the key difference is in how the text is processed. If, for whatever reason, MathJax APIs modify the text before emitting the outerHTML, your approach would miss it, and might break MathJax rendering.

leovan commented 4 years ago

Great, thx @SaswatPadhi

leovan commented 4 years ago

Hi, @SaswatPadhi , I pull the latest code, but make on macOS results the following error:

pseudocode.js src/Lexer.js src/ParseError.js src/Parser.js src/Renderer.js src/utils.js
make[1]: pseudocode.js: No such file or directory
make[1]: *** [lint] Error 1
make: *** [build/pseudocode.js] Error 2

I do find the pseudocode.js in the root directory, so I don't know what's wrong with it.

SaswatPadhi commented 4 years ago

I think you might have deleted the build directory accidentally. I just tried removing that directory, and I get the same error.

Try creating it and then running make again.