-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
MathJax 3.x compatibility issue #2559
Comments
MathJax 3 support would be nice, but it would require almost a complete rewrite of https://github.com/hakimel/reveal.js/blob/master/plugin/math/math.js (based on your comment I hoped there would be an easy workaround, but unfortunately not 😞) Trying to use Mathjax 3 (also with the
error, which means that most of the plugin is not working (i.e. none of the options are applied and the reveal event listener is not added). Additionally, v3 doesn't use queues so that part needs to be rewritten as well. EDIT: rewrote the plugin, will prepare a pull request, but I'll also paste it below tomorrow |
Instead of overwriting the current plugin, I made a new one, because at the moment there are still some issues with MathJax 3 (I encountered newlines not working and under/over braces not working), so if you want to change back to MathJax 2 just enable the other plugin again. Save the following as /**
* A plugin which enables rendering of math equations inside
* of reveal.js slides. Essentially a thin wrapper for MathJax 3
*
* @author Hakim El Hattab
* @author Gerhard Burger
*/
var RevealMath3 = window.RevealMath3 || (function(){
var options = Reveal.getConfig().math3 || {};
var mathjax = options.mathjax || 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';
var url = mathjax;
var defaultOptions = {
tex: {
inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ]
},
options: {
skipHtmlTags: [ 'script', 'noscript', 'style', 'textarea', 'pre' ]
},
startup: {
ready: () => {
MathJax.startup.defaultReady();
MathJax.startup.promise.then(() => {
Reveal.layout();
});
}
}
};
function defaults( options, defaultOptions ) {
for ( var i in defaultOptions ) {
if ( !options.hasOwnProperty( i ) ) {
options[i] = defaultOptions[i];
}
}
}
function loadScript( url, callback ) {
var script = document.createElement( 'script' );
script.type = "text/javascript"
script.id = "MathJax-script"
script.src = url;
script.async = true
// Wrapper for callback to make sure it only fires once
var finish = function() {
if( typeof callback === 'function' ) {
callback.call();
callback = null;
}
}
script.onload = finish;
document.head.appendChild( script );
}
return {
init: function() {
defaults( options, defaultOptions );
defaults( options.tex, defaultOptions.tex );
defaults( options.options, defaultOptions.options);
defaults( options.startup, defaultOptions.startup );
options.mathjax = null;
window.MathJax = options;
loadScript( url, function() {
// Reprocess equations in slides when they turn visible
Reveal.addEventListener( 'slidechanged', function( event ) {
MathJax.typeset();
} );
} );
}
}
})();
Reveal.registerPlugin( 'math3', RevealMath3 ); |
Cheers, Martin
Am 16. Mai 2020 10:31:58 MESZ schrieb Gerhard Burger <[email protected]>:
…Instead of overwriting the current plugin, I made a new one, because at
the moment there are still some issues with MathJax 3 (I encountered
[newlines not working](mathjax/MathJax#2312)
and [under/over braces not
working](mathjax/MathJax#2402)), so if you
want to change back to MathJax 2 just enable the other plugin again.
Save the following as `plugins/math3/math3.js`, then change your
`index.html` to load this plugin. You need `math3` in your options to
customize it.
```js
/**
* A plugin which enables rendering of math equations inside
* of reveal.js slides. Essentially a thin wrapper for MathJax 3
*
* @author Hakim El Hattab
* @author Gerhard Burger
*/
var RevealMath3 = window.RevealMath3 || (function(){
var options = Reveal.getConfig().math3 || {};
var mathjax = options.mathjax ||
***@***.***/es5/tex-svg.js';
var url = mathjax;
var defaultOptions = {
tex: {
inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ]
},
options: {
skipHtmlTags: [ 'script', 'noscript', 'style', 'textarea', 'pre' ]
},
startup: {
ready: () => {
MathJax.startup.defaultReady();
MathJax.startup.promise.then(() => {
Reveal.layout();
});
}
}
};
function defaults( options, defaultOptions ) {
for ( var i in defaultOptions ) {
if ( !options.hasOwnProperty( i ) ) {
options[i] = defaultOptions[i];
}
}
}
function loadScript( url, callback ) {
var script = document.createElement( 'script' );
script.type = "text/javascript"
script.id = "MathJax-script"
script.src = url;
script.async = true
// Wrapper for callback to make sure it only fires once
var finish = function() {
if( typeof callback === 'function' ) {
callback.call();
callback = null;
}
}
script.onload = finish;
document.head.appendChild( script );
}
return {
init: function() {
defaults( options, defaultOptions );
defaults( options.tex, defaultOptions.tex );
defaults( options.options, defaultOptions.options);
defaults( options.startup, defaultOptions.startup );
options.mathjax = null;
window.MathJax = options;
loadScript( url, function() {
// Reprocess equations in slides when they turn visible
Reveal.addEventListener( 'slidechanged', function( event ) {
MathJax.typeset();
} );
} );
}
}
})();
Reveal.registerPlugin( 'math3', RevealMath3 );
```
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2559 (comment)
--
Earth is flat, pigs can fly and nuclear power is efas
|
@hakimel I was planning to prepare a pull request, but I see that you want plugins in a separate repository. Is it ok if I create a separate repository for this or do you want to update the math plugin in this repository? From https://docs.mathjax.org/en/latest/upgrading/v2.html:
and
So it might be smart to keep the plugins separate for a while? |
I think it's best to create a new plugin in a separate repo. Thanks for asking. On a related note I've been considering switching the math plugin over to KaTeX instead. From a developer point of view, I've found that easier to work with (we use it in slides.com). Mostly an FYI but if anyone has input I'm all ears :) |
Thanks for your quick reply, will create a separate repo then. |
@hakimel Experimented a bit with KaTeX and it's quite easy to get it to work and quite fast indeed, thanks for the tip! So I was thinking: is it maybe an idea to create a |
Still thinking about the best way to go about this. Maintaining three separate plugins seems like extra work. If KaTeX has the features people need, then I'd rather just switch to a single 'math' plugin powered by KaTeX. The existing KaTeX plugin hasn't been updated in a while but maybe we can use that as a starting point: https://github.com/j13z/reveal.js-math-katex-plugin/ |
Yes, I see your point... Maybe I'll dump the MathJax 3 plugin code somewhere "as-is". EDIT: outdated code removed, see pull request below |
Thanks for sharing @burgerga! I've added switching to KaTeX to the v4.1 todo-list so it's super helpful to see an implementation of it. |
No problem, also seems to work fine for 4.0.0 (after I adapted it to the
new plugin infrastructure), I can prepare a pull request against the dev
branch if you want... Very nice work on 4.0.0 by the way!
…On Wed, May 20, 2020, 19:34 Hakim El Hattab ***@***.***> wrote:
Thanks for sharing @burgerga <https://github.com/burgerga>!
I've added switching to KaTeX to the v4.1 todo-list so it's super helpful
to see an implementation of it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2559 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG5QYVBHRZVYRP5OHU3T6LRSQIBRANCNFSM4KCWVFXA>
.
|
Yes please, I'd love a pull request that replaces the existing math plugin with your KaTeX version. Once that's in, I'll move the old math plugin to a separate repo so that remains available for people who want to keep using MatJax 2. |
Just to leave my two cents here. I'm currently using the Academic theme for Hugo, which uses Academic uses MathJax v3 with a feature that allows me to use some commands only available through extensions (such as I noticed that the I don't know if KaTeX has something similar (never used it myself) but I'd be willing to have that feature. Thanks in advance! |
I forgot to mention |
I don't have any experience with Hugo, but mhchem might be a bit harder to get to work with the Reveal math (katex) plugin since it needs te be loaded after |
@rodrigoalcarazdelaosa Just updated the pull request, the plugin now allows easy enabling of mhchem! |
For the newbies among us, can anyone explain how can I use MathJax 3 with Reveal.js? Maybe a short standalone demo? |
@xenomarz You can specify options using
Other options (see http://docs.mathjax.org/en/latest/options/index.html) can also be specified, currently only
is used by default. |
KaTeX developer here, finally taking a look at reveal.js for an upcoming presentation (great stuff!). Let me know if I can help with KaTeX integration. @rodrigoalcarazdelaosa KaTeX supports |
Any updates on this? |
If you'd like an example of how to use KaTeX with RevealJS (which is very easy, no plugin required), see this template or one of these examples using it: example, example. I think it would be nicer to include direct support for KaTeX in the RevealMath plugin, or perhaps a separate plugin. This would enable rendering math only slide by slide like with MathJax, which could be a bit faster for decks with many many slides. Oh, I just saw that PR #2677 is one approach to this. If there's more work to be done, I'm willing to help. @burgerga Maybe you want to turn https://github.com/burgerga/reveal.js/tree/feat_mathjax3 into a PR as well? I agree that offering both MathJax and KaTeX as options would be nice; I'm just not sure whether it should be one plugin or two (or three if we want legacy MathJax v2 support). |
@edemaine Since that PR is about 1.5 years old I pulled the trigger and created https://github.com/burgerga/reveal.js-math. |
@burgerga I really like how you set up reveal.js-math to offer all three options. Would you mind if I copy that into reveal.js core and replace the current math plugin? If so I will also alias |
@hakimel Thanks, and yes go ahead! I think that would be convenient for many people :) |
Thanks @burgerga! This has been added now. I made the API fully backwards compatible so all existing presentations can continue to initialize with: Reveal.initialize({
math: {
config: 'TeX-AMS_HTML-full'
},
plugins: [ RevealMath ]
}); Beyond that everything works as described in the README here: https://github.com/burgerga/reveal.js-math This needs to be added to the revealjs.com/math docs as well but other than that it should be good to go. |
No problem, when you add the docs could you make it a co-authored commit, then I can share in the glory of being a reveal contributor :) When the docs are done, I will delete reveal.js-math, so it doesn't linger around and cause confusion. |
I wasn't aware co-authored commits were a thing, sorry! I only tagged your username in the commit message for the changes I copied over. I'm guessing there's no way to amend that now? Will make sure to add you as a co-author for the docs update. |
Probably not possible to amend, but that's fine, no need to worry :) |
The docs have been updated: https://618b8dc985f599ad10a72ac4--revealjs.netlify.app/math/. This is only available in a branch so far but will go live with reveal.js 4.2.0. The co-authored commit is here: reveal/revealjs.com@be3046e |
Awesome, and thanks! I have already archived the reveal.js-math repo, and put a message in the description that this is now part of reveal |
@api docker Engine |
Docker phiên bản 1.4 |
DSL và Gem |
Dockly (giảm khó khăn đóng gói ứng dụng) |
Định dạng:test_Docker làm # mã ở dãy cuối |
Docker:test_docker lam kho ‘an-awesome-name’cuối |
MathJax 2.x uses URL configuration parameters e.g.:
In current 3.x this dispatch mechanism has been superseeded using e.g.:
MathJax.js
is no longer present in 3.x. This works using the reveal MathJax plugin e.g.:However using »Inspect« Chromium shows the following JavaScript error:
Omitting
config: 'x'
completely does not help either.Technically it's a mere nuisance. But if you are chasing for errors this one is confusing. Making »config« an option rather than a mandatory property would help.
The text was updated successfully, but these errors were encountered: