Docs

Libraries

There are no known libraries yet. If you've written one, talk to me!

REST Endpoints

POST /api/v2

Request

Body should be JSON data containing the LaTeX code and the output format. The format can be one of pdf, png or jpg.

{
	'code': '\begin{document} Hello \end{document}',
	'format': 'pdf'
}

When format is either png or jpg, two more fields are available. quality specifies the compression quality of the resulting image, with 100 being the highest quality. density is the frequency with which to sample pixels from the PDF file. Higher density will result in a larger file.

{
	'code': '\begin{document} Hello \end{document}',
	'format': 'pdf',
	'quality': 20,
	'density': 300
}

The default value for quality is 85, and the default value for density is 200.

Success Response

{
	'staus': 'success',
	'log': '(LaTeX rendering log, usually quite large)',
	'filename': 'mpkitxwIIArLENkzamE0FzkURk3aA9HI.pdf'
}

Failure Response

{
	'status': 'error',
	'description': 'Human readable message of what went wrong',
	'log': '(LaTeX rendering log, not guaranteed here)'
}

GET /api/v2/filename

Request

filename should be filename retrieved from the initial post request.

Response

The file. A 404 error code will be given if it doesn't exist. Files are stored on the server for an indeterminate length of time, but will be eventually be removed.

Python Example

Written for Python 3. You'll have to pip3 install requests if you don't have the library already.

import requests
import shutil

HOST = 'http://63.142.251.124:80'

LATEX = r'''
\documentclass{article}
\begin{document}
\pagenumbering{gobble}
\section{Hello, World!}
This is \LaTeX!
\end{document}
'''

def download_file(url, dest_filename):
	response = requests.get(url, stream = True)
	response.raise_for_status()
	with open(dest_filename, 'wb') as out_file:
		shutil.copyfileobj(response.raw, out_file)

def render_latex(output_format, latex, dest_filename):
	payload = {'code': latex, 'format': output_format}
	response = requests.post(HOST + '/api/v2', data = payload)
	response.raise_for_status()
	jdata = response.json()
	if jdata['status'] != 'success':
		raise Exception('Failed to render LaTeX')
	url = HOST + '/api/v2/' + jdata['filename']
	download_file(url, dest_filename)

render_latex('pdf', LATEX, './out.pdf')

Details and Limitations