question-workbench-skill 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +3 -3
- package/SKILL.md +4 -5
- package/package.json +1 -1
- package/scripts/make-worksheet.mjs +54 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- **纠正方向**:识别与解题仍输出教材里的 Unicode 数学符号(∠ △ ∵ ∴ ⊥ ∥ ²、S₁、x²、√3、π),不再要求模型写 LaTeX。
|
|
6
|
+
- 讲义脚本新增 Unicode→LaTeX 转换:只包裹真正的数学片段,再把它们交给 KaTeX 渲染,中文标点不会被吞进公式。
|
|
7
|
+
- 0.2.0 中“要求模型输出 `$...$`”的做法作废。
|
|
8
|
+
|
|
3
9
|
## 0.2.0
|
|
4
10
|
|
|
5
11
|
- 公式改用 LaTeX:识别与解题都要求 `$...$` / `$$...$$`,不再输出 ∠ △ ∵ ∴ ⊥ ∥ ² 等特殊符号。
|
package/README.md
CHANGED
|
@@ -46,9 +46,9 @@ node .dsh/skills/question-workbench/scripts/make-worksheet.mjs input.json
|
|
|
46
46
|
|
|
47
47
|
## 公式与 KaTeX
|
|
48
48
|
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
- KaTeX 的 CSS 与脚本从 jsDelivr
|
|
49
|
+
- 识别与解题时,数学公式**照原样写教材符号**:`∠ △ ∵ ∴ ⊥ ∥ ²`、`S₁`、`x²`、`√3`、`π`,不需要写 LaTeX,也不用 `$` 包裹。
|
|
50
|
+
- 讲义脚本会自动把这些 Unicode 数学符号转换成 KaTeX 公式再渲染,避免特殊字符在不同字体/打印机下变成方框或乱码。
|
|
51
|
+
- KaTeX 的 CSS 与脚本从 jsDelivr 加载,**首次打开讲义需要联网**;离线时公式退回为可读的原始符号(不会乱码)。
|
|
52
52
|
|
|
53
53
|
## 识别与字数
|
|
54
54
|
|
package/SKILL.md
CHANGED
|
@@ -15,12 +15,11 @@ whenToUse: 用户提供题目图片/截图,或要求识别、解答、排版
|
|
|
15
15
|
- 【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写 `[待核实:简短原因]`,不要猜。**以完整转录为准,不设总字数上限**;长文(阅读填空、完形)也要转录完。
|
|
16
16
|
- 【图形】每张图一行,≤25 字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
**数学公式照原样用教材符号书写**,不要用 LaTeX 命令,也不要用 `$` 包裹:
|
|
19
19
|
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
- 只把数学内容放进 `$...$`,中文说明留在外面;勾股、比例、根式、分式都用 LaTeX,不要用 Unicode 上标或除号
|
|
20
|
+
- 直接写 `∠BAC=60°`、`△ABC`、`AB⊥CD`、`AB∥CD`、`∵`、`∴`、`S₁`、`x²`、`√3`、`π`、`AB∶BC=6∶5`
|
|
21
|
+
- 中文说明、题干文字照常写,不用刻意分栏
|
|
22
|
+
- 讲义生成时会自动把这些符号转成 KaTeX 公式渲染,所以不需要你输出 LaTeX
|
|
24
23
|
|
|
25
24
|
不要在这一步解题,也不要补全图中看不清的内容。输出后停下来等用户确认。
|
|
26
25
|
|
package/package.json
CHANGED
|
@@ -11,6 +11,58 @@ const KATEX = 'https://cdn.jsdelivr.net/npm/katex@0.16.11/dist';
|
|
|
11
11
|
const esc = (v) => String(v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
12
12
|
const marker = /([待核实[^]\n]{0,160}]|\[verify[^\]\n]{0,160}\])/gi;
|
|
13
13
|
const marked = (v) => esc(v).replace(marker, '<b class="bad">$1</b>');
|
|
14
|
+
|
|
15
|
+
// Convert plain Unicode math (∠ △ ∵ ∴ ⊥ ∥ ² S₁ …) into KaTeX inline math, so the
|
|
16
|
+
// author keeps writing normal textbook symbols instead of LaTeX commands.
|
|
17
|
+
const SYMBOLS = {
|
|
18
|
+
'∠': '\\angle ', '△': '\\triangle ', '∵': '\\because ', '∴': '\\therefore ',
|
|
19
|
+
'⊥': '\\perp ', '∥': '\\parallel ', '≌': '\\cong ', '∽': '\\backsim ',
|
|
20
|
+
'≈': '\\approx ', '≠': '\\ne ', '≤': '\\le ', '≥': '\\ge ',
|
|
21
|
+
'±': '\\pm ', '×': '\\times ', '÷': '\\div ', '·': '\\cdot ',
|
|
22
|
+
'√': '\\surd ', 'π': '\\pi ', '°': '^{\\circ}', '∶': ':', ':': ':',
|
|
23
|
+
'∞': '\\infty ', '∪': '\\cup ', '∩': '\\cap ', '∈': '\\in ', '⊂': '\\subset '
|
|
24
|
+
};
|
|
25
|
+
const SUP = { '⁰': '0', '¹': '1', '²': '2', '³': '3', '⁴': '4', '⁵': '5', '⁶': '6', '⁷': '7', '⁸': '8', '⁹': '9' };
|
|
26
|
+
const SUB = { '₀': '0', '₁': '1', '₂': '2', '₃': '3', '₄': '4', '₅': '5', '₆': '6', '₇': '7', '₈': '8', '₉': '9' };
|
|
27
|
+
const MATH_CHARS = new Set([...Object.keys(SYMBOLS), ...Object.keys(SUP), ...Object.keys(SUB)]);
|
|
28
|
+
|
|
29
|
+
function unicodeMathToTex(token) {
|
|
30
|
+
let out = '';
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (i < token.length) {
|
|
33
|
+
const ch = token[i];
|
|
34
|
+
if (SUP[ch]) { let n = ''; while (i < token.length && SUP[token[i]]) { n += SUP[token[i]]; i++; } out += '^{' + n + '}'; continue; }
|
|
35
|
+
if (SUB[ch]) { let n = ''; while (i < token.length && SUB[token[i]]) { n += SUB[token[i]]; i++; } out += '_{' + n + '}'; continue; }
|
|
36
|
+
if (SYMBOLS[ch] !== undefined) { out += SYMBOLS[ch]; i++; continue; }
|
|
37
|
+
if (ch === '%') { out += '\\%'; i++; continue; }
|
|
38
|
+
out += ch;
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const RUN_EXTRA = new Set('+-=/().,:<>[]{}^_|'.split(''));
|
|
45
|
+
|
|
46
|
+
function latexify(text) {
|
|
47
|
+
const lines = String(text).split('\n');
|
|
48
|
+
return lines.map((line) => {
|
|
49
|
+
let out = '';
|
|
50
|
+
let run = '';
|
|
51
|
+
const flush = () => {
|
|
52
|
+
if (!run) return;
|
|
53
|
+
const hasMath = [...run].some((c) => MATH_CHARS.has(c));
|
|
54
|
+
out += hasMath ? '$' + unicodeMathToTex(run) + '$' : run;
|
|
55
|
+
run = '';
|
|
56
|
+
};
|
|
57
|
+
for (const ch of line) {
|
|
58
|
+
const isRunChar = /[A-Za-z0-9]/.test(ch) || RUN_EXTRA.has(ch) || MATH_CHARS.has(ch);
|
|
59
|
+
if (isRunChar) run += ch;
|
|
60
|
+
else { flush(); out += ch; }
|
|
61
|
+
}
|
|
62
|
+
flush();
|
|
63
|
+
return out;
|
|
64
|
+
}).join('\n');
|
|
65
|
+
}
|
|
14
66
|
const stripChecks = (v) => String(v)
|
|
15
67
|
.replace(/(?:^|\n)\s*【(?:待确认|待核实)】[\s\S]*?(?=\n\s*【|$)/g, '')
|
|
16
68
|
.replace(/(?:^|\n)\s*\[(?:Checks|Items to verify)\][\s\S]*?(?=\n\s*\[|$)/gi, '')
|
|
@@ -45,13 +97,13 @@ const figures = (Array.isArray(options.images) ? options.images : []).map((file)
|
|
|
45
97
|
});
|
|
46
98
|
const title = (options.title && String(options.title).trim()) || '题目讲义';
|
|
47
99
|
const notes = options.notes && String(options.notes).trim()
|
|
48
|
-
? '<h2>解答 / 解析</h2><section>' + marked(options.notes) + '</section>' : '';
|
|
100
|
+
? '<h2>解答 / 解析</h2><section>' + marked(latexify(options.notes)) + '</section>' : '';
|
|
49
101
|
|
|
50
102
|
const html = '<!doctype html><html><head><meta charset="utf-8"><title>' + esc(title) + '</title>'
|
|
51
103
|
+ '<style>' + STYLE + '</style>' + KATEX_HEAD + '</head><body>'
|
|
52
104
|
+ '<h1>' + esc(title) + '</h1>'
|
|
53
105
|
+ (options.grade ? '<p>' + esc(options.grade) + '</p>' : '')
|
|
54
|
-
+ '<section>' + marked(text) + '</section>'
|
|
106
|
+
+ '<section>' + marked(latexify(text)) + '</section>'
|
|
55
107
|
+ figures.map((f) => '<figure><img src="' + f.data + '" alt="' + esc(f.name) + '"><figcaption>' + esc(f.name) + '</figcaption></figure>').join('')
|
|
56
108
|
+ notes + '</body></html>';
|
|
57
109
|
|