Added checkbox option for wrapping with align, and a spinner indicator
This commit is contained in:
parent
cdbe20ea57
commit
53ad55c443
2
app.js
2
app.js
@ -142,9 +142,7 @@ function getLatexTemplate(equation) {
|
|||||||
\\usepackage[utf8]{inputenc}
|
\\usepackage[utf8]{inputenc}
|
||||||
\\thispagestyle{empty}
|
\\thispagestyle{empty}
|
||||||
\\begin{document}
|
\\begin{document}
|
||||||
\\begin{align*}
|
|
||||||
${equation}
|
${equation}
|
||||||
\\end{align*}
|
|
||||||
\\end{document}`;
|
\\end{document}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<meta name="description" content="Convert LaTeX math equations to PNG/JPG/SVG images, with transparent backgrounds and perfect LaTeX rendering">
|
<meta name="description" content="Convert LaTeX math equations to PNG/JPG/SVG images, with transparent backgrounds and perfect LaTeX rendering">
|
||||||
<meta name="author" content="Joseph Rautenbach">
|
|
||||||
<!-- Bootstrap CSS -->
|
<!-- Bootstrap CSS -->
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
||||||
<link rel="stylesheet" href="custom.css">
|
<link rel="stylesheet" href="custom.css">
|
||||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
|
||||||
<script src="latex2image-client.js"></script>
|
<script src="latex2image-client.js"></script>
|
||||||
@ -27,39 +26,58 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<form>
|
||||||
<div class="form-group">
|
<div class="card-body">
|
||||||
<textarea class="form-control" id="latexInputTextArea" placeholder="Enter LaTeX math equation" rows="5"></textarea>
|
<div class="form-group">
|
||||||
</div>
|
<textarea class="form-control" id="latexInputTextArea" placeholder="Enter LaTeX math equation" rows="5"></textarea>
|
||||||
<div class="form-row">
|
|
||||||
<div class="form-group col-sm-6">
|
|
||||||
<label for="outputFormatSelect">Image format</label>
|
|
||||||
<select class="form-control" id="outputFormatSelect">
|
|
||||||
<option selected>PNG</option>
|
|
||||||
<option>SVG</option>
|
|
||||||
<option>JPG</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-row">
|
||||||
<label for="outputScaleSelect">Scale</label>
|
<div class="col-sm-6">
|
||||||
<select class="form-control" id="outputScaleSelect">
|
<div class="form-group">
|
||||||
<option>10%</option>
|
<label for="outputFormatSelect">Image format</label>
|
||||||
<option>25%</option>
|
<select class="form-control" id="outputFormatSelect">
|
||||||
<option>50%</option>
|
<option selected>PNG</option>
|
||||||
<option>75%</option>
|
<option>JPG</option>
|
||||||
<option>100%</option>
|
<option>SVG</option>
|
||||||
<option selected>125%</option>
|
</select>
|
||||||
<option>150%</option>
|
</div>
|
||||||
<option>200%</option>
|
</div>
|
||||||
<option>500%</option>
|
<div class="col-sm-6">
|
||||||
<option>1000%</option>
|
<div class="form-group">
|
||||||
</select>
|
<label for="outputScaleSelect">Scale</label>
|
||||||
|
<select class="form-control" id="outputScaleSelect">
|
||||||
|
<option>10%</option>
|
||||||
|
<option>25%</option>
|
||||||
|
<option>50%</option>
|
||||||
|
<option>75%</option>
|
||||||
|
<option>100%</option>
|
||||||
|
<option selected>125%</option>
|
||||||
|
<option>150%</option>
|
||||||
|
<option>200%</option>
|
||||||
|
<option>500%</option>
|
||||||
|
<option>1000%</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="autoAlignCheckbox" checked>
|
||||||
|
<label class="form-check-label" for="autoAlignCheckbox">
|
||||||
|
Wrap input with <code>\begin{align*}</code> and <code>\end{align*}</code> automatically
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary" type="button" id="convertButton">
|
||||||
|
<span class="spinner-grow spinner-grow-sm d-none" role="status" aria-hidden="true" id="convertSpinner"></span>
|
||||||
|
<span id="convertButtonText">Convert</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="btn btn-info" type="button" id="exampleButton">
|
||||||
|
Show Example
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<input type='submit' class="btn btn-primary" id="convertButton" value="Convert">
|
</form>
|
||||||
|
|
||||||
<input type='submit' class="btn btn-info" id="exampleButton" value="Show Example">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
@ -68,7 +86,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<img id="resultImage" />
|
<img id="resultImage" />
|
||||||
<br><br>
|
<br><br>
|
||||||
<a href="#" class="btn btn-primary" role="button" id="downloadButton" download>Save Image</a>
|
<a href="#" class="btn btn-primary" role="button" id="downloadButton" target="_blank" download>Save Image</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-danger initiallyHidden" id="errorAlert"></div>
|
<div class="alert alert-danger initiallyHidden" id="errorAlert"></div>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
var sampleEquation = '\\frac{\\pi}{2} = \\int_{-1}^{1} \\sqrt{1-x^2}\\ dx';
|
var sampleEquation = '\\frac{\\pi}{2} = \\int_{-1}^{1} \\sqrt{1-x^2}\\ dx';
|
||||||
var hasShownBefore = false;
|
var hasShownBefore = false;
|
||||||
|
|
||||||
|
var ENDPOINT = '/convert';
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
function show(resultData) {
|
function show(resultData) {
|
||||||
function afterSlideUp() {
|
function afterSlideUp() {
|
||||||
@ -30,38 +32,45 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#convertButton').click(function() {
|
$('#convertButton').click(function() {
|
||||||
if (!$('#latexInputTextArea').val()) {
|
var latexInput = $('#latexInputTextArea').val();
|
||||||
show(JSON.stringify({
|
|
||||||
error: 'No LaTeX input provided'
|
if (!latexInput) {
|
||||||
}));
|
show({ error: 'No LaTeX input provided.' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($('#autoAlignCheckbox').prop('checked')) {
|
||||||
|
latexInput = '\\begin{align*}\n' + latexInput + '\\end{align*}\n';
|
||||||
|
}
|
||||||
|
|
||||||
$('#result').slideUp(hasShownBefore ? 330 : 0, function() {
|
$('#result').slideUp(hasShownBefore ? 330 : 0, function() {
|
||||||
$('#resultImage').attr('src', '');
|
$('#resultImage').attr('src', '');
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#convertButton').prop('disabled', true);
|
$('#convertButton').prop('disabled', true);
|
||||||
$('#exampleButton').prop('disabled', true);
|
$('#exampleButton').prop('disabled', true);
|
||||||
$('#convertButton').prop('value', 'Converting...');
|
$('#convertButtonText').html('Converting...');
|
||||||
|
$('#convertSpinner').removeClass('d-none');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/convert',
|
url: ENDPOINT,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
latexInput: $('#latexInputTextArea').val(),
|
latexInput: latexInput,
|
||||||
outputFormat: $('#outputFormatSelect').val(),
|
outputFormat: $('#outputFormatSelect').val(),
|
||||||
outputScale: $('#outputScaleSelect').val()
|
outputScale: $('#outputScaleSelect').val()
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#convertButton').prop('disabled', false);
|
$('#convertButton').prop('disabled', false);
|
||||||
$('#exampleButton').prop('disabled', false);
|
$('#exampleButton').prop('disabled', false);
|
||||||
$('#convertButton').prop('value', 'Convert');
|
$('#convertButtonText').html('Convert');
|
||||||
|
$('#convertSpinner').addClass('d-none');
|
||||||
show(data);
|
show(data);
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
$('#convertButton').prop('disabled', false);
|
$('#convertButton').prop('disabled', false);
|
||||||
$('#exampleButton').prop('disabled', false);
|
$('#exampleButton').prop('disabled', false);
|
||||||
$('#convertButton').prop('value', 'Convert');
|
$('#convertButtonText').html('Convert');
|
||||||
|
$('#convertSpinner').addClass('d-none');
|
||||||
alert('Error communicating with server');
|
alert('Error communicating with server');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -70,6 +79,7 @@ $(document).ready(function() {
|
|||||||
// Show and convert a sample equation
|
// Show and convert a sample equation
|
||||||
$('#exampleButton').click(function() {
|
$('#exampleButton').click(function() {
|
||||||
$('#latexInputTextArea').val(sampleEquation);
|
$('#latexInputTextArea').val(sampleEquation);
|
||||||
|
$('#autoAlignCheckbox').prop('checked', true);
|
||||||
$('#convertButton').click();
|
$('#convertButton').click();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user