-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Django-tex is written and maintained by Martin Bierbaum <https://github.com/weinbusch> | ||
|
||
Other contributors, listed alphabetically, are: | ||
|
||
(If you think that your name belongs here, please let the maintainer know) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Martin Bierbaum | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# flask-tex | ||
|
||
`flask-tex` offers helper functions for using LaTeX from within a Flask | ||
app. `flask-tex` requires a local LaTeX installation and uses `pdflatex` | ||
by default. | ||
|
||
## Usage | ||
|
||
Import `flask_tex.render_to_pdf` and use it like `flask.render_template` | ||
in your view function. | ||
|
||
```python | ||
from flask import Flask | ||
from flask_tex import render_to_pdf | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/") | ||
def return_pdf_response(): | ||
return render_to_pdf("tex_template.tex", foo="Hello World!") | ||
``` | ||
|
||
Your template might look like this and should be located in place where `flask` | ||
can find it. | ||
|
||
```tex | ||
\documentclass{article} | ||
\title{Using \LaTeX{} with Flask} | ||
\begin{document} | ||
\maketitle | ||
{{ foo }} | ||
\end{document} | ||
``` | ||
|
||
For lower level access to LaTeX, use `flask.run_tex`: | ||
|
||
```python | ||
from flask_tex import run_tex | ||
|
||
pdf = run_tex(source, command="pdflatex") | ||
``` | ||
|
||
where `source` is a string containing a `tex` document and command is a string defining | ||
the LaTeX command to use for compiling the source. The default `command` is `pdflatex`, but | ||
you can supply others, e.g. `latexmk -pdf`. `pdf` is a bytes object containing the pdf file. | ||
|
||
`run_tex` runs LaTeX inside a temporary directory. Use `flask_tex.compile_tex` | ||
to circumvent this and run LaTeX in a directory of your choice: | ||
|
||
```python | ||
from flask_tex import compile_tex | ||
|
||
pdf = compile_tex(source, command="pdflatex", directory="/foo/bar/") | ||
``` |