Merge 6f49462d70e975b7e9a1f192921284ed52312061 into f077a800f9ae89ee21d2421872344c5723fabd02

This commit is contained in:
Howard O'Neil 2022-08-15 11:37:48 -07:00 committed by GitHub
commit 4615ad53b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 7 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
node_modules/
temp/
output/
output/
.env
.sh

8
app.js
View File

@ -86,6 +86,7 @@ conversionRouter.post('/convert', async (req, res) => {
await fsPromises.writeFile(`${tempDir}/${id}/equation.tex`, getLatexTemplate(equation));
// Run the LaTeX compiler and generate a .svg file
console.log(getDockerCommand(id, outputScale))
await execAsync(getDockerCommand(id, outputScale));
const inputSvgFileName = `${tempDir}/${id}/equation.svg`;
@ -163,11 +164,12 @@ function getDockerCommand(id, output_scale) {
timeout 5 dvisvgm --no-fonts --scale=${output_scale} --exact equation.dvi`;
// Start the container in the appropriate directory and run commands within it.
// Default WORKDIR in blang/latex is /data
// Files in this directory will be accessible under /data within the container.
return `
cd ${tempDir}/${id}
docker run --rm -i --user="$(id -u):$(id -g)" \
--net=none -v "$PWD":/data "blang/latex:ubuntu" \
docker run --user="$(id -u):$(id -g)" \
--net=none -v $PWD/${tempDir}/${id}:/data "blang/latex:ubuntu" \
/bin/bash -c "${containerCmds}"`;
}

View File

@ -0,0 +1,18 @@
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=latex 2018.1.22) 15 AUG 2022 16:21
entering extended mode
%&-line parsing enabled.
**equation.tex
! Emergency stop.
<*> equation.tex
Here is how much of TeX's memory you used:
2 strings out of 493030
102 string characters out of 6136260
53057 words of memory out of 5000000
3641 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
0i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s
No pages of output.

View File

@ -0,0 +1,18 @@
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=latex 2018.1.22) 15 AUG 2022 16:22
entering extended mode
%&-line parsing enabled.
**equation.tex
! Emergency stop.
<*> equation.tex
Here is how much of TeX's memory you used:
2 strings out of 493030
102 string characters out of 6136260
53057 words of memory out of 5000000
3641 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
0i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s
No pages of output.

1
package-lock.json generated
View File

@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
"name": "latex2image-web",
"version": "1.0.0",
"license": "MIT",
"dependencies": {

View File

@ -51,8 +51,8 @@
<option>50%</option>
<option>75%</option>
<option>100%</option>
<option selected>125%</option>
<option>150%</option>
<option>125%</option>
<option selected>150%</option>
<option>200%</option>
<option>500%</option>
<option>1000%</option>
@ -87,6 +87,7 @@
<img id="resultImage" />
<br><br>
<a href="#" class="btn btn-primary" role="button" id="downloadButton" target="_blank" download>Save Image</a>
<a href="#" class="btn btn-outline-primary" role="button" id="clipboardButton" target="_blank" download>Copy clipboard</a>
</div>
</div>
<div class="alert alert-danger initiallyHidden" id="errorAlert"></div>

View File

@ -3,6 +3,15 @@ var hasShownBefore = false;
var ENDPOINT = '/convert';
const copyImage = async (src) => {
const response = await fetch(src);
const blob = await response.blob();
await navigator.clipboard.write([
new ClipboardItem({"image/png": blob}),
]);
alert("Copied!")
}
$(document).ready(function() {
function show(resultData) {
function afterSlideUp() {
@ -10,6 +19,10 @@ $(document).ready(function() {
if ((resultDataJSON = JSON.parse(resultData)) && !resultDataJSON.error) {
$('#resultImage').attr('src', resultDataJSON.imageURL);
$('#downloadButton').attr('href', resultDataJSON.imageURL);
$('#clipboardButton').off("click").on("click", (e) => {
e.preventDefault();
copyImage(resultDataJSON.imageURL);
})
$('#resultCard').show();
$('#errorAlert').hide();
} else {
@ -64,6 +77,7 @@ $(document).ready(function() {
$('#exampleButton').prop('disabled', false);
$('#convertButtonText').html('Convert');
$('#convertSpinner').addClass('d-none');
show(data);
},
error: function() {
@ -79,7 +93,7 @@ $(document).ready(function() {
// Show and convert a sample equation
$('#exampleButton').click(function() {
$('#latexInputTextArea').val(sampleEquation);
$('#autoAlignCheckbox').prop('checked', true);
// $('#autoAlignCheckbox').prop('checked', true);
$('#convertButton').click();
});
});