diff --git a/.workbuddy/tools/md2pdf/fix_gitea_math.py b/.workbuddy/tools/md2pdf/fix_gitea_math.py index 21a5a02..31f1bea 100644 --- a/.workbuddy/tools/md2pdf/fix_gitea_math.py +++ b/.workbuddy/tools/md2pdf/fix_gitea_math.py @@ -289,6 +289,49 @@ def scan_math_underscore(text): return hits +def scan_nested_dollar(text): + """公式内部又写了一层 ``$`` (典型:``$$P=A^{-1}B\\ (\\text{$\\alpha$ 到 $\\beta$ 的过渡矩阵})$$`` )。 + + KaTeX 在数学模式里遇到 ``$`` 会直接报错,整块公式在网页上原样露出源码; + 而本地 md 预览用的是另一条渲染链,往往看不出问题。改法是把中文挪出公式、 + 公式只留 ``P=A^{-1}B`` ,或删掉内层 ``$`` ,取决于句子结构,故只报告不自动修。""" + hits = [] + + def check(lineno, seg): + inner = seg + for mark in ('$$', '$'): + if inner.startswith(mark): + inner = inner[len(mark):] + break + for mark in ('$$', '$'): + if inner.endswith(mark): + inner = inner[:-len(mark)] + break + if '$' in inner.replace('\\$', ''): + # \tag{$*$} 是 KaTeX 支持的写法(编号用星号),不算嵌套 + if re.search(r'\$', re.sub(r'\\tag\{[^{}]*\}', '', inner).replace('\\$', '')): + hits.append((lineno, seg.replace('\n', ' ')[:90])) + + # 1) 单行公式(含写在一行里的 $$...$$) + base = mask_code(text) + for a, b in find_math_any(base): + check(text.count('\n', 0, a) + 1, text[a:b + 1]) + + # 2) 跨行的 $$ ... $$ 块 + lines = text.split('\n') + inblock, start = False, 0 + for k, line in enumerate(lines): + st = line.strip() + if not st.startswith('$$') or st.count('$$') >= 2: + continue + inblock = not inblock + if inblock: + start = k + else: + check(start + 1, '\n'.join(lines[start:k + 1])) + return sorted(set(hits)) + + def main(): apply = '--apply' in sys.argv scope = None @@ -299,10 +342,14 @@ def main(): total_files = total_hits = 0 report = [] warn = [] + warn2 = [] for path in sorted(iter_md_files(scope)): raw = open(path, encoding='utf-8').read() + rel = os.path.relpath(path, ROOT) for ln, seg in scan_math_underscore(raw): - warn.append((os.path.relpath(path, ROOT), ln, seg)) + warn.append((rel, ln, seg)) + for ln, seg in scan_nested_dollar(raw): + warn2.append((rel, ln, seg)) new, changes = fix_text(raw) new2, fm_hits = fix_frontmatter(new) if fm_hits: @@ -326,6 +373,13 @@ def main(): print(f' L{ln:<5d}{rel}') print(f' {seg}') print(f'--- 共 {len(warn)} 处,请把空位挪到公式外或改用 \\underline{{\\quad}} ---') + if warn2: + print() + print('== 提示:公式内部嵌套 $(KaTeX 报错,整块露源码,需手工改)==') + for rel, ln, seg in warn2: + print(f' L{ln:<5d}{rel}') + print(f' {seg}') + print(f'--- 共 {len(warn2)} 处,请把中文挪出公式,或删掉内层 $ ---') if __name__ == '__main__': diff --git a/基于考研的学习/数学一/在学练习/大题十年考点/14-点13-线代方程组与向量.md b/基于考研的学习/数学一/在学练习/大题十年考点/14-点13-线代方程组与向量.md index 0953c62..883d803 100644 --- a/基于考研的学习/数学一/在学练习/大题十年考点/14-点13-线代方程组与向量.md +++ b/基于考研的学习/数学一/在学练习/大题十年考点/14-点13-线代方程组与向量.md @@ -25,7 +25,9 @@ $$\text{有解}\iff r(A)=r(A,B);\qquad \text{唯一解}\iff r(A)=r(A,B)=n\ (\tex 设两组基 $\alpha_1,\alpha_2,\alpha_3$ 与 $\beta_1,\beta_2,\beta_3$ ,记 $A=(\alpha_1,\alpha_2,\alpha_3)$ ,$B=(\beta_1,\beta_2,\beta_3)$ 。 -$$B=AP\ \Longrightarrow\ P=A^{-1}B\ (\text{$\alpha$ 到 $\beta$ 的过渡矩阵}).$$ +$$B=AP\ \Longrightarrow\ P=A^{-1}B$$ + +这里的 $P$ 就是 $\alpha$ 到 $\beta$ 的过渡矩阵(**从 $\alpha$ 到 $\beta$ 右乘 $P$ **,反过来则左乘 $P^{-1}$ )。 **坐标变换**:若向量 $\gamma$ 在 $\alpha$ 下坐标为 $x$ 、在 $\beta$ 下为 $y$ ,则