乳胶数学渲染服务器。
texoid的Python项目详细描述
纹理
python服务器,用于将乳胶数学渲染为svg和png。 它非常轻巧,非常适合将乳胶文档嵌入到网页中,而无需亲自渲染文档。
安装
texoid的设置和使用非常简单。
$ pip install texoid
texoid使用^{texbox
,install Docker一起使用texoid。
或者,texoid可以直接使用latex将文档呈现为dvi格式,dvisvgm
转换为svg,imagemagick将svg转换为png。在一个典型的debian或ubuntu机器上,您可以使用:
$ apt-get install texlive-latex-base texlive-binaries imagemagick
运行texoid
有Docker
要使用docker运行texoid,只需对docker
组中的用户运行以下命令:
$ texoid --port=<port> --docker
这将自动提取最新的texbox
图像并开始使用它。
没有docker
要在不使用Docker的情况下启动Texoid,请使用:
$ LATEX_BIN=<path to latex> DVISVGM_BIN=<path to dvisvgm> CONVERT_BIN=<path to convert> texoid --port=<port>
如果这三个可执行文件都存在于/usr/bin
中,则不需要环境变量。这里,convert
指的是imagemagick的convert
工具。
使用texoid
texoid希望post body包含要呈现的乳胶文档。您应该使用适当的Content-Type
发送请求,例如text/plain
、application/x-tex
,或text/x-tex
。不要使用application/x-www-form-urlencoded
。
texoid还有一个遗留api。这个api使用application/x-www-form-urlencoded
作为Content-Type
,并发送在q
字段中编码的乳胶代码表单。
响应
响应将始终包含一个布尔字段success
。
如果success
是true
:
svg
将包含呈现文档的svg源png
将包含base64编码的二进制png文件meta
将是包含两个条目的dict:width
,呈现文档的宽度(像素)height
,呈现文档的高度,同样以像素为单位- 这些参数是生成的svg/png的大小,以便在网页中正确显示
如果success
是false
,则响应将包含一个带乳胶错误输出的error
字段。
示例
在这些示例中,假设texoid服务器在端口8888的localhost
上运行。我们将呈现一个简单的乳胶文档:
\documentclass{standalone}\begin{document}$E=mc^2$\end{document}
渲染成功
$ curl -H 'Content-Type: text/plain' --data-raw '\documentclass{standalone}\begin{document}$E=mc^2$\end{document}' localhost:8888
{"success": true, "svg": "<?xml version='1.0'?><svg....</svg>", "png": "iVBORw0KGgoA....RK5CYII=", "meta": {"width": "48", "height": "10"}}
格式错误的请求
$ curl -H 'Content-Type: text/plain' --data 'malformed' localhost:8888
{"success": false, "error": "This is pdfTeX, Version 3.14159265-2.6-1.40.15...LaTeX Error: Missing \\begin{document}..."}
$ curl -H 'Content-Type: text/plain' --data 'malformed' localhost:8888 {"success": false, "error": "This is pdfTeX, Version 3.14159265-2.6-1.40.15...LaTeX Error: Missing \\begin{document}..."}
就这样!