Code Monkey home page Code Monkey logo

latex2svg-service's Introduction

latex2svg-service

A small online service to convert a LaTeX document to SVG, using Bun, Elysia, texlive.net and pdf2svg.

This is mainly intended for internal usage in a company, so it's run on a pretty small machine and I don't want to pay too much for this. Hence an API key is required to prevent over-use. If you want an API key, feel free to contact [email protected].

const texContent = `
\\documentclass[tikz]{standalone}
\\begin{document}
\\begin{tikzpicture}
  \\draw (0,0) circle (1cm);
\\end{tikzpicture}
\\end{document}
`.trimStart();

const res = await fetch("https://latex2svg.joulev.dev/v1", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ fileContent: texContent }),
});
const svg = await res.text();
// <svg xmlns="http://www.w3.org/2000/svg" ...

The endpoint accepts JSON requests of type

interface BodySchema {
  fileContent: string;
}

The file will then be run on pdflatex.

The endpoint always returns textual response so res.text() is safe.

If the compilation succeeds, the Content-Type of the response is set to image/svg+xml with the text response being the SVG code.

If the compilation fails with an error, the 400 status code is used with Content-Type being text/plain and the response being the compilation log. You may want to let the user know this log content for them to debug the compilation error.

latex2svg-service's People

Contributors

joulev avatar

Stargazers

 avatar  avatar

Watchers

 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.