8000 GitHub - ctch3ng/latex2image-web: LaTeX to image converter with web UI using Node.js / Docker
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ctch3ng/latex2image-web

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaTeX2Image (now works in Windows as well)

Image

A Node.js web application that allows LaTeX math equations to be entered and converted to PNG/JPG/SVG images.

For each conversion, an isolated Docker container with a LaTeX installation is started; it compiles the generated .tex file and converts it to an SVG vector image. If required, the SVG file is then converted to a raster image format for PNG/JPG.

Bootstrap and jQuery are used in the web interface, with AJAX calls made to the conversion API endpoint.

Live Demo

The application is accessible at https://latex2image.joeraut.com

Requirements

Operating system

I made use of Ubuntu 18.04. Other Linux distributions should work without problems.

2020-05-09 Confirmed working on Windows 10 build 18363.778

Docker

Docker CE with non-root user support.

Docker image containing the required LaTeX packages preinstalled.

Pull the image:

docker pull blang/latex:ubuntu

Node.js

I made use of v10.14.2, anything newer should be fine.

2020-05-09 Confirmed working on Node.js v10.20.1

After cloning or downloading this project, run the following to install local dependencies from npm:

cd latex2image-web/
npm install

(Optional) Global Node.js packages for non-SVG image export

SVG files can be generated as-is, but for PNG and JPG export support, the two global Node.js packages svgexport and imagemin-cli are required:

npm install svgexport -g
npm install imagemin-cli -g

For Windows users, in %AppData%\npm\node_modules\svgexport\render.js

Change the line

await page.goto('file://' + encodeURI(svgfile))

into

await page.goto('file:///' + encodeURI(svgfile).replace(new RegExp(/%5C/g),"/"))

Usage

To run:

node app.js

For Windows users, run:

node app_win.js

The web interface will be accessible at http://localhost:3001 by default. The port and HTTP URL can be modified inside app.js.

Enter a LaTeX equation, for example \frac{a}{b}, and press Convert. The result will be displayed below the button.

Security

LaTeX is powerful, with the reading and writing of external files and execution of terminal commands possible. It was decided that a new isolated Docker container be launched for every conversion.

The container is only able to access the local temp/<id>/ (temp in Windows) directory and has no network access.

Additionally, the compilation process will be killed after 5 seconds if not complete; this is to safeguard against infinite loops and other troublesome LaTeX quirks.

Internals

Commands used:

  • latex - Converts .tex source file to .dvi intermediate
  • dvisvgm - Converts .dvi file to .svg vector image
  • svgexport - Converts .svg to .png or .jpg raster images
  • imagemin - Compresses .png and .jpg images

Notes

  • The directories temp/ and output/ will be generated automatically inside the latex2image-web/ directory upon first launch.
  • temp/ stores temporary .tex, .dvi, and .svg files during compilation in an inner temp/<id>/ directory (temp/ in Windows), which is deleted upon completion of the conversion.
  • Final output images are stored in output/, and are never deleted.

Authors

  • Joseph Rautenbach - joeraut
  • CT Cheng - ctch3ng -> app_win.js, README.md, static/index.html

Issues

For any issues or bugs, please submit an issue or pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

LaTeX to image converter with web UI using Node.js / Docker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 77.4%
  • HTML 22.0%
  • CSS 0.6%
0