Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

REST Framework LaTeX Plugin

CircleCI PyPI version Documentation Status

A simple plug-n-play LaTeX renderer for Django REST Framework.



REST Framework LaTeX can be downloaded from PyPI:

pip install rest-framework-latex


Currently the LaTeX plugin requires lualatex - to install this on Ubuntu:

sudo aptitude install texlive-latex-extra texlive-xetex

This will probably take some time due to the size of LaTeX (around 1GB)

Using the Renderer

You can then configure the renderer in your settings or on each view:



The LATEX_RESOURCES directory contains the base template environment e.g. any images or static resources to include in your template. This must be set for the renderer to work:

LATEX_RESOURCES = '/home/user/path_to_resources'

This works just like TemplateHTMLRenderer but by setting a latex_name on your view:

from rest_framework import viewsets

from rest_framework_latex import renderers

class SomeViewSet(viewsets.ViewSet):
  renderer_classes = [

  latex_name = 'directory/latexfile.tex'

Latex Templates

To use the template tags, add rest_framework_latex to your INSTALLED_APPS:


The TeX file used for rendering will be pushed through Django's templating system. This will cause some issues whereby you want to do something like:

\textt{{{ some_variable }}}

To get around this issue you will need to do something like the following:

\textt{% templatetag openbrace %}{{ some_variable }}{% templatetag closebrace %}

Included Tags

Tag Tag/Filter Purpose
latex_safe Filter Escape all user-entered content for LaTeX rules
latex_resources Tag Print the value of settings.LATEX_RESOURCES

How it works

The renderer works by creating a new temporary directory, and then copying over the LATEX_RESOURCES directory into the new temporary directory.

Next it renders the TeX file into the temporary directory.

Then it runs lualatex over the TeX file, and this will produce the PDF file we read into memory.

Then we delete the temporary directory and return the PDF to the client.

Django Compatibility

The REST Framework LaTeX plugin is compatible with Django 1.11 and up and Django REST Framework 3.3 and up.


No releases published


No packages published

Contributors 4