Skip to content

Instantly share code, notes, and snippets.

@angelsl
Last active September 17, 2016 15:38
Show Gist options
  • Save angelsl/227e4e22ea8b4f972d692de39fa4d1a1 to your computer and use it in GitHub Desktop.
Save angelsl/227e4e22ea8b4f972d692de39fa4d1a1 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>MathJax Sandbox</title>
<style>
body { font-family: "Open Sans", sans-serif; }
hr { margin: 2em auto; }
textarea { width: 100%; height: 10em; }
div.link-container { display: none; margin-top: 3em; font-size: 70%; }
</style>
<link href="//fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<script src="//cdn.jsdelivr.net/jquery/latest/jquery.slim.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config
(
{
"tex2jax":
{
"inlineMath": [ [ '$', '$' ] ]
}
}
);
</script>
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript">
function Render()
{
var MathJaxContent = $("textarea").val();
$("#math-container").html(MathJaxContent.replace(/\n/g, "<br>"));
MathJax.Hub.Queue([ "Typeset", MathJax.Hub, "math-container" ]);
if (MathJaxContent) $("div.link-container").show();
else $("div.link-container").hide();
var Encoded = encodeURIComponent(btoa(MathJaxContent));
$("input.link").val(window.location.origin + window.location.pathname + "#" + Encoded);
window.location.hash = Encoded;
}
function Initialize()
{
$("button").click(Render);
$(document).keyup
(
function(E)
{
// Render upon Ctrl + Enter.
if (E.keyCode == 13 && E.ctrlKey)
Render();
}
);
$("input.link").click(function() { $(this).select(); });
var Data = decodeURIComponent(window.location.hash.slice(1));
try { Data = atob(Data); }
catch (E) { Data = null; }
if (Data) $("textarea").val(Data);
Render();
}
$(Initialize);
</script>
</head>
<body>
<div>MathJax:</div>
<textarea></textarea>
<button>Render</button> (or press <code>Ctrl + Enter</code>)
<hr>
<div id="math-container"></div>
<div class="link-container">
<span>link to this MathJax snippet:</span>
<input class="link">
</div>
<div style="font-size: 70%"><a href="https://github.com/jbergknoff/mathjax-sandbox">Source on GitHub</a></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment