Added preview logic using MathJax.

Changed LaTeX output environment from tabular to array.
This commit is contained in:
Tom Carter 2014-06-11 17:56:13 -05:00
parent 4dfcc2b0ed
commit 00ee7b5644
2 changed files with 17 additions and 5 deletions

View File

@ -8,6 +8,9 @@
var latexOutput = {}; var latexOutput = {};
var excelParser = { var excelParser = {
//latexEnvironment: 'tabular',
latexEnvironment: 'array',
latexEscape: function(text) { latexEscape: function(text) {
var escapeRegExpr = function(str) { var escapeRegExpr = function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
@ -44,7 +47,7 @@
args[i] = 'l'; args[i] = 'l';
} }
args = ' | ' + args.join(' | ') + ' | '; args = ' | ' + args.join(' | ') + ' | ';
var latex = "\\begin{tabular}{" + args + "}\n\\hline\n"; var latex = "\\begin{" + excelParser.latexEnvironment + "}{" + args + "}\n\\hline\n";
for(i=0; i < table.length; i++) { for(i=0; i < table.length; i++) {
var cols = table[i]; var cols = table[i];
// TODO: replace "&" with "\&" // TODO: replace "&" with "\&"
@ -59,7 +62,7 @@
latex += " \\\\ \\hline\n"; latex += " \\\\ \\hline\n";
} }
latex += "\\end{tabular}\n"; latex += "\\end{" + excelParser.latexEnvironment + "}\n";
return latex; return latex;
}, },
@ -130,13 +133,20 @@
// I apologize for the hack :( // I apologize for the hack :(
if(id === '1') { if(id === '1') {
$('#latex-output').val(latex); excelParser.showOutput(1);
} }
}); });
}); });
}); });
}, },
showOutput: function(id) {
var latex = latexOutput[id];
$('#latex-output').val(latex);
$('#preview').html('$$\n' + latex + '\n$$');
MathJax.Hub.Typeset("preview");
},
handleFiles: function(event) { handleFiles: function(event) {
// prevent default browser behavior // prevent default browser behavior
event.stopPropagation(); event.stopPropagation();
@ -202,8 +212,7 @@
// when a new workbook is selected, do stuff! // when a new workbook is selected, do stuff!
$('#workbook').change(function(event) { $('#workbook').change(function(event) {
var select = $(event.target); var select = $(event.target);
var output = latexOutput[select.val()]; excelParser.showOutput(select.val());
$('#latex-output').val(output);
}); });
} }
}; };

View File

@ -34,8 +34,11 @@
<p>Formatting from the Excel document won't be preserved, only the text will be extracted.</p> <p>Formatting from the Excel document won't be preserved, only the text will be extracted.</p>
<p>Lovingly hacked together by <a href="http://ericwood.org">Eric Wood</a></p> <p>Lovingly hacked together by <a href="http://ericwood.org">Eric Wood</a></p>
</div> </div>
<h4>Preview</h4>
<div id="preview">$$ \LaTeX $$</div>
</div> </div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="zip/zip.js"></script> <script type="text/javascript" src="zip/zip.js"></script>
<script type="text/javascript" src="converter.js"></script> <script type="text/javascript" src="converter.js"></script>
</body> </body>