d4665a362e
- 新增 officefile/latex/ 目录,包含 main.tex、preamble.tex 及 14 个章节 + 10 个附录 tex 文件 - md→tex 转换流程:pandoc 转换 + _postprocess.py 后处理(去编号、修破折号、清标签) - 修复 5 个 md 源文件的标题层级(H1→H2 降级,统一层级结构) - 配置 VS Code LaTeX Workshop(xelatex + ctexbook 编译链) - 新增 VS Code workspace 和 .gitignore(排除 LaTeX 编译产物) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import os
|
|
|
|
outdir = os.path.join(os.path.dirname(__file__), 'chapters')
|
|
for fname in sorted(os.listdir(outdir)):
|
|
if not fname.endswith('.tex'):
|
|
continue
|
|
fpath = os.path.join(outdir, fname)
|
|
with open(fpath, 'r', encoding='utf-8') as fh:
|
|
content = fh.read()
|
|
lines = content.split('\n')
|
|
prev_cmd = ''
|
|
prev_title = ''
|
|
for i, line in enumerate(lines):
|
|
s = line.strip()
|
|
matched = None
|
|
for cmd in ['\\chapter{', '\\section{', '\\subsection{', '\\subsubsection{']:
|
|
if s.startswith(cmd):
|
|
matched = cmd
|
|
break
|
|
if matched:
|
|
# Check for level jumps (skip of 1 or more intermediate levels)
|
|
levels = {'\\chapter{': 0, '\\section{': 1, '\\subsection{': 2, '\\subsubsection{': 3}
|
|
if prev_cmd and matched in levels and prev_cmd in levels:
|
|
jump = levels[matched] - levels[prev_cmd]
|
|
if jump > 1:
|
|
title = s[len(matched):-1]
|
|
print(f'{fname}:{i+1}: {prev_cmd.replace("{","")} -> {matched.replace("{","")} ({jump} levels): {title[:60]}')
|
|
prev_cmd = matched
|