GithubHelp home page GithubHelp logo

rodrperezi / django-tex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weinbusch/django-tex

0.0 2.0 0.0 30 KB

A simple Django app to render Latex templates and compile them into Pdf files.

License: MIT License

Python 97.16% TeX 2.84%

django-tex's Introduction

DJANGO-TEX

Django-tex is a simple Django app to render LaTeX templates and compile them into PDF files.

Django-tex requires a local LaTeX installation and uses the jinja2 templating engine for template rendering.

Quick start

  1. Add "django_tex" to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...
    'django_tex',
]
  1. Create a LaTeX template in your template directory:
# test.tex
\documentclass{article}

\begin{document}

\section{ {{- foo -}} }

\end{document}
  1. Use "compile_template_to_pdf" in your code to get the PDF file as a bytes object:
from django_tex.core import compile_template_to_pdf

template_name = 'test.tex'
context = {'foo': 'Bar'}
PDF = compile_template_to_pdf(template_name, context)

Or use render_to_pdf to generate a HTTPResponse containing the PDF file:

from django_tex.views import render_to_pdf

def view(request):
    template_name = 'test.tex'
    context = {'foo': 'Bar'}
    return render_to_pdf(template_name, context, filename='test.pdf')

Some notes on usage

Since django-tex uses jinja, you can use jinja's whitespace control in LaTeX templates. For example, \section{ {{ foo }} } would be rendered as \section{ Bar } with the above context; \section{ {{- foo -}} }, however, gets rendered nicely as \section{Bar}.

Django's built-in filters are available. So you can use {{ foo|date('d. F Y') }} to get 1. Januar 2018, for instance.

Further, django-tex adds the custom filter localize to the jinja environment. This runs its input through django.utils.formats.localize_input to create a localized representation. The output depends on the USE_L10N and LANGUAGE_CODE settings. Use the filter like this: {{ foo|localize }}.

If you want to convert linebreaks into LaTeX linebreaks (\\), use the linebreaks filter ({{ foo | linebreaks }}).

django-tex's People

Watchers

James Cloos avatar  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.