From 00ee7b56445f216cc6e8b5129ca0555bac04f8f9 Mon Sep 17 00:00:00 2001 From: Tom Carter Date: Wed, 11 Jun 2014 17:56:13 -0500 Subject: [PATCH] Added preview logic using MathJax. Changed LaTeX output environment from tabular to array. --- converter.js | 19 ++++++++++++++----- index.html | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/converter.js b/converter.js index 72d9da5..7a05a17 100644 --- a/converter.js +++ b/converter.js @@ -8,6 +8,9 @@ var latexOutput = {}; var excelParser = { + //latexEnvironment: 'tabular', + latexEnvironment: 'array', + latexEscape: function(text) { var escapeRegExpr = function(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); @@ -44,7 +47,7 @@ args[i] = 'l'; } 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++) { var cols = table[i]; // TODO: replace "&" with "\&" @@ -59,7 +62,7 @@ latex += " \\\\ \\hline\n"; } - latex += "\\end{tabular}\n"; + latex += "\\end{" + excelParser.latexEnvironment + "}\n"; return latex; }, @@ -130,13 +133,20 @@ // I apologize for the hack :( 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) { // prevent default browser behavior event.stopPropagation(); @@ -202,8 +212,7 @@ // when a new workbook is selected, do stuff! $('#workbook').change(function(event) { var select = $(event.target); - var output = latexOutput[select.val()]; - $('#latex-output').val(output); + excelParser.showOutput(select.val()); }); } }; diff --git a/index.html b/index.html index b9c54df..69ce3ac 100644 --- a/index.html +++ b/index.html @@ -34,8 +34,11 @@

Formatting from the Excel document won't be preserved, only the text will be extracted.

Lovingly hacked together by Eric Wood

+

Preview

+
$$ \LaTeX $$
+