调用乳胶/建筑乳胶文档的包装纸。

latex的Python项目详细描述


文档可以在https://pythonhosted.org/latex找到。

允许从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 body
Hello, \VAR{name|e}.
%- endblock

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java有没有办法在堆栈后保留元素。pop()?   多线程Java:Thread。currentThread()。getName()返回“还没有线程”   java For循环只返回最后一个值   java初始化和比较整数   Java将自定义光标热点设置为图像的中心(.png)   java如何在assertThat中使用带有类型推断的hamcrest nullValue   java Quarkus REST客户端避免空字段的JSON序列化   java使用JFileChooser将语音从文本保存到语音文件   java Android Studio找不到JAR'org。日食jgit4。5.3.201708160445r。罐子   java如何在ElasticSearch中使用带通配符的术语?   java可能的空指针异常安卓   在JavaSwing中使用AwesomeFont中的自定义字体和unicode字符向JButton添加图标?   部署过程中的java持久化单元名称问题WildFly   JavaSpring数据:我无法在数据库中保存关系模型   字符串如何计算文件中单词的长度?JAVA   java Eclipse调试器中变量项旁边的id=xxx是什么   httpclient Java httppost文件打印后上载速度   JAXB对象不实现可序列化的结果是什么?   java Spring JPA数据:自定义通用存储库和服务:未满足PendencyException   java如何从解析类中检索所有值?