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

Add MathJax3 Writer #1362

Closed
simeonschaub opened this issue Jul 11, 2020 · 2 comments · Fixed by #1367
Closed

Add MathJax3 Writer #1362

simeonschaub opened this issue Jul 11, 2020 · 2 comments · Fixed by #1367
Labels
Format: HTML Related to the default HTML output Type: Enhancement

Comments

@simeonschaub
Copy link
Contributor

It would be good to support MathJax 3 for LaTeX rendering as well. My main motivation behind this is that MathJax 3 officially supports the physics package as a plugin. From quick testing, it also seems to render a lot faster than MathJax 2 and really not much slower than KaTeX. It's probably better to add alongside MathJax 2, since the config formats are not compatible, so this would otherwise be breaking. I'd like to take a stab at this, if that's ok.

@mortenpi
Copy link
Member

Yes, this would be good. Going forward, MathJax 3 should probably be the default MathJax version anyway. But we should give people the option to also keep using MathJax 2.

From the API perspective we have two options I guess:

  • Make it possible to pass a version number to MathJax and then check for that in mathengine!.
  • Create a new type, e.g. MathJax3. In this case, we could also deprecate MathJax in favor of MathJax2.

I think either should be a pretty straightforward addition to here:

"Provides a namespace for remote dependencies."
module RD
using JSON
using ....Utilities.JSDependencies: RemoteLibrary, Snippet, RequireJS, jsescape, json_jsescape
using ..HTMLWriter: KaTeX, MathJax
const requirejs_cdn = "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
const google_fonts = "https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"
const fontawesome_version = "5.11.2"
const fontawesome_css = [
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/$(fontawesome_version)/css/fontawesome.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/$(fontawesome_version)/css/solid.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/$(fontawesome_version)/css/brands.min.css",
]
const jquery = RemoteLibrary("jquery", "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js")
const jqueryui = RemoteLibrary("jqueryui", "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js")
const lunr = RemoteLibrary("lunr", "https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.6/lunr.min.js")
const lodash = RemoteLibrary("lodash", "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js")
# headroom
const headroom_version = "0.10.3"
const headroom = RemoteLibrary("headroom", "https://cdnjs.cloudflare.com/ajax/libs/headroom/$(headroom_version)/headroom.min.js")
const headroom_jquery = RemoteLibrary(
"headroom-jquery",
"https://cdnjs.cloudflare.com/ajax/libs/headroom/$(headroom_version)/jQuery.headroom.min.js",
deps = ["jquery", "headroom"],
)
# highlight.js
"Add the highlight.js dependencies and snippet to a [`RequireJS`](@ref) declaration."
function highlightjs!(r::RequireJS, languages = String[])
# NOTE: the CSS themes for hightlightjs are compiled into the Documenter CSS
# When updating this dependency, it is also necessary to update the the CSS
# files the CSS files in assets/html/scss/highlightjs
hljs_version = "9.15.10"
push!(r, RemoteLibrary(
"highlight",
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/$(hljs_version)/highlight.min.js"
))
prepend!(languages, ["julia", "julia-repl"])
for language in languages
language = jsescape(language)
push!(r, RemoteLibrary(
"highlight-$(language)",
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/$(hljs_version)/languages/$(language).min.js",
deps = ["highlight"]
))
end
push!(r, Snippet(
vcat(["jquery", "highlight"], ["highlight-$(jsescape(language))" for language in languages]),
["\$", "hljs"],
raw"""
$(document).ready(function() {
hljs.initHighlighting();
})
"""
))
end
# MathJax & KaTeX
const katex_version = "0.11.1"
const katex_css = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/$(katex_version)/katex.min.css"
function mathengine!(r::RequireJS, engine::KaTeX)
push!(r, RemoteLibrary(
"katex",
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/$(katex_version)/katex.min.js"
))
push!(r, RemoteLibrary(
"katex-auto-render",
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/$(katex_version)/contrib/auto-render.min.js",
deps = ["katex"],
))
push!(r, Snippet(
["jquery", "katex", "katex-auto-render"],
["\$", "katex", "renderMathInElement"],
"""
\$(document).ready(function() {
renderMathInElement(
document.body,
$(json_jsescape(engine.config, 2))
);
})
"""
))
end
function mathengine!(r::RequireJS, engine::MathJax)
push!(r, RemoteLibrary(
"mathjax",
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML",
exports = "MathJax"
))
push!(r, Snippet(["mathjax"], ["MathJax"],
"""
MathJax.Hub.Config($(json_jsescape(engine.config, 2)));
"""
))
end
mathengine(::RequireJS, ::Nothing) = nothing
end

@simeonschaub
Copy link
Contributor Author

I think since MathJax3 uses a completely different config format, I though option 2 made more sense. I would love to hear your initial feedback on my draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Format: HTML Related to the default HTML output Type: Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants