From 6f49462d70e975b7e9a1f192921284ed52312061 Mon Sep 17 00:00:00 2001 From: Howard O'Neil Date: Tue, 16 Aug 2022 01:33:45 +0700 Subject: [PATCH] copy to clipboard --- .gitignore | 4 +++- app.js | 8 +++++--- .../howard/la_temp/31b21413817bbb01/texput.log | 18 ++++++++++++++++++ .../howard/la_temp/bdbacdd09db668c0/texput.log | 18 ++++++++++++++++++ package-lock.json | 1 + static/index.html | 5 +++-- static/latex2image-client.js | 16 +++++++++++++++- 7 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 home/howard/la_temp/31b21413817bbb01/texput.log create mode 100644 home/howard/la_temp/bdbacdd09db668c0/texput.log diff --git a/.gitignore b/.gitignore index de5853e..6bd2b74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ temp/ -output/ \ No newline at end of file +output/ +.env +.sh \ No newline at end of file diff --git a/app.js b/app.js index f20e30a..c9b46d7 100644 --- a/app.js +++ b/app.js @@ -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}"`; } diff --git a/home/howard/la_temp/31b21413817bbb01/texput.log b/home/howard/la_temp/31b21413817bbb01/texput.log new file mode 100644 index 0000000..04171bc --- /dev/null +++ b/home/howard/la_temp/31b21413817bbb01/texput.log @@ -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. diff --git a/home/howard/la_temp/bdbacdd09db668c0/texput.log b/home/howard/la_temp/bdbacdd09db668c0/texput.log new file mode 100644 index 0000000..42f38fd --- /dev/null +++ b/home/howard/la_temp/bdbacdd09db668c0/texput.log @@ -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. diff --git a/package-lock.json b/package-lock.json index 71c3a69..533c5cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "latex2image-web", "version": "1.0.0", "license": "MIT", "dependencies": { diff --git a/static/index.html b/static/index.html index b8356af..bfc820e 100644 --- a/static/index.html +++ b/static/index.html @@ -51,8 +51,8 @@ - - + + @@ -87,6 +87,7 @@

Save Image + Copy clipboard
diff --git a/static/latex2image-client.js b/static/latex2image-client.js index 4a98b80..589115f 100644 --- a/static/latex2image-client.js +++ b/static/latex2image-client.js @@ -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(); }); });