Skip to content

Commit

Permalink
add respository meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
weinbusch committed Feb 16, 2020
1 parent ab24153 commit f937f99
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions AUTHORS
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)
21 changes: 21 additions & 0 deletions LICENSE
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.
61 changes: 61 additions & 0 deletions README.md
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/")
```

0 comments on commit f937f99

Please sign in to comment.