Skip to content

Instantly share code, notes, and snippets.

@CedricLeong
Last active December 16, 2015 05:08
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 CedricLeong/5381804 to your computer and use it in GitHub Desktop.
Save CedricLeong/5381804 to your computer and use it in GitHub Desktop.
HTML:
// Input
<span id="editable-math" class="mathquill-editable" ></span></p>
//Latex Code not shown to user
<p><textarea id="latex-source" style="display:none;"></textarea></p>
// Button to convert input to image
<p><button id="codecogs">Render LaTeX as an image with Code Cogs</button> <a id="codecogslink"><img id="codecogsimg" alt="LaTeX rendered as an image"> </a></p>
-----------------------------------------------------------------------------------------------------------------------
Javascript:
$('#show-html-source').toggle(function() {
$(this).html('Hide Semantically Meaningful HTML Source').parent().next().show();
}, function() {
$(this).html('Show Semantically Meaningful HTML Source').parent().next().hide();
});
var latexMath = $('#editable-math'), latexSource = $('#latex-source'), htmlSource = $('#html-source'), codecogsimg = $('#codecogsimg'), codecogslink = $('#codecogslink');
$('#codecogs').click(function() {
var latex = latexSource.val();
codecogsimg.attr('src','http://latex.codecogs.com/gif.latex?'+latex);
h});
$(function() {
latexMath.bind('keydown keypress', function() {
setTimeout(function() {
var latex = latexMath.mathquill('latex');
latexSource.val(latex);
// location.hash = '#'+latex; //extremely performance-crippling in Chrome for some reason
htmlSource.text(printTree(latexMath.mathquill('html')));
});
}).keydown().focus();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment