Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Forked from mauriciopoppe/_README.md
Created January 18, 2020 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosdelfino/b55056452443f2e50242cf3a7d235d72 to your computer and use it in GitHub Desktop.
Save carlosdelfino/b55056452443f2e50242cf3a7d235d72 to your computer and use it in GitHub Desktop.
MathJax numbered equation preview on Jekyll

MathJax numbered equation preview

No need to click on an a tag to see the equation, just hover on any <a> tag created using \eqref{label} and that's it!

Contents:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
messageStyle: 'none',
tex2jax: {
inlineMath: [['$','$']],
displayMath: [['$$','$$']],
processEnvironments: false
},
// show equation numbers
TeX: {
equationNumbers: {
autoNumber: "AMS"
}
},
'HTML-CSS': {
imageFont: null
}
});
</script>
.mathjax-tooltip {
display: none;
width: 100%;
position: absolute;
}
/*
* MathJax eqn preview for a tags
*
* Copyright (c) 2015 Mauricio Poppe
* Licensed under the MIT license.
*/
(function () {
var $container = $(document.body);
var $tooltip = $('<div />').addClass('mathjax-tooltip');
$container.append($tooltip);
function onMouseOver(ev) {
var a = ev.currentTarget;
var $number = $(a.hash);
var $root = $number.closest('.MathJax_Display');
var bounds = $(a).offset();
var containerBounds = $container.offset();
$tooltip.stop(true, true);
$tooltip.append($root.clone());
$tooltip.css({
top: bounds.top - containerBounds.top - $tooltip.height() - 5,
left: -1
});
$tooltip.fadeIn();
}
function onMouseOut(a) {
$tooltip.stop(true, true);
$tooltip.fadeOut(function () {
$tooltip.empty();
});
}
MathJax.Hub.Queue(function () {
$container.on('mouseover', 'a[href*="mjx-eqn-"]', onMouseOver);
$container.on('mouseout', 'a[href*="mjx-eqn-"]', onMouseOut);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment