diff --git a/app.js b/app.js index 32e5fd7..d146375 100644 --- a/app.js +++ b/app.js @@ -142,9 +142,7 @@ function getLatexTemplate(equation) { \\usepackage[utf8]{inputenc} \\thispagestyle{empty} \\begin{document} - \\begin{align*} ${equation} - \\end{align*} \\end{document}`; } diff --git a/static/index.html b/static/index.html index 888ba0f..b8356af 100644 --- a/static/index.html +++ b/static/index.html @@ -5,9 +5,8 @@ - - + @@ -27,39 +26,58 @@
-
-
- -
-
-
- - +
+
+
+
-
- - +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ +    +
- -    - -
+

@@ -68,7 +86,7 @@
diff --git a/static/latex2image-client.js b/static/latex2image-client.js index 2554c06..4a98b80 100644 --- a/static/latex2image-client.js +++ b/static/latex2image-client.js @@ -1,6 +1,8 @@ var sampleEquation = '\\frac{\\pi}{2} = \\int_{-1}^{1} \\sqrt{1-x^2}\\ dx'; var hasShownBefore = false; +var ENDPOINT = '/convert'; + $(document).ready(function() { function show(resultData) { function afterSlideUp() { @@ -30,38 +32,45 @@ $(document).ready(function() { } $('#convertButton').click(function() { - if (!$('#latexInputTextArea').val()) { - show(JSON.stringify({ - error: 'No LaTeX input provided' - })); + var latexInput = $('#latexInputTextArea').val(); + + if (!latexInput) { + show({ error: 'No LaTeX input provided.' }); return; } + if ($('#autoAlignCheckbox').prop('checked')) { + latexInput = '\\begin{align*}\n' + latexInput + '\\end{align*}\n'; + } + $('#result').slideUp(hasShownBefore ? 330 : 0, function() { $('#resultImage').attr('src', ''); }); $('#convertButton').prop('disabled', true); $('#exampleButton').prop('disabled', true); - $('#convertButton').prop('value', 'Converting...'); + $('#convertButtonText').html('Converting...'); + $('#convertSpinner').removeClass('d-none'); $.ajax({ - url: '/convert', + url: ENDPOINT, type: 'POST', data: { - latexInput: $('#latexInputTextArea').val(), + latexInput: latexInput, outputFormat: $('#outputFormatSelect').val(), outputScale: $('#outputScaleSelect').val() }, success: function(data) { $('#convertButton').prop('disabled', false); $('#exampleButton').prop('disabled', false); - $('#convertButton').prop('value', 'Convert'); + $('#convertButtonText').html('Convert'); + $('#convertSpinner').addClass('d-none'); show(data); }, error: function() { $('#convertButton').prop('disabled', false); $('#exampleButton').prop('disabled', false); - $('#convertButton').prop('value', 'Convert'); + $('#convertButtonText').html('Convert'); + $('#convertSpinner').addClass('d-none'); alert('Error communicating with server'); } }); @@ -70,6 +79,7 @@ $(document).ready(function() { // Show and convert a sample equation $('#exampleButton').click(function() { $('#latexInputTextArea').val(sampleEquation); + $('#autoAlignCheckbox').prop('checked', true); $('#convertButton').click(); }); });