Last active
December 16, 2015 05:08
-
-
Save CedricLeong/5381804 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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