latex2image-web/README.md

92 lines
3.0 KiB
Markdown
Raw Permalink Normal View History

2019-01-20 20:23:31 +02:00
# LaTeX2Image
2019-01-20 23:56:53 +02:00
![Image](screenshots/main.png)
2019-01-20 23:04:24 +02:00
A Node.js web application that allows LaTeX math equations to be entered and converted to PNG/JPG/SVG images.
2021-01-16 19:11:17 +02:00
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](https://sharp.pixelplumbing.com/).
2019-01-20 23:04:24 +02:00
Bootstrap and jQuery are used in the web interface, with AJAX calls made to the conversion API endpoint.
2019-01-20 23:29:50 +02:00
## Live Demo
2019-01-20 23:22:05 +02:00
2019-05-23 12:04:45 +02:00
The application is accessible at [https://latex2image.joeraut.com](https://latex2image.joeraut.com)
2019-01-20 23:22:05 +02:00
2019-05-23 11:36:48 +02:00
## Requirements
2019-01-20 23:04:24 +02:00
2019-01-20 23:12:36 +02:00
### Operating system
I made use of Ubuntu 18.04. Other Linux distributions should work without problems.
2019-01-20 23:04:24 +02:00
### Docker
2019-01-20 23:12:36 +02:00
[Docker CE](https://docs.docker.com/install/linux/docker-ce/ubuntu/) with [non-root user support](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user).
2019-01-20 23:04:24 +02:00
### [latex-docker](https://github.com/blang/latex-docker)
Docker image containing the required LaTeX packages preinstalled.
2019-01-20 23:12:36 +02:00
2019-01-20 23:04:24 +02:00
Pull the image:
```
docker pull blang/latex:ubuntu
```
2019-01-21 14:00:20 +02:00
### Node.js
2019-01-20 23:04:24 +02:00
2020-03-07 05:38:15 +02:00
I made use of v10.14.2, anything newer should be fine.
2019-01-20 23:04:24 +02:00
2019-05-23 11:38:53 +02:00
After cloning or downloading this project, run the following to install local dependencies from npm:
2019-01-20 23:04:24 +02:00
```
2019-05-23 11:33:25 +02:00
cd latex2image-web/
npm install
2019-01-20 23:04:24 +02:00
```
## Usage
To run:
```
node app.js
```
2019-05-23 11:33:25 +02:00
The web interface will be accessible at `http://localhost:3001` by default. The port and HTTP URL can be modified inside `app.js`.
2019-01-20 23:04:24 +02:00
2019-01-20 23:12:36 +02:00
Enter a LaTeX equation, for example `\frac{a}{b}`, and press Convert. The result will be displayed below the button.
2019-01-20 23:04:24 +02:00
2019-01-20 23:22:05 +02:00
## Security
2019-01-21 14:00:20 +02:00
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.
2019-01-20 23:22:05 +02:00
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.
2019-01-20 23:25:45 +02:00
## Internals
### Commands used:
2019-01-20 23:25:45 +02:00
* `latex` - Converts `.tex` source file to `.dvi` intermediate
* `dvisvgm` - Converts `.dvi` file to `.svg` vector image
We use [sharp](https://www.npmjs.com/package/sharp) to convert the SVG file to PNG and JPG images where required.
2019-01-20 23:25:45 +02:00
2019-01-20 23:04:24 +02:00
## Notes
* The directories `temp/` and `output/` will be generated automatically inside the `latex2image-web/` directory upon first launch.
2019-01-20 23:22:05 +02:00
* `temp/` stores temporary `.tex`, `.dvi`, and `.svg` files during compilation in an inner `temp/<id>/` directory, which is deleted upon completion of the conversion.
2019-01-20 23:12:36 +02:00
* Final output images are stored in `output/`, and are never deleted.
2019-01-20 23:04:24 +02:00
## Authors
2019-01-20 23:12:36 +02:00
* Joseph Rautenbach - [joeraut](https://github.com/joeraut)
## Issues
2019-01-20 23:04:24 +02:00
2019-01-20 23:12:36 +02:00
For any issues or bugs, please submit an issue or pull request.
2019-01-20 23:04:24 +02:00
## License
2019-01-20 23:29:50 +02:00
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.