Git Product home page Git Product logo

latex2image-web's Introduction

LaTeX2Image

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 using sharp.

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

Enhencement feature

Generate image on the fly

   example: /latex?latexInput=a_{n%2B1}%3Da_n%2Bk&outputFormat=PNG&outputScale=200%25&color=ff0000
           
   let latex = "a_{n+1}=a_n+k"
   `/latex?latexInput=${encodeURIComponent(latex)}&outputFormat=PNG&outputScale=200%25&color=ffff00`

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.

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.

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

cd latex2image-web/
npm install

Usage

To run:

node app.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>/ 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

We use sharp to convert the SVG file to PNG and JPG images where required.

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, which is deleted upon completion of the conversion.
  • Final output images are stored in output/, and are never deleted.

Authors

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.

latex2image-web's People

Contributors

joeraut avatar ck-luo avatar ittipatken avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.