math-exercise-pdf
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "math-exercise-pdf" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-02415609a547cf78b148f99076b92272940a1f4513ebd66609f2bb1db15be782. Verify the upstream source and version against https://skillhub.cn/skills/user_ce094de0/math-exercise-pdf before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Postgraduate math exercise PDF generator: used to create math practice problems, exam papers, and math homework collections as PDF documents. Supports LaTeX math formula typesetting, cover design, and categorized chapter structure to produce structured practice or exam documents.
Introduction source: third_party · user_ce094de0 · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Inputs and outputs
- Translation pending; see source documentation.
- Software, accounts and paid services
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: math-exercise-pdf
description: 考研数学练习题PDF生成器。当用户需要创建数学练习题、考试试卷、数学作业集等PDF文档时使用此技能。支持LaTeX数学公式排版、封面设计、分类章节结构。考研数学做题模板 - PDF生成器
生成专业排版的数学练习题PDF文档,支持完整的LaTeX数学公式渲染。
输出格式选择
- HTML方式(推荐)- 使用HTML+KaTeX,通过Playwright (Chromium headless) 生成PDF,无需LaTeX环境
- LaTeX方式 - 生成.tex文件后用xelatex编译,公式渲染最精致
工作流程
步骤1:收集题目信息
向用户确认以下信息:
- 标题(如"数学练习题"、"考研数学强化训练"等)
- 副标题(如知识点范围)
- 年份/系列信息
- 题目内容(按章节/分类组织)
步骤2:选择输出格式
如果 用户需要高质量PDF且本地有LaTeX环境 → 使用LaTeX模板
如果 用户需要快速预览或无LaTeX环境 → 使用HTML模板
步骤3:生成文档
HTML方式(推荐):
- 复制
assets/math_template.html作为基础 - 替换封面信息(标题、副标题、年份)
- 按章节添加题目内容
- 保存为 .html 文件
- 运行
python scripts/html_to_pdf.py <文件名>.html生成PDF - 若脚本提示"未放在数学定界符中的LaTeX命令",先修复再导出
LaTeX方式:
- 复制
assets/math_template.tex作为基础 - 替换封面信息(标题、副标题、年份)
- 按章节添加题目内容
- 保存为 .tex 文件
- 使用
xelatex编译生成PDF
文件结构
math-exercise-pdf/
├── SKILL.md # 技能说明文档
├── assets/
│ ├── math_template.html # HTML模板(推荐)
│ ├── math_template.tex # LaTeX模板
│ └── README.md # 模板使用说明
└── scripts/
├── html_to_pdf.py # HTML转PDF脚本
├── self_check.py # 自检脚本(验证环境+最小PDF)
└── README.md # 脚本使用说明
题目格式规范
数学公式语法
行内公式:$公式$
块级公式:$$公式$$ 或 \[公式\]
公式渲染防错规则(关键)
- 所有 LaTeX 命令(如
\frac、\sum、\lim、\epsilon、\underline)必须写在数学定界符中($...$或$$...$$)。 - 填空线请写为
$\\underline{\\qquad\\qquad}$,不要在普通文本里裸写\underline{...}。 - 不要覆盖 KaTeX 内部分式布局相关样式(如
.katex .mfrac的display:flex),否则会导致分子分母错位或缺失。 - 数学公式中的不等号必须使用以下三种之一(按推荐顺序):
\\lt/\\gt(KaTeX 原生命令,最推荐)</>(HTML 实体,脚本会自动转义为\\lt/\\gt)- 不要写裸
</>(KaTeX 不支持,浏览器会把它当 HTML 标签,破坏公式)
- PDF 导出统一使用
scripts/html_to_pdf.py;脚本会先做语法检查,并自动修复数学区内的</>后再导出。 - 如需跳过语法检查,可使用
--strict,但只建议在确认无误时使用。
章节结构模板
## 第X部分 章节名称
### 题 N
题目内容,支持数学公式 $x^2 + y^2 = r^2$
### 题 N+1
下一题内容...
常用LaTeX数学命令
| 符号 | 代码 | 符号 | 代码 |
|---|---|---|---|
| 分数 | \dfrac{a}{b} |
根号 | \sqrt{x} |
| 求和 | \sum_{i=1}^{n} |
积分 | \int_a^b |
| 极限 | \lim_{x \to 0} |
偏导 | \frac{\partial f}{\partial x} |
| 向量 | \vec{a} |
矩阵 | \begin{pmatrix}...\end{pmatrix} |
脚本命令行参数
python html_to_pdf.py <输入html> [输出pdf] [--strict] [--keep-temp]
参数:
--strict 严格模式: 检测到可疑LaTeX时中止导出 (默认仅警告不中断)
--keep-temp 保留临时安全副本 (调试用, 默认导出后自动删除)
故障排查
快速诊断
运行 python scripts/self_check.py 一次性检查:
- Python 依赖(playwright、pymupdf)
- Playwright Chromium 浏览器是否已下载
- KaTeX CDN(jsdelivr)是否可达
sanitize_raw_angle_in_math函数的正确性- 最小 HTML 文件能否成功生成 PDF
如果自检失败,按错误提示逐项修复。
常见问题
Q1: PDF 中出现裸 LaTeX(如 $x^2$)
- 原因:KaTeX 库未加载(断网/CND被墙)或触发时机问题
- 排查:
self_check.py第3项检查 KaTeX CDN 是否可达- 用浏览器打开 HTML,按 F12 看 Console 是否有 JS 错误
- 用浏览器打开 HTML,看 DOM 中
.katex元素数是否 > 0
Q2: PDF 中数学公式里的 < / > 显示为字面字符
- 原因:用户写了裸
</>而非\\lt/\\gt或</> - 修复:把 HTML 里的
$ ... < ... $改成$ ... \\lt ... $ - 注:脚本不能自动修复裸
</>(避免误判跨HTML标签的OCR噪声)
Q3: PDF 中出现 $\frac{\partial}{\partial}$ 这种"梯形"伪影
- 原因:自定义 CSS 覆盖了 KaTeX 的
.katex .mfrac样式 - 修复:删除任何对
.katex .mfrac的display/flex/align-items覆盖
Q4: 三角符号(▲▼●)出现在 PDF 上
- 原因:
.katex上设置了过大的font-size(如1.1em) - 修复:删除
.katex { font-size: ... !important; }覆盖
Q5: 某些公式不渲染但 PDF 看起来"还行"
- 原因:KaTeX
throwOnError: false让失败公式保持原文 - 排查:浏览器打开 HTML,按 F12 Console 看
ParseError警告 - 修复:根据警告修正 LaTeX 语法
渲染机制说明
本 skill 使用 Playwright (Chromium headless) 而非 Edge headless,原因是:
- Playwright 对
defer脚本和auto-render的触发更可靠 - Playwright 的
page.evaluate可主动调用renderMathInElement,避免依赖DOMContentLoaded时机
KaTeX auto-render 的二次扫描机制(setTimeout(600ms))确保所有动态添加的公式也被处理。
示例输出
HTML模板渲染效果
第一部分 高等数学
题 1
设函数 $f(x)$ 在 $[0,1]$ 上连续,证明:
$$\int_0^1 f(x)dx = f(\xi), \quad \xi \in [0,1]$$
题 2
求极限:$\displaystyle\lim_{x\to 0}\frac{\sin x}{x}$
依赖要求
pip install playwright pymupdf
playwright install chromium
- LaTeX转PDF(可选):TeX Live 或 MiKTeX 发行版
Current listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决考研数学练习题PDF生成的明确需求
- 支持专业LaTeX数学公式排版
- 提供HTML和LaTeX两种输出格式选择
Highlights
- 触发词覆盖完整(练习题、考试试卷、作业集)
- 边界清晰,不易与其他技能混淆
Areas to improve
-
文档过长 Reported severity: Minor
主文档约600行,超出建议的500行限制
Recommendation: 可考虑将部分内容移至assets/README.md中
-
缺少When to Use显式章节 Reported severity: Minor
虽然有描述但缺少显式的When to Use章节
Recommendation: 建议添加显式的When to Use章节提升可读性
Highlights
- Phase/步骤清晰完整
- 包含端到端示例和故障排查
- frontmatter完整规范
Highlights
- 工具来源明确(Playwright、KaTeX)
- 参数说明详细完整
- 覆盖主要异常场景并有自检脚本
- 提供详细的故障排查指南
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 180
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Translation pending; see source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.