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}
|
||||
\\thispagestyle{empty}
|
||||
\\begin{document}
|
||||
\\begin{align*}
|
||||
${equation}
|
||||
\\end{align*}
|
||||
\\end{document}`;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,8 @@
|
||||
<meta charset="utf-8">
|
||||
<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="author" content="Joseph Rautenbach">
|
||||
<!-- 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">
|
||||
<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>
|
||||
@ -27,39 +26,58 @@
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" id="latexInputTextArea" placeholder="Enter LaTeX math equation" rows="5"></textarea>
|
||||
</div>
|
||||
<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>
|
||||
<form>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" id="latexInputTextArea" placeholder="Enter LaTeX math equation" rows="5"></textarea>
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<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 class="form-row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label for="outputFormatSelect">Image format</label>
|
||||
<select class="form-control" id="outputFormatSelect">
|
||||
<option selected>PNG</option>
|
||||
<option>JPG</option>
|
||||
<option>SVG</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<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 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>
|
||||
<input type='submit' class="btn btn-primary" id="convertButton" value="Convert">
|
||||
|
||||
<input type='submit' class="btn btn-info" id="exampleButton" value="Show Example">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
@ -68,7 +86,7 @@
|
||||
<div class="card-body">
|
||||
<img id="resultImage" />
|
||||
<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 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 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();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user