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)¶ 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 pdflatex and bibtex logs. These are generated by running pdflatex and bibtex in a temporary directory which is removed once the results are copied into the LaTeXFile object.
-
djatex.
render_latex
(request, filename, template_name, error_template_name=None, bib_template_name=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 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.