The djatex module — djaTeX 0.1.10 documentation

# The djatex module

The module defines a class, LaTeXFile, and a shortcut function intended to be called from a django view to render a LaTeX template as an attached PDF file.

class `djatex.` `LaTeXFile`(latex_source, bibtex_source=None, home_dir=None)

  An object which holds LaTeX and, optionally, BibTeX source strings. Its compile method creates a byte sequence containing a pdf rendering of the LaTeX source, as well as strings containing the xelatex and bibtex logs. These are generated by running xelatex and bibtex in a temporary directory which is removed once the results are copied into the LaTeXFile object. If the home_dir argument is not None it should be an absolute path to a directory containing auxiliary files needed for compilation, such as inputs, images or font .fd files. These will be symlinked into the temporary directory before LaTeX is run.

`djatex.` `render_latex`(request, filename, template_name, error_template_name=None, bib_template_name=None, home_dir=None, context=None)

  This shortcut function accepts a LaTeX template file and returns an HttpResponse. If the LaTeX compiles without error, the response will have content_type application/pdf and the content data will be the PDF rendering of the LaTeX source. The filename argument is the name of the PDF file.

  If the optional bib_template_name is provided then the LaTeX will be compiled with the usual pdflatex bibtex pdflatex pdflatex drill. Otherwise, pdflatex will be run once and, if the output specifies undefined references, a second time.

  If the optional home_dir argument is supplied it should be an absolute path to a directory containing any files which are required to compile the LaTeX template. These will be symlinked into the temporary compilatin directory before running LaTeX.

  If there are errors then the response returned by this function will be either a Server Error if no error_template_name is provided. If an error_template_name is provided then that template will be rendered with a context dictionary having three keys. The first, named ‘stage’ has value either ‘latex’ or ‘bibtex’ and specifies which TeX executable failed. The other two, ‘output’ and ‘source’ contain the stdout of the TeX executable and the input LaTeX or BibTex. The values are lists of strings, to enable the error template to display the results with the same line breaks, possibly including line numbers.