gregwar/tex2png-bundle

LaTeX 到 PNG 公式转换器

安装次数: 1,771

依赖项: 0

建议者: 0

安全性: 0

星标: 4

关注者: 4

分支: 4

公开问题: 1

类型:symfony-bundle

dev-master 2013-06-05 18:06 UTC

This package is auto-updated.

Last update: 2024-08-24 04:17:06 UTC


README

GregwarTex2pngBundle 提供了一个服务和 Twig 辅助工具,用于将 TeX 公式转换为 PNG 图片

安装

步骤 1:下载 GregwarTex2pngBundle

使用 vendors 脚本

将以下行添加到您的 deps 文件中

    [GregwarTex2pngBundle]
        git=git://github.com/Gregwar/Tex2pngBundle.git
        target=/bundles/Gregwar/Tex2pngBundle

现在,运行 vendors 脚本来下载捆绑包

$ php bin/vendors install

使用子模块

如果您更喜欢使用 git 子模块,请运行以下命令

$ git submodule add git://github.com/Gregwar/Tex2pngBundle.git vendor/bundles/Gregwar/Tex2pngBundle
$ git submodule update --init

使用 Composer

将以下内容添加到您的 composer.json 文件的 "require" 部分

    "gregwar/tex2png-bundle": "1.0.0"

并更新您的依赖项

    php composer.phar update

步骤 2:配置自动加载器

如果您使用 composer,可以跳过此步骤。

将其添加到您的 autoload.pp

<?php
...
'Gregwar' => __DIR__.'/../vendor/bundles',

步骤 3:启用捆绑包

在您的 app/AppKernel.php 中注册捆绑包

<?php
...
public function registerBundles()
{
    $bundles = array(
        ...
        new Gregwar\Tex2pngBundle\GregwarTex2pngBundle(),
        ...
    );
...

步骤 4:配置捆绑包并设置目录

将以下配置添加到您的 app/config/config.yml

gregwar_tex2png: ~

如果您想自定义缓存目录名称,可以指定它

gregwar_tex2png:
    cache_dir:  my_cache_dir

创建缓存目录并更改权限,以便 web 服务器可以写入它

mkdir web/cache
chmod 777 web/cache

用法

基础

此捆绑包基于 Gregwar 的 Tex2png 类,并提供了一个服务和 Twig 扩展

<img src="{{ tex('\\sum_{i=0}^{i=n} i') }}" />

将使用公式生成 PNG 图片并将其缓存在文件中。如果此文件已存在,它将不执行其他操作,只需查找正确的文件名。

注意,您可以使用 tex_img Twig 函数生成整个 HTML 标签

{{ tex_img('\\sum_{i=0}^{i=n} i') }}

如果您想更改图像的密度(分辨率),可以将它指定为第二个参数(默认值:155)

{{ tex_img('\\sum_{i=0}^{i=n} i', 300) }}

使用服务

Twig2pngBundle 提供了一个服务,可以用于直接从您的逻辑中生成 tex 文件

<?php
...
$this->get('tex2png')->create('\sum_{i=0}^{i=n} i')
    ->saveTo('formulas/sum.png')
    ->generate();

要求

GregwarTex2pngBundle 需您安装 latexdvipng,一个临时目录,以及 PHP 函数 shell_exec() 应该可用并可使用。

许可

此捆绑包受 MIT 许可证的保护