ftes/phpmathpublisher

phpMathPublisher 分支。用 php5.3 重新编写。添加 PSR-4 支持

dev-master 2018-02-14 09:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:58:16 UTC


README

phpMathPublisher 分支,托管在 github 上,以便于在基于 composer 的 php 应用程序中无缝集成。Packagist 包通过 服务钩子 自动更新。

作者

如何使用

  1. 通过构造函数 new PhpMathPublisher($imgpath, $webpath, $size) 配置设置,其中
  • $imgpath 是 png 文件应存储的路径,
  • $webpath 是 png 文件可以通过 web 服务器访问的路径,
  • size 是在生成这些图像时使用的文本大小。
  1. 调用您的 PhpMathPublisher 对象上的一个接口方法
  • mathImage($text):创建公式图像(如果图像不在缓存中)并返回 <img src=...></img> html 代码
  • mathImagePath($text):创建公式图像(如果图像不在缓存中)并返回文件系统上的绝对路径
  • mathImageBinary($text):创建公式图像并返回二进制 PNG 内容(警告:不使用文件缓存,因此效率低下)
  • mathFilter($text):使用 mathImage()$text 中的所有 <m> 标签替换为 <img> 标签
  • renderImage($text, $file):在指定位置为给定的公式创建图像

示例

(new PhpMathPublisher('../dir/to/img/', 'img/', 12))->mathFilter('A math formula : <m>f(x)=sqrt{x}</m>') 将返回

'A math formula : <img src=\"img/math_988.5_903b2b36fc716cfb87ff76a65911a6f0.png\" style=\"vertical-align:-11.5px; display: inline-block ;\" alt=\"f(x)=sqrt{x}\" title=\"f(x)=sqrt{x}\">'

公式对应的图像只创建一次。然后图像存储到图像目录中。第一次调用 mathfilter 时,将创建公式对应的图像,但下次调用 mathfilter 将仅返回 html 代码。

注意:如果此脚本提供的免费 LaTeX 字体效果不佳(公式非常小 - 这可能发生在某些 GD 配置中),您应尝试使用这些字体的 bakoma 版本(此处可下载