import re, os outdir = r'e:/Project/SI/2026_DesignAI/officefile/latex/chapters' total = 0 for fname in sorted(os.listdir(outdir)): if fname == 'ch13-conclusion.tex' or not fname.endswith('.tex'): continue fpath = os.path.join(outdir, fname) with open(fpath, 'r', encoding='utf-8') as f: content = f.read() for cmd in ['section', 'subsection', 'subsubsection']: pattern = re.compile(r'\\' + cmd + r'\{(\d+\.[^}]+)\}') matches = pattern.findall(content) for m in matches[:3]: head = m[:60] print(f' \\{cmd}{{{head}}}') if len(matches) > 3: print(f' ... and {len(matches)-3} more \\{cmd} with numbers') total += len(matches) print(f'\nTotal headings with numeric prefix: {total}')