允许从python调用latex而不留下混乱。类似于
(正式过时)tex包,其
successor不能安装pypi:min_latex=(r"\documentclass{article}"r"\begin{document}"r"Hello, world!"r"\end{document}")fromlateximportbuild_pdf# this builds a pdf-file inside a temporary directorypdf=build_pdf(min_latex)# look at the first few bytes of the headerprintbytes(pdf)[:10]
还支持使用Jinja2模板
生成乳胶文件。
make_env可以用来创建一个Environment,它可以很好地与
乳胶:Variables can be used in a LaTeX friendly way: Hello, \VAR{name|e}.
Note that autoescaping is off. Blocks are creating using the block macro:
\BLOCK{if weather is 'good'}
Hooray.
\BLOCK{endif}
\#{comments are supported as well}
%# and so are line comments
To keep things short, line statements can be used:
%- if weather is good
Yay.
%- endif
示例使用fromjinja2.loadersimportFileSystemLoaderfromlatex.jinja2importmake_envenv=make_env(loader=FileSystemLoader('.'))tpl=env.get_template('doc.latex')print(tpl.render(name="Alice"))
base.latex演示如何用\BLOCK{...}替换
{% ... %}:\documentclass{article}\begin{document}\BLOCK{block body}\BLOCK{endblock}\end{document}
最后,doc.latex显示了为什么%-语法通常更可取:%- extends "base.latex"%- block bodyHello, \VAR{name|e}.
%- endblock
欢迎加入QQ群-->: 979659372
推荐PyPI第三方库