Adding feature of changing color of displayed equation.
This commit is contained in:
parent
f077a800f9
commit
dcd974e5b4
17
app.js
17
app.js
@ -77,13 +77,22 @@ conversionRouter.post('/convert', async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define a regular expression pattern to match a 6-character string of numbers or letters.
|
||||||
|
const colorPattern = /^[0-9a-zA-Z]{6}$/;
|
||||||
|
|
||||||
|
if (!colorPattern.test(req.body.outputColor)) {
|
||||||
|
res.end(JSON.stringify({ error: 'Invalid color format. It should be a 6-character string of numbers and/or letters.' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const equation = req.body.latexInput.trim();
|
const equation = req.body.latexInput.trim();
|
||||||
const fileFormat = req.body.outputFormat.toLowerCase();
|
const fileFormat = req.body.outputFormat.toLowerCase();
|
||||||
const outputScale = scaleMap[req.body.outputScale];
|
const outputScale = scaleMap[req.body.outputScale];
|
||||||
|
const fontColor = req.body.outputColor;
|
||||||
|
|
||||||
// Generate and write the .tex file
|
// Generate and write the .tex file
|
||||||
await fsPromises.mkdir(`${tempDir}/${id}`);
|
await fsPromises.mkdir(`${tempDir}/${id}`);
|
||||||
await fsPromises.writeFile(`${tempDir}/${id}/equation.tex`, getLatexTemplate(equation));
|
await fsPromises.writeFile(`${tempDir}/${id}/equation.tex`, getLatexTemplate(equation, fontColor));
|
||||||
|
|
||||||
// Run the LaTeX compiler and generate a .svg file
|
// Run the LaTeX compiler and generate a .svg file
|
||||||
await execAsync(getDockerCommand(id, outputScale));
|
await execAsync(getDockerCommand(id, outputScale));
|
||||||
@ -133,7 +142,7 @@ app.listen(port, () => console.log(`Latex2Image listening at http://localhost:${
|
|||||||
//// Helper functions
|
//// Helper functions
|
||||||
|
|
||||||
// Get the LaTeX document template for the requested equation
|
// Get the LaTeX document template for the requested equation
|
||||||
function getLatexTemplate(equation) {
|
function getLatexTemplate(equation, fontColor) {
|
||||||
return `
|
return `
|
||||||
\\documentclass[12pt]{article}
|
\\documentclass[12pt]{article}
|
||||||
\\usepackage{amsmath}
|
\\usepackage{amsmath}
|
||||||
@ -143,8 +152,12 @@ function getLatexTemplate(equation) {
|
|||||||
\\usepackage{siunitx}
|
\\usepackage{siunitx}
|
||||||
\\usepackage[utf8]{inputenc}
|
\\usepackage[utf8]{inputenc}
|
||||||
\\thispagestyle{empty}
|
\\thispagestyle{empty}
|
||||||
|
\\definecolor{mycolor}{HTML}{${fontColor}}
|
||||||
\\begin{document}
|
\\begin{document}
|
||||||
|
\{
|
||||||
|
\\color{mycolor}
|
||||||
${equation}
|
${equation}
|
||||||
|
\}
|
||||||
\\end{document}`;
|
\\end{document}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
package-lock.json
generated
1
package-lock.json
generated
@ -5,6 +5,7 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "latex2image-web",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -42,6 +42,12 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="outputColorSelect">Font color (HEX format without '#')</label>
|
||||||
|
<input type="text" class="form-control" id="outputColorSelect" placeholder="000000">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="outputScaleSelect">Scale</label>
|
<label for="outputScaleSelect">Scale</label>
|
||||||
|
@ -57,7 +57,8 @@ $(document).ready(function() {
|
|||||||
data: {
|
data: {
|
||||||
latexInput: latexInput,
|
latexInput: latexInput,
|
||||||
outputFormat: $('#outputFormatSelect').val(),
|
outputFormat: $('#outputFormatSelect').val(),
|
||||||
outputScale: $('#outputScaleSelect').val()
|
outputScale: $('#outputScaleSelect').val(),
|
||||||
|
outputColor: $('#outputColorSelect').val()
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#convertButton').prop('disabled', false);
|
$('#convertButton').prop('disabled', false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user