{ "info": { "author": "Martin Bierbaum", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# django-tex\n\ndjango-tex is a simple Django app to render LaTeX templates and compile\nthem into PDF files.\n\nDjango-tex requires a local LaTeX installation and uses the jinja2 \ntemplating engine for template rendering.\n\n## Installation\n\n`django-tex` is available on [pypi.org](https://pypi.org/project/django-tex/). It can be installed by:\n\n```pip install django_tex```\n\n## Quick start\n\n1. Add \"django_tex\" to your `INSTALLED_APPS` setting:\n\n```python\nINSTALLED_APPS = [\n ...\n 'django_tex',\n]\n```\n\n2. Configure a template engine named `tex` in settings.py:\n\n```python\nTEMPLATES = [\n {\n 'NAME': 'tex',\n 'BACKEND': 'django_tex.engine.TeXEngine', \n 'APP_DIRS': True,\n },\n]\n```\n\n3. Create a LaTeX template in your template directory:\n\n```tex\n# test.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\section{ {{- foo -}} }\n\n\\end{document}\n```\n\n4. Use \"compile_template_to_pdf\" in your code to get the PDF file as a bytes object:\n\n```python\nfrom django_tex.core import compile_template_to_pdf\n\ntemplate_name = 'test.tex'\ncontext = {'foo': 'Bar'}\nPDF = compile_template_to_pdf(template_name, context)\n```\n\nOr use `render_to_pdf` to generate a HTTPResponse containing the PDF file:\n\n```python\nfrom django_tex.shortcuts import render_to_pdf\n\ndef view(request):\n template_name = 'test.tex'\n context = {'foo': 'Bar'}\n return render_to_pdf(request, template_name, context, filename='test.pdf')\n```\n\n## Some notes on usage\n\n### Latex binary\n\nThe default LaTeX interpreter is set to `lualatex`. This can be changed by the setting\n`LATEX_INTERPRETER`, for instance: `LATEX_INTERPRETER = 'pdflatex'`. Of course, the interpreter needs\nto be installed on your system for `django-tex` to work properly.\n\n### Interpreter arguments\n\nYou can pass additional arguments to the latex interpreter by using the `LATEX_INTERPRETER_OPTIONS` setting.\n\n### Whitespace control\n\nSince django-tex uses jinja, you can use jinja's whitespace control in \nLaTeX templates. For example, `\\section{ {{ foo }} }` would be rendered as \n`\\section{ Bar }` with the above context; `\\section{ {{- foo -}} }`, however, \ngets rendered nicely as `\\section{Bar}`.\n\n### Built-in filters\n\nDjango's built-in filters are available. So you can use `{{ foo|date('d. F Y') }}` \nto get `1. Januar 2018`, for instance.\n\nFurther, django-tex adds the custom filter `localize` to the jinja environment.\nThis runs its input through `django.utils.formats.localize_input` to\ncreate a localized representation. The output depends on the `USE_L10N` and `LANGUAGE_CODE`\nsettings. Use the filter like this: `{{ foo|localize }}`.\n\nIf you want to convert linebreaks into LaTeX linebreaks (`\\\\`), use the `linebreaks` filter (`{{ foo | linebreaks }}`).\n### Escaping LaTeX special characters\n\nTo escape LaTeX special characters, use the `escape_latex` filter. This escapes the following characters: `&$%#_{}`.\nPlease note Jinja's autoescaping is turned off in the default `django-tex` environment.\n\n### Custom filters\n\nCustom filters can be defined as explained in the jinja documentation [here](http://jinja.pocoo.org/docs/2.10/api/#custom-filters). For example, the following filter formats a\n`datetime.timedelta` object as a hh:mm string:\n\n```python\ndef hhmm_format(value):\n total_seconds = value.total_seconds()\n hours, remainder = divmod(total_seconds, 3600)\n minutes, seconds = divmod(remainder, 60)\n return '{:n}:{:02n}'.format(hours, minutes)\n```\n\nThe filter has to be added to a custom environment and the `django-tex` templating engine has to be made aware\nof the environment. This can be achieved, for example, by defining a custom environment callable in an `environment.py` module in your app:\n\n```python\n# environment.py\nfrom django_tex.environment import environment\n\ndef hhmm_format(value):\n pass # as above\n\ndef my_environment(**options):\n env = environment(**options)\n env.filters.update({\n 'hhmm_format': hhmm_format\n })\n return env\n```\n\n... and passing the dotted path to `my_environment` to the `TEMPLATES` settings:\n\n```python\n# settings.py\n\nTEMPLATES = [\n {\n 'NAME': 'tex',\n 'BACKEND': 'django_tex.engine.TeXEngine', \n 'APP_DIRS': True,\n 'OPTIONS': {\n 'environment': 'myapp.environment.my_environment',\n }\n },\n]\n```\n\n### Including graphics files\n\nGraphics can be included in LaTeX documents using the `\\includegraphics{}` command provided\nby the `graphicx` package. Normally, LaTeX looks for graphics files in the current working directory, i.e. the \ndirectory including the source `.tex` file. The problem here is that `django-tex` creates a temporary directory to\nstore the source file so that the LaTeX compiler does not see any graphics files provided by the Django application.\nThis problem can be solved by specifying the absolute path to one or more directories including the graphics files \nusing the `\\graphicspath` command.\n\n`Django-tex` allows the user to specify the absolute paths to one or more directories in the `LATEX_GRAPHICSPATH` \nsetting. This setting should contain a list of one or more paths:\n\n```python\n# settings.py\n\nLATEX_GRAPHICSPATH = ['c:\\foo\\bar', 'c:\\bar\\foo']\n```\n\nOf course, a good way of constructing those paths is to use `os.path.join(BASE_DIR, )`.\n\nUsing the template tag `{% graphicspath %}`, the correct `\\graphicspath` command can be inserted into the `.tex` \ntemplate. In the above case, `{% graphicspath %}` turns into `\\graphicspath{ {\"c:/foo/bar/\"} {\"c:/bar/foo/\"} }`. Use \n`{% graphicspath %}` like this:\n\n```\n\\documentclass{article}\n\\usepackage{graphicx}\n\n{% graphicspath %}\n\n\\begin{document}\n\n\\includegraphics{foo}\n\n\\end{document}\n```\n\nIf `LATEX_GRAPHICSPATH` is not specified, `django-tex` takes the `BASE_DIR` instead.\n\nNote: There might be a problem if the path to the graphics directory contains whitespaces. To my knowledge, `lualatex` cannot handle whitespaces in the `\\graphicspath` command, but `pdflatex` can.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/weinbusch/django-tex", "keywords": "django latex jinja2", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-tex", "package_url": "https://pypi.org/project/django-tex/", "platform": "", "project_url": "https://pypi.org/project/django-tex/", "project_urls": { "Homepage": "https://github.com/weinbusch/django-tex" }, "release_url": "https://pypi.org/project/django-tex/1.1.7/", "requires_dist": null, "requires_python": ">=3.6.2", "summary": "A simple Django app to render Latex templates and compile them into PDF files.", "version": "1.1.7" }, "last_serial": 5568871, "releases": { "1.1.2.post2": [ { "comment_text": "", "digests": { "md5": "f4bce385e23c816d941bab4fb471a7a8", "sha256": "3b8579f0eb61047e6068e1ec4a5bf416704be4fa2d0652c3162612627ec5f3dd" }, "downloads": -1, "filename": "django_tex-1.1.2.post2-py3-none-any.whl", "has_sig": false, "md5_digest": "f4bce385e23c816d941bab4fb471a7a8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.2", "size": 7503, "upload_time": "2019-01-16T23:24:39", "url": "https://files.pythonhosted.org/packages/e2/dc/affe2862d00586752ba80f6a7d956fa59e40a96b7fb9137adffb9a8e2456/django_tex-1.1.2.post2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d0835e378e2cb34e3382d6b20331c894", "sha256": "b97ee681eed7a3c2e15ed9a476f4b04f2446e89f7ab52455d0a75035fe9914b8" }, "downloads": -1, "filename": "django-tex-1.1.2.post2.tar.gz", "has_sig": false, "md5_digest": "d0835e378e2cb34e3382d6b20331c894", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 9600, "upload_time": "2019-01-16T23:24:42", "url": "https://files.pythonhosted.org/packages/47/ef/ebd14053f61540c004dd495341ccd1ac296342491986ca930ddd12d414de/django-tex-1.1.2.post2.tar.gz" } ], "1.1.2.post3": [ { "comment_text": "", "digests": { "md5": "39182126328b159a4ca4d83b6e199592", "sha256": "615e6079534e087b0764756889649384f0c7b7e56b0f46ade0cb0b3c816beb64" }, "downloads": -1, "filename": "django_tex-1.1.2.post3-py3-none-any.whl", "has_sig": false, "md5_digest": "39182126328b159a4ca4d83b6e199592", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.2", "size": 7433, "upload_time": "2019-01-16T23:37:40", "url": "https://files.pythonhosted.org/packages/6d/07/d9a2bf032a5465ae1e107e55f7ff74eab397d27395e31d02ef2f7fdce6d8/django_tex-1.1.2.post3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4ad406e0439a1fa7a3ed0e5b79571e95", "sha256": "3d1d5cf6675645bf7f33a37a77f3ca4f3f3085ed3b816464c2d3c46bddf0aef5" }, "downloads": -1, "filename": "django-tex-1.1.2.post3.tar.gz", "has_sig": false, "md5_digest": "4ad406e0439a1fa7a3ed0e5b79571e95", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 10264, "upload_time": "2019-01-16T23:43:30", "url": "https://files.pythonhosted.org/packages/6e/39/11a7db8c0c0940a1498a1b1b9f60f7bf4bcc5768bb7c67e8cfaa6d311cd7/django-tex-1.1.2.post3.tar.gz" } ], "1.1.2.post4": [ { "comment_text": "", "digests": { "md5": "d105e101a6a11dd526aceaa373a4d959", "sha256": "eb8c9fadc9b0c0723cf827dedfce58ae4d5f9738df89ffd6a69910bfb2cc309d" }, "downloads": -1, "filename": "django-tex-1.1.2.post4.tar.gz", "has_sig": false, "md5_digest": "d105e101a6a11dd526aceaa373a4d959", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 10254, "upload_time": "2019-01-20T14:07:04", "url": "https://files.pythonhosted.org/packages/bf/c7/0b93b5b0d0a6dd895232a10d7af6c13ecf959c68e50c1068685aabb60000/django-tex-1.1.2.post4.tar.gz" } ], "1.1.3": [ { "comment_text": "", "digests": { "md5": "a203a9fa9e80a8bc27aa130b13f7db99", "sha256": "962c30ae7b605379dc556f5b73382a6ac04196e1e95716b039ffbd14d5ae55fd" }, "downloads": -1, "filename": "django-tex-1.1.3.tar.gz", "has_sig": false, "md5_digest": "a203a9fa9e80a8bc27aa130b13f7db99", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 10457, "upload_time": "2019-02-04T21:30:20", "url": "https://files.pythonhosted.org/packages/e5/de/1d940314af683a3d0b3c9821d44102f07aa0a69ee7b0cbdf2f887075b6e9/django-tex-1.1.3.tar.gz" } ], "1.1.4": [ { "comment_text": "", "digests": { "md5": "6ded3e329f75a904278fdbf686dfc428", "sha256": "a9767cfd19174c8cdcb2daafd9b30e24c19af86bf03a0c2e0a49a9e0eedcfe1d" }, "downloads": -1, "filename": "django-tex-1.1.4.tar.gz", "has_sig": false, "md5_digest": "6ded3e329f75a904278fdbf686dfc428", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 10503, "upload_time": "2019-03-11T09:46:19", "url": "https://files.pythonhosted.org/packages/2a/5c/c1005a4b8f452a2db3c1bce1946a63180209ec1534b160e144c0a14cde37/django-tex-1.1.4.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "fbbc66e89412db5f92e95a82c7d204be", "sha256": "6dad39a868fafd33947eb110d7116bf4cd0ec34fdbfe05bfcdbb91d6c899ace9" }, "downloads": -1, "filename": "django-tex-1.1.5.tar.gz", "has_sig": false, "md5_digest": "fbbc66e89412db5f92e95a82c7d204be", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 13742, "upload_time": "2019-06-06T18:11:04", "url": "https://files.pythonhosted.org/packages/d6/87/6b4ec7c7f490a818579a99764ce3ba81916c4975925cb12b4dd4346be7a9/django-tex-1.1.5.tar.gz" } ], "1.1.6": [ { "comment_text": "", "digests": { "md5": "d863b42b79c26980c94643e43fa68bca", "sha256": "f150456c517b2462c97a69819a6e61252c746afd4cb667fa281d97c9b767db9a" }, "downloads": -1, "filename": "django-tex-1.1.6.tar.gz", "has_sig": false, "md5_digest": "d863b42b79c26980c94643e43fa68bca", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 14103, "upload_time": "2019-06-28T18:33:31", "url": "https://files.pythonhosted.org/packages/9e/4e/24dbbf9224bdb3d747bae0d2377c3ead7e761e48695d05c797843516d9c8/django-tex-1.1.6.tar.gz" } ], "1.1.7": [ { "comment_text": "", "digests": { "md5": "c711597a70eec2a5eae338468436e269", "sha256": "4a4f118c97eb6399401f47f939825ec1f9eb21b70a5103b4b5ad682b8dda86f7" }, "downloads": -1, "filename": "django-tex-1.1.7.tar.gz", "has_sig": false, "md5_digest": "c711597a70eec2a5eae338468436e269", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 14143, "upload_time": "2019-07-22T20:01:54", "url": "https://files.pythonhosted.org/packages/95/4d/34a4d07b3c5f0daa212f1d445f468a57d9b9e0ab5daacc78340ef1728660/django-tex-1.1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c711597a70eec2a5eae338468436e269", "sha256": "4a4f118c97eb6399401f47f939825ec1f9eb21b70a5103b4b5ad682b8dda86f7" }, "downloads": -1, "filename": "django-tex-1.1.7.tar.gz", "has_sig": false, "md5_digest": "c711597a70eec2a5eae338468436e269", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.2", "size": 14143, "upload_time": "2019-07-22T20:01:54", "url": "https://files.pythonhosted.org/packages/95/4d/34a4d07b3c5f0daa212f1d445f468a57d9b9e0ab5daacc78340ef1728660/django-tex-1.1.7.tar.gz" } ] }