AI公式识别·一键转LaTeX
简介
基于智谱GLM-OCR API的数学公式识别工具,可将图片/PDF中的复杂公式高精度转换为LaTeX格式,支持积分、矩阵、分式等专业数学表达式。
原始描述
Official skill for recognizing and extracting mathematical formulas from images and PDFs into LaTeX format using ZhiPu GLM-OCR API. Supports complex equation...
通过你的 Agent 添加
安装目录:glmocr-formula/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
GLM-OCR Formula Recognition Skill 是智谱官方推出的数学公式专用OCR工具,核心功能是将包含数学公式的图像或PDF文档转换为可编辑的LaTeX格式。用户通过调用 python scripts/glm_ocr_cli.py 脚本,传入本地文件路径(--file)或远程URL(--file-url)即可发起识别请求。API返回结构化JSON结果,其中 text 字段包含Markdown/LaTeX混合格式的提取内容,layout_details 提供版面分析细节。
显著优点
- 专业公式识别能力:针对复杂数学场景优化,支持积分、求和、矩阵、分式、根式、上下标等结构,远超通用OCR的公式处理水平
- 标准LaTeX输出:直接输出学术标准LaTeX代码,无缝对接Overleaf、MathJax、KaTeX等排版系统
- 混合内容处理:可同时识别文档中的普通文本与公式,保持阅读顺序和结构层次
- 灵活输入方式:同时支持本地文件与远程URL,满足截图、扫描件、在线资源等多场景需求
- 企业级API底座:依托智谱开放平台,具备稳定的服务可用性和持续模型迭代
潜在缺点与局限性
- API密钥依赖:必须使用
ZHIPU_API_KEY,国内平台注册流程对部分海外用户存在门槛
- 网络延迟敏感:公式识别需云端推理,大文件或复杂排版可能出现超时(可通过
GLM_OCR_TIMEOUT 调整)
- LaTeX渲染限制:多数聊天环境不支持原生LaTeX渲染,需人工转换为Unicode或借助外部工具查看效果
- 端点固定不可改:出于安全考虑,不支持自定义API地址,无法对接私有化部署或代理服务
- 成本因素:作为商业API服务,高频调用将产生费用,免费额度有限
适合人群
- 科研人员:需要从PDF论文、预印本中提取公式进行引用或改写
- 教育工作者:批量处理教材、试卷中的数学内容制作电子资源
- 学生群体:将手写或印刷笔记转换为可编辑的电子版公式
- 出版从业者:学术图书、期刊的数字化排版工作流
常规风险
- 密钥泄露风险:
ZHIPU_API_KEY 需妥善保管,避免提交至公共代码仓库
- 数据隐私:上传文件将传输至智谱云端处理,敏感科研数据需谨慎评估
- API稳定性:依赖第三方服务商,存在配额耗尽、服务降级等不可控因素
- 识别误差:极端复杂的手写公式或低质量扫描件可能出现结构识别错误,关键场景建议人工复核
- API密钥依赖:必须使用
ZHIPU_API_KEY,国内平台注册流程对部分海外用户存在门槛 - 网络延迟敏感:公式识别需云端推理,大文件或复杂排版可能出现超时(可通过
GLM_OCR_TIMEOUT调整) - LaTeX渲染限制:多数聊天环境不支持原生LaTeX渲染,需人工转换为Unicode或借助外部工具查看效果
- 端点固定不可改:出于安全考虑,不支持自定义API地址,无法对接私有化部署或代理服务
- 成本因素:作为商业API服务,高频调用将产生费用,免费额度有限
适合人群
- 科研人员:需要从PDF论文、预印本中提取公式进行引用或改写
- 教育工作者:批量处理教材、试卷中的数学内容制作电子资源
- 学生群体:将手写或印刷笔记转换为可编辑的电子版公式
- 出版从业者:学术图书、期刊的数字化排版工作流
常规风险
- 密钥泄露风险:
ZHIPU_API_KEY 需妥善保管,避免提交至公共代码仓库
- 数据隐私:上传文件将传输至智谱云端处理,敏感科研数据需谨慎评估
- API稳定性:依赖第三方服务商,存在配额耗尽、服务降级等不可控因素
- 识别误差:极端复杂的手写公式或低质量扫描件可能出现结构识别错误,关键场景建议人工复核
- 密钥泄露风险:
ZHIPU_API_KEY需妥善保管,避免提交至公共代码仓库 - 数据隐私:上传文件将传输至智谱云端处理,敏感科研数据需谨慎评估
- API稳定性:依赖第三方服务商,存在配额耗尽、服务降级等不可控因素
- 识别误差:极端复杂的手写公式或低质量扫描件可能出现结构识别错误,关键场景建议人工复核
技能正文
name: glmocr-formula
description:
Official skill for recognizing and extracting mathematical formulas from images and PDFs into LaTeX format
using ZhiPu GLM-OCR API. Supports complex equations, inline formulas, and formula blocks.
Use this skill when the user wants to extract formulas, convert formula images to LaTeX,
or OCR mathematical expressions.
metadata:
openclaw:
requires:
env:
- ZHIPU_API_KEY
- GLM_OCR_TIMEOUT
primaryEnv: ZHIPU_API_KEY
emoji: "📐"
homepage: https://github.com/zai-org/GLM-OCR/tree/main/skills/glmocr-formula
GLM-OCR Formula Recognition Skill / GLM-OCR 公式识别技能
Recognize mathematical formulas from images and PDFs and convert them to LaTeX format using the ZhiPu GLM-OCR layout parsing API.
When to Use / 使用场景
- Extract mathematical formulas from images or scanned documents / 从图片或扫描件中提取数学公式
- Convert formula images to LaTeX / 将公式图片转为 LaTeX 格式
- Recognize complex equations, integrals, matrices / 识别复杂方程、积分、矩阵
- Parse scientific papers, textbooks, exam papers with formulas / 解析含公式的论文、教材、试卷
- User mentions "formula OCR", "extract formula", "公式识别", "公式OCR", "提取公式", "图片转LaTeX"
Key Features / 核心特性
- Complex formula support: Handles integrals, summations, matrices, fractions, radicals
- LaTeX output: Formulas are output in LaTeX format, ready for use in documents
- Inline & block formulas: Recognizes both inline and display-style formulas
- Mixed content: Can handle documents with both text and formulas
- Local file & URL: Supports both local files and remote URLs
Resource Links / 资源链接
Resource
Link
Get API Key
智谱开放平台 API Keys
API Docs
Layout Parsing / 版面解析
Prerequisites / 前置条件
API Key Setup / API Key 配置(Required / 必需)
- Complex formula support: Handles integrals, summations, matrices, fractions, radicals
- LaTeX output: Formulas are output in LaTeX format, ready for use in documents
- Inline & block formulas: Recognizes both inline and display-style formulas
- Mixed content: Can handle documents with both text and formulas
- Local file & URL: Supports both local files and remote URLs
Resource Links / 资源链接
Resource
Link
Get API Key
智谱开放平台 API Keys
API Docs
Layout Parsing / 版面解析
Prerequisites / 前置条件
API Key Setup / API Key 配置(Required / 必需)
| Resource | Link |
|---|---|
| Get API Key | 智谱开放平台 API Keys |
| API Docs | Layout Parsing / 版面解析 |
API Key Setup / API Key 配置(Required / 必需)
脚本通过 ZHIPU_API_KEY 环境变量获取密钥,可与其他智谱技能复用同一个 key。
This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.
Get Key / 获取 Key: Visit 智谱开放平台 API Keys to create or copy your key.
Setup options / 配置方式(任选一种):
-
Global config (recommended) / 全局配置(推荐): Set once in
openclaw.jsonunderenv.vars, all Zhipu skills will share it:{ "env": { "vars": { "ZHIPU_API_KEY": "你的密钥" } } } -
Skill-level config / Skill 级别配置: Set for this skill only in
openclaw.json:{ "skills": { "entries": { "glmocr-formula": { "env": { "ZHIPU_API_KEY": "你的密钥" } } } } } -
Shell environment variable / Shell 环境变量: Add to
~/.zshrc:export ZHIPU_API_KEY="你的密钥"
💡 如果你已为其他智谱 skill(如
glmocr、glmv-caption、glm-image-generation)配置过 key,它们共享同一个ZHIPU_API_KEY,无需重复配置。
Security & Transparency / 安全与透明度
- Environment variables used / 使用的环境变量:
ZHIPU_API_KEY (required / 必需)
GLM_OCR_TIMEOUT (optional timeout seconds / 可选超时秒数)
- Fixed endpoint / 固定官方端点:
https://open.bigmodel.cn/api/paas/v4/layout_parsing
- No custom API URL override / 不支持自定义 API URL 覆盖: avoids accidental key exfiltration via redirected endpoints.
- Raw upstream response is optional / 原始响应默认不返回: use
--include-raw only when needed for debugging.
ZHIPU_API_KEY(required / 必需)GLM_OCR_TIMEOUT(optional timeout seconds / 可选超时秒数)
https://open.bigmodel.cn/api/paas/v4/layout_parsing--include-raw only when needed for debugging.⛔ MANDATORY RESTRICTIONS / 强制限制 ⛔
- ONLY use GLM-OCR API — Execute the script
python scripts/glm_ocr_cli.py - NEVER parse formulas yourself — Do NOT try to extract formulas using built-in vision or any other method
- NEVER offer alternatives — Do NOT suggest "I can try to read it" or similar
- IF API fails — Display the error message and STOP immediately
- NO fallback methods — Do NOT attempt formula extraction any other way
📋 Output Display Rules / 输出展示规则
After running the script, present the OCR result clearly and safely.
- Show extracted text/formulas (
text) in full - Summarization is allowed, but do not hide important extraction failures
- If
layout_detailscontains formula-related entries, you may highlight them - If the result file is saved, tell the user the file path
- Show raw upstream response only when explicitly requested or debugging (
--include-raw)
⚠️ LaTeX Rendering / LaTeX 渲染注意:
OCR API returns formulas in LaTeX format (e.g., $\frac{1}{2}$, $\theta^{x+1}$). Since most chat platforms do not render LaTeX, you should ask the user once (on first use):
"OCR 结果包含 LaTeX 公式,需要我将公式转为 Unicode 可读格式展示,还是保留原始 LaTeX?"
Remember the user's choice for the rest of the session. Do NOT ask again on subsequent calls unless the user explicitly changes their preference.
- User chooses readable format → convert LaTeX to Unicode/plain-text:
| LaTeX | Unicode / 纯文本 |
|---|---|
$\frac{a}{b}$ |
a/b |
$x^{n}$ |
x^n |
$x_{i}$ |
xᵢ |
$\sqrt{x}$ |
√x |
$\theta$ |
θ |
$\phi$ |
φ |
$\therefore$ |
∴ |
$\Rightarrow$ |
⇒ |
$\left\{ \begin{array}{l} ... \end{array} \right.$ |
⎧ line1 ⎨ line2 ⎩ |
$\textcircled{1}$ |
① |
$\in$ |
∈ |
$\infty$ |
∞ |
$\ln$ |
ln |
$\leq$ / $\geq$ |
≤ / ≥ |
- User chooses raw LaTeX → display the original LaTeX output directly, and remind them the raw data is also saved in the output file if
--outputwas used.
How to Use / 使用方法
Extract from URL / 从 URL 提取
python scripts/glm_ocr_cli.py --file-url "https://example.com/formula.png"
Extract from Local File / 从本地文件提取
python scripts/glm_ocr_cli.py --file /path/to/equation.png
Save Result to File / 保存结果到文件
python scripts/glm_ocr_cli.py --file formula.png --output result.json --pretty
Include Raw Upstream Response (Debug Only) / 包含原始上游响应(仅调试)
python scripts/glm_ocr_cli.py --file formula.png --output result.json --include-raw
CLI Reference / CLI 参数
python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
Parameter
Required
Description
--file-url
One of
URL to image/PDF
--file
One of
Local file path to image/PDF
--output, -o
No
Save result JSON to file
--pretty
No
Pretty-print JSON output
--include-raw
No
Include raw upstream API response in result field (debug only)
Response Format / 响应格式
{
"ok": true,
"text": "Extracted formulas and text in Markdown/LaTeX...",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
python scripts/glm_ocr_cli.py --file /path/to/equation.png
python scripts/glm_ocr_cli.py --file formula.png --output result.json --pretty
Include Raw Upstream Response (Debug Only) / 包含原始上游响应(仅调试)
python scripts/glm_ocr_cli.py --file formula.png --output result.json --include-raw
CLI Reference / CLI 参数
python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
Parameter
Required
Description
--file-url
One of
URL to image/PDF
--file
One of
Local file path to image/PDF
--output, -o
No
Save result JSON to file
--pretty
No
Pretty-print JSON output
--include-raw
No
Include raw upstream API response in result field (debug only)
Response Format / 响应格式
{
"ok": true,
"text": "Extracted formulas and text in Markdown/LaTeX...",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
python scripts/glm_ocr_cli.py --file formula.png --output result.json --include-raw
python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
| Parameter | Required | Description |
|---|---|---|
--file-url |
One of | URL to image/PDF |
--file |
One of | Local file path to image/PDF |
--output, -o |
No | Save result JSON to file |
--pretty |
No | Pretty-print JSON output |
--include-raw |
No | Include raw upstream API response in result field (debug only) |
Response Format / 响应格式
{
"ok": true,
"text": "Extracted formulas and text in Markdown/LaTeX...",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
{
"ok": true,
"text": "Extracted formulas and text in Markdown/LaTeX...",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
Key fields:
ok— whether extraction succeededtext— extracted text in Markdown with LaTeX formulaslayout_details— layout analysis detailserror— error details on failure
Error Handling / 错误处理
API key not configured:
ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys
→ Show exact error to user, guide them to configure
Authentication failed (401/403): API key invalid/expired → reconfigure
Rate limit (429): Quota exhausted → inform user to wait
File not found: Local file missing → check path
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。