• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

mbr/latex: Python wrappers for calling LaTeX/building LaTeX documents.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mbr/latex

开源软件地址(OpenSource Url):

https://github.com/mbr/latex

开源编程语言(OpenSource Language):

Python 100.0%

开源软件介绍(OpenSource Introduction):

latex

Documentation can be found at https://pythonhosted.org/latex .

Allows calling LaTeX from Python without leaving a mess. Similar to the (officially obsolete) tex package, whose successor is not PyPi-installable:

min_latex = (r"\documentclass{article}"
             r"\begin{document}"
             r"Hello, world!"
             r"\end{document}")

from latex import build_pdf

# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)

# look at the first few bytes of the header
print bytes(pdf)[:10]

Also comes with support for using Jinja2 templates to generate LaTeX files.

make_env can be used to create an Environment that plays well with LaTex:

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

Example use

from jinja2.loaders import FileSystemLoader
from latex.jinja2 import make_env

env = make_env(loader=FileSystemLoader('.'))
tpl = env.get_template('doc.latex')

print(tpl.render(name="Alice"))

The base.latex demonstrates how \BLOCK{...} is substituted for {% ... %}:

\documentclass{article}
\begin{document}
\BLOCK{block body}\BLOCK{endblock}
\end{document}

Finally, doc.latex shows why the %- syntax is usually preferable:

%- extends "base.latex"

%- block body
Hello, \VAR{name|e}.
%- endblock

Translations using Babel

Strings from .latex-templates can be extracted, provided your babel.cfg is setup correctly:

[jinja2: *.latex]
block_start_string = \BLOCK{
block_end_string = }
variable_start_string = \VAR{
variable_end_string = }
comment_start_string = \#{
comment_end_string = }
line_statement_prefix = %-
line_comment_prefix = %#
trim_blocks = True
autoescape = False



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap