惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
Y
Y Combinator Blog
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
博客园 - 司徒正美
I
InfoQ
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
U
Unit 42

又见苍岚

COLMAP PatchMatch Stereo 算法详解 事件驱动的状态机框架:从理论到工程实践 Git 在国内网络环境下无法 Push 的排查与修复 —— 配置 Clash 代理 分段五次多项式插值原理详解 路径插值方法深度对比研究 Claude Code 使用指南 OpenClaw 记忆管理与技能创建指南 CBS(Conflict-Based Search)算法详解 A* 算法及其变种详解 OpenClaw 配置多 Agents Windows Powershell 无法加载文件,因为在此系统上禁止运行脚本问题的解决方案 MaxClaw 安装流程 大模型 AI 名词介绍 AList 网盘聚合工具简介 Protobuf 简介与测试 Claude Code 简介以及 GLM 4.7 模型接入 Github 歌词下载工具 163MusicLyrics Python __getattr__ 懒加载 Python TypedDict 机器人仿真平台 Gazebo 安装记录 机器人仿真平台 Gazebo 简介 多机器人路径规划问题(Multi-Agent Path Finding, MAPF)简介 Python exifread 读取修改过的 jpeg 信息错误问题修复 3D 坐标系变换的理解 3D 旋转矩阵基本概念 MongoDB Compass 介绍 Python 环境管理工具 uv Flutter 开发指南 Snipaste 安装下载与黑屏问题解决方案 全局路径规划算法记录
公式识别 API 简介 -- Simpletex 使用
Yiwei Zhang · 2025-04-21 · via 又见苍岚

写博客时候经常需要将图片公式转换为 Latex 格式,已知有几个平台,感觉比较贵,我试用了几个,本文记录相关信息。

简介

公式识别就是将图片转化为 Latex 文本,例如:

对应 Latex:

1
\alpha_i=(1-\exp(-\sigma_i\delta_i))\text{ and }T_i=\prod_{j=1}^{i-1}(1-\alpha_i).

Markdown 渲染公式:
$$
\alpha_i=(1-\exp(-\sigma_i\delta_i))\text{ and }T_i=\prod_{j=1}^{i-1}(1-\alpha_i).
$$
公式识别就是这个识别过程。

常用平台

名称 简介 链接
mathpix 早期有名的公式识别工具,又快又准,现在收费了 https://mathpix.com/
LaTeX-OCR Github 项目,需要有自己的服务器和算力 https://github.com/lukas-blecher/LaTeX-OCR
quicker 一款指上工具箱,其中包含公式识别的调用插件,客户端仅有 Windows版本 https://getquicker.net/
simpletex 新晋的公式识别工具,很好用,现在也收费了 https://simpletex.cn/

API 平台

名称 简介 链接
simpletex 识别准确,当前还在测试,价格不贵,性价比高 https://simpletex.cn/api
mathpix 识别准确,价格比 Simpletxt 贵很多 https://mathpix.com/pricing/api
科大讯飞公式识别 API 当前在内测,每天500次免费调用,但是效果不好 https://www.xfyun.cn/doc/words/formula-discern/API.html
百度公式识别 API **该接口的公有云服务即将下线,**感觉还处在业务调整阶段 https://ai.baidu.com/ai-doc/OCR/Ok3h7xxva
阿里印刷体数学公式识别 API 没有测试,相信阿里的结果应该是准的,就是价格不便宜 https://help.aliyun.com/zh/ocr/developer-reference/api-ocr-api-2021-07-07-recognizeeduformula

Simpletex

对比下来当前还是 Simpletex 比较合适,20元开启 API 功能,之后根据不同模型标注不同价格:

  • 轻量公式识别模型API

服务价格(轻量)

月调用量(次) 价格(元/次)
<1000 免费
1000-5000 0.04
>5000 0.01

API调用方法

接口地址:https://server.simpletex.cn/api/latex_ocr_turbo

  • 标准公式识别模型API

服务价格(标准)

月调用量(次) 价格(元/次)
<1000 免费
1000-5000 0.05
>5000 0.02

其中,每月1号凌晨0时清空记录,按阶梯次进行计费。轻量模型每日赠送2000次免费调用,标准模型赠送500次免费调用。

这里文档有时写的每日有的每月,我也没搞清具体是哪个,感觉每月的可能性大一点。

API 调用方法

接口地址:https://server.simpletex.cn/api/latex_ocr

调用方法

  • 创建令牌(需要充值20元)

  • 创建应用

  • 示例代码

    填入:SIMPLETEX_APP_ID

    填入:SIMPLETEX_APP_SECRET

    准备图片:./image/02.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import datetime
import json
import requests
from random import Random
import hashlib

SIMPLETEX_APP_ID = ""
SIMPLETEX_APP_SECRET = ""

def random_str(randomlength=16):
str = ''
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
length = len(chars) - 1
random = Random()
for i in range(randomlength):
str += chars[random.randint(0, length)]
return str

def get_req_data(req_data, appid, secret):
header = {}
header["timestamp"] = str(int(datetime.datetime.now().timestamp()))
header["random-str"] = random_str(16)
header["app-id"] = appid
pre_sign_string = ""
sorted_keys = list(req_data.keys()) + list(header)
sorted_keys.sort()
for key in sorted_keys:
if pre_sign_string:
pre_sign_string += "&"
if key in header:
pre_sign_string += key + "=" + str(header[key])
else:
pre_sign_string += key + "=" + str(req_data[key])

pre_sign_string += "&secret=" + secret
header["sign"] = hashlib.md5(pre_sign_string.encode()).hexdigest()
return header, req_data

img_file = {"file": open("./image/02.png", 'rb')}
data = { } # 请求参数数据(非文件型参数),视情况填入,可以参考各个接口的参数说明
header, data = get_req_data(data, SIMPLETEX_APP_ID, SIMPLETEX_APP_SECRET)
res = requests.post("https://server.simpletex.cn/api/latex_ocr", files=img_file, data=data, headers=header)

print(json.loads(res.text))
pass

输出结果:

1
{'status': True, 'res': {'latex': '\\alpha_i=(1-\\exp(-\\sigma_i\\delta_i))\\text{ and }T_i=\\prod_{j=1}^{i-1}(1-\\alpha_i).', 'conf': 0.9386832118034363}, 'request_id': 'tr_17453305716849140986868559936'}

参考资料

文章链接:
https://www.zywvvd.com/notes/tools/simpletex-api/simpletex-api/