agentleFS
NEU-ZHANEU-ZHA/legal-ai-skills/skills/legal-homework-formatter/SKILL.md

legal-homework-formatter

Skill65 starsChanged 4 months agoMITView on GitHub

用于处理中国法学作业的格式调整。当用户需要创建或修改法学作业 Word 文档,特别是涉及脚注格式、法律文件引用格式、标题格式调整、目录生成/修复时使用此 skill。必须先询问并确认姓名、学号、课程模板等个人/课程信息;不得默认填入维护者或示例个人信息。触发词:作业格式、Word格式、脚注格式、标题对齐、段落格式、目录、TOC、法学作业。

The file

Show its rules and text

We split this skill into the rules it gives an agent

60 rules. About 0 are common, 26 are distinctive, and 34 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈26

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 34

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 14
  2. Distinctive:

    Before generating a title, filename, header, or metadata, ask the user for:

    line 26
  3. Very specific:

    If the user does not provide a required identity field, use an explicit placeholder such as [待补: 姓名] or [待补: 学号] and flag it in the final …

    line 34
  4. Very specific:

    When the user asks to "strictly follow the homework skill" or provides the course reference template/PPT, apply these verified rules rather …

    line 56
  5. Distinctive:

    Use the user-provided reference template as the ZIP/DOCX base when available, not a blank document.

    line 58
  6. Very specific:

    remove <w:pStyle w:val="Heading1"/>, <w:pStyle w:val="Heading2"/>, and similar converted heading styles from manually numbered …

    line 68
  7. Very specific:

    remove <w:highlight> and <w:shd> on generated title/heading runs unless the user explicitly asks for color.

    line 71
  8. Very specific:

    run python3 scripts/fix_pandoc_heading_artifacts.py input.docx --output output.docx before the final compatibility check when the source …

    line 72
  9. Very specific:

    After running any quote normalizer, re-check footnotes: standalone curly quote runs in footnotes may accidentally inherit body size.

    line 74
  10. Very specific:

    Do not save a finished footnoted document with python-docx after manually editing footnotes unless you have verified word/footnotes.xml and …

    line 75
  11. Distinctive:

    Before writing footnote text into DOCX, strip leading/trailing whitespace from the citation payload.

    line 76
  12. Very specific:

    Do not place two footnote references back-to-back after the same sentence-final punctuation.

    line 77
  13. Very specific:

    Default fonts in docDefaults: ascii="Times New Roman" eastAsia="宋体" hAnsi="Times New Roman" cs="Times New Roman"

    line 111
  14. Very specific:

    Student information and naming fields: - ask for name (姓名), student ID (学号), and only the date/course prefix required by the current …

    line 120
  15. Distinctive:

    Use the reference template as the ZIP base.

    line 124
  16. Distinctive:

    Use pStyle="1" for 一级标题, pStyle="2" for 二级标题

    line 133
  17. Distinctive:

    Run does NOT need rPr — style provides sz=28/24 and bold

    line 134
  18. Distinctive:

    NO pStyle (inherits Normal/a: sz=21, line=300)

    line 147
  19. Very specific:

    Run rPr: only <w:rFonts w:hint="eastAsia"/> — NO explicit sz

    line 148
  20. Distinctive:

    NO pStyle, centered, sz=30 (小三号/15pt), bold

    line 187
  21. Distinctive:

    Use character style rStyle="ab" (superscript, 9pt)

    line 200
  22. Very specific:

    If preserving an existing clean template footnote, do not renumber it merely because it is ID 1.

    line 204
  23. Very specific:

    If footnote text contains Chinese quotation marks, ensure the quote runs are also 小五: <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:eastAsia="宋体"/> …

    line 228
  24. Distinctive:

    大纲/提纲: do not add a standalone outline section to the submitted document unless the assignment or user explicitly requests one

    line 237
  25. Very specific:

    Use this step when the user asks for 目录, TOC, "做目录", or when the assignment/template clearly expects a directory.

    line 241
  26. Very specific:

    Do not import a generic profile's \u switch, SDT wrapper, forced Heading1/2/3 styles, or unrelated tab-stop defaults into a homework …

    line 245
  27. Very specific:

    Use the homework template's TOC10, TOC1, TOC2, and TOC3 styles when they are available.

    line 248
  28. Very specific:

    Keep the TOC field clean, but generate static preview entries with TOC1/TOC2/TOC3 style plus a paragraph-level right-aligned dot-leader tab …

    line 252
  29. Very specific:

    Do not copy old PAGEREF _Toc...

    line 256
  30. Very specific:

    When replacing a WPS-generated TOC, follow the outer TOC complex-field depth to its matching end.

    line 257
  31. Very specific:

    Do not delete an SDT/content control merely because its visible text contains 目录.

    line 258
  32. Very specific:

    Do not set w:updateFields=true in word/settings.xml.

    line 260
  33. Very specific:

    Do not copy a whole w:sdt content-control TOC wrapper unless you have verified Word opens without repair prompts.

    line 261
  34. Very specific:

    Keep the document title and 目录 on the first page.

    line 264
  35. Very specific:

    Start the body on the next page by adding <w:pageBreakBefore/> to the first body paragraph.

    line 265
  36. Very specific:

    Avoid inserting a visible page-break run (<w:br w:type="page"/>) after the TOC because Quick Look/Word may display a stray square or layout …

    line 266
  37. Distinctive:

    Do not blindly trust existing Word styles.

    line 273
  38. Very specific:

    Do not assume that style IDs 1/2/3 always mean heading levels 1/2/3.

    line 274
  39. Very specific:

    When a confirmed heading's visible text already carries 一、, (一), or 1.

    line 275
  40. Distinctive:

    Use a double check:

    line 276
  41. Distinctive:

    If the effective outline level and text numbering agree, include it directly.

    line 277
  42. Distinctive:

    If a numbered paragraph has a corroborating heading-style name or another heading outline level but lacks the expected level, preserve its …

    line 278
  43. Distinctive:

    If a paragraph has a heading/outline style but text does not look like a heading, do not include or silently downgrade it.

    line 280
  44. Distinctive:

    If uncertain, leave it out and report it as "需人工确认标题".

    line 281
  45. Very specific:

    Do not include the document title, the 目录 title, a drafting-only 大纲/提纲, or body emphasis merely because a converter assigned it a heading …

    line 282
  46. Distinctive:

    Do not include fourth-level or lower material.

    line 283
  47. Very specific:

    Verify exactly one TOC field exists, its \o range matches the selected depth, and it does not contain \u when the document has a standalone …

    line 286
  48. Distinctive:

    Verify the document title matches the final filename basename, the TOC title and entries render black, and the TOC has no unnecessary level …

    line 287
  49. Distinctive:

    If the user will update the field in Word/WPS, verify the post-update color too.

    line 288
  50. Very specific:

    Verify PAGEREF, _Toc... anchors, and missing bookmarks are not present in the generated preview entries.

    line 289
  51. Very specific:

    Verify generated w:pPr child order, especially w:pStyle before w:pageBreakBefore, and w:tabs before w:spacing.

    line 290
  52. Very specific:

    Verify mc:Ignorable prefixes are declared and w:rPr child order is valid.

    line 291
  53. Very specific:

    Verify body footnoteReference IDs and footnote text payload are unchanged unless the task also asked for footnote work.

    line 292
  54. Distinctive:

    Do NOT use "前引" or "同上". For repeat citations in this course, use either a repeated abbreviated citation or "同前注X"/"同前注〔X〕" where helpful.

    line 337
  55. Distinctive:

    Use 参见 for indirect citations

    line 338
  56. Distinctive:

    All headings left-aligned, bold, correct sz (28/24)

    line 347
  57. Very specific:

    All footnote IDs unique; template-style regular ID 1 is valid, while generated replacement notes may safely start at 4

    line 352
  58. Distinctive:

    Use a reference template as base when provided: do not assume any private course template exists.

    line 362
  59. Distinctive:

    Body runs inherit font size from Normal: don't set sz=21 explicitly on every body run

    line 364
  60. Distinctive:

    Heading runs inherit everything from style: don't set rPr on heading runs

    line 365

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Legal Homework Formatter

Purpose

This skill provides standardized formatting workflows for Chinese legal homework assignments. It helps documents follow a user-provided course template and the Law Journal Citation Handbook, while resolving common compatibility issues between WPS and Microsoft Word.

When to Use

Use this skill when:

  • Creating new Chinese legal homework assignments in Word format
  • Formatting existing homework to meet citation standards
  • Fixing footnote display issues between WPS and Word
  • Adjusting title, heading, or citation formats
  • Generating or repairing a homework table of contents (目录/TOC)
  • Converting draft content to properly formatted legal documents

Privacy and Required Inputs

This public version must never default to the maintainer's personal information or a private course template.

Before generating a title, filename, header, or metadata, ask the user for:

  • assignment date/course prefix, only if the current instructions require one;
  • assignment number/title;
  • student name;
  • student ID, if required;
  • course or instructor-specific template, if required.

If the user does not provide a required identity field, use an explicit placeholder such as [待补: 姓名] or [待补: 学号] and flag it in the final checklist. Do not infer, reuse, or hard-code a real person's name, ID, school, email address, or local file path.

Reference Template

Use the user-provided course reference template as the base for generating homework documents when one is available. Its style system is the authoritative source for course-specific formatting. If no template is provided, create a conservative .docx with the formatting rules below and clearly tell the user which template-dependent checks could not be performed.

This public skill also includes an anonymized fallback template at:

assets/legal-homework-template-anonymized.docx

Use it when the user needs a working Word style base but has not provided a private course template. The template keeps the formatting structure while replacing identity fields with [日期], [序号], [姓名], and [学号]. Do not rename it to a private course filename when publishing or redistributing the skill.

For a user-facing material checklist and missing-information workflow, read:

references/user_materials_guide.md

Lessons From the 2026-05-13 Homework Formatting Pass

When the user asks to "strictly follow the homework skill" or provides the course reference template/PPT, apply these verified rules rather than relying on generic python-docx defaults:

  • Use the user-provided reference template as the ZIP/DOCX base when available, not a blank document.
  • Match the course PPT's "三名同一" rule: email subject, attachment file name, and document title should be identical.
  • Derive the title pattern from the current assignment or instructor instructions. Do not carry a date prefix or graded homework N wording from an older course merely because it appears in a reused template. If the user supplies the intended filename, use its basename as the document title unless the current assignment requires a different title.
  • Main title: 小三, centered, no first-line indent, spacing after="156", split the title into runs so Chinese name and hyphens render in 宋体 while English/date/student ID render in Times New Roman.
  • Body paragraphs: 五号, 宋体/Times New Roman, first-line indent 420 twips, line spacing 300 (1.25x), paragraph after 156 twips, justified alignment.
  • Paragraph-after unit check: w:after="156" is stored in OOXML twips, equal to 7.8 pt because Word uses twentieths of a point. In the civil-law reference template this corresponds to half of the document grid line pitch (docGrid linePitch="312"), so Word/WPS may display the same setting as about 0.5 行 or 7.8 磅 depending on UI/context. Treat these as equivalent, not conflicting.
  • Footnotes: 小五, 宋体/Times New Roman, single line spacing, left aligned, no first-line indent, no paragraph spacing before/after.
  • Footnote numbering: remove <w:numRestart w:val="eachPage"/> from word/settings.xml and any section-level footnotePr; homework footnotes should number continuously across the whole document. The reference template contains eachPage, but that setting causes duplicate-looking footnote numbers page by page.
  • If a heading already contains a manual Chinese prefix such as 一、 or (一), suppress any inherited automatic numbering on that confirmed paragraph (for example, direct <w:numPr><w:numId w:val="0"/></w:numPr>). Preserve its existing paragraph style. Do not globally rewrite styles 1/2/3 merely by numeric ID: WPS may renumber style IDs, and the same style may still be needed by genuinely auto-numbered paragraphs.
  • If the document was generated from Markdown/Pandoc or any converter that applies Word Heading1/Heading2 styles, do not only override run fonts and sizes. Also remove inherited heading paragraph styles and decorations from the final document, or Word may still render blue/green heading colors and automatic bullets/numbering:
    • remove <w:pStyle w:val="Heading1"/>, <w:pStyle w:val="Heading2"/>, and similar converted heading styles from manually numbered titles/headings;
    • during artifact cleanup, remove converter-generated direct <w:numPr> from titles/headings. After assigning the final course style/outline, a confirmed manually numbered heading must end with direct w:numId=0 if its retained style inherits automatic numbering; cleanup is not the final numbering state;
    • clear run-level <w:color> values inherited from styles/themes, especially w:themeColor, then set direct black color <w:color w:val="000000"/>;
    • remove <w:highlight> and <w:shd> on generated title/heading runs unless the user explicitly asks for color.
    • run python3 scripts/fix_pandoc_heading_artifacts.py input.docx --output output.docx before the final compatibility check when the source DOCX came from Pandoc/Markdown. This bug appeared in a 2026-05-27 Word check: Pandoc's heading style survived OOXML post-processing, so Word displayed the main title and headings in blue-green and with black bullet markers even though font/size had been overwritten.
  • After running any quote normalizer, re-check footnotes: standalone curly quote runs in footnotes may accidentally inherit body size. Force footnote quote runs (“”‘’) back to 小五 (w:sz=18) and 宋体.
  • Do not save a finished footnoted document with python-docx after manually editing footnotes unless you have verified word/footnotes.xml and footnoteReference markers are preserved. Prefer ZIP/XML surgery for final footnote and quote fixes.
  • Before writing footnote text into DOCX, strip leading/trailing whitespace from the citation payload. The template may use one normal delimiter space after the footnote number, but the citation text itself must not start with an extra blank.
  • Do not place two footnote references back-to-back after the same sentence-final punctuation. If multiple sources support the same claim, combine them in one footnote separated by ;; if they support different clauses, place each marker after its own clause or legal article.
  • The homework template may include Chinese TOC styles. To add a directory, use the template's TOC styles and a clean Word field, but do not copy dirty old preview entries such as PAGEREF _Toc....
  • For Word compatibility, do not set <w:updateFields w:val="true"/> just to force TOC updates. Word will show a field-update prompt. Also avoid copying a template's whole w:sdt TOC content-control shell into generated files unless you have verified Word opens without repair prompts. Prefer clean ordinary TOC field paragraphs plus static preview entries.
  • Preserve WordprocessingML child order in generated paragraph properties. Word may show "unreadable content" even when ZIP/XML parsing succeeds if, for example, w:spacing appears before w:tabs in a TOC entry or w:pageBreakBefore is inserted before w:pStyle.
  • Homework TOC layout: the document title and 目录 stay on the first page; the main body starts on the next page by setting w:pageBreakBefore on the first body paragraph, not by inserting a visible <w:br w:type="page"/>.
  • Heading detection for TOC must use both style and text structure. Existing styles 1/2/3 are strong clues but not always trustworthy because users often hand-format titles. Confirm with text patterns like 一、, (一), and 1. before including a paragraph in the TOC.

Style System (OOXML Reference)

Based on the reference template's styles.xml:

Paragraph Styles

styleIdNamesz (半磅)对应中文BoldOther
aNormal21 (五号/10.5pt)正文Noline=300 (1.25倍), after=50, firstLine=200, widowControl=0, adjustRightInd=0, snapToGrid=0
1heading 128 (四号/14pt)一级标题YeskeepNext, keepLines, numPr (auto "一、")
2heading 224 (小四号/12pt)二级标题YeskeepNext, keepLines, numPr (auto "(一)")
3heading 321 (五号)三级标题YeskeepNext, keepLines
a7footnote text18 (小五号/9pt)脚注文本Noline=240 (单倍), left aligned
TOC10TOC 标题128 (四号/14pt)目录标题Nocentered, black
TOC1toc 121/22-ish一级目录项Noright tab with dot leader when generated
TOC2toc 221/22-ish二级目录项Noindented TOC item
TOC3toc 321/22-ish三级目录项Nofurther indented TOC item

Character Styles

styleIdNamePurpose
abfootnote referenceSuperscript footnote markers (上标)

docDefaults

  • sz=21 (五号/10.5pt), szCs=22 (default paragraph-level rPr)
  • Default fonts in docDefaults: ascii="Times New Roman" eastAsia="宋体" hAnsi="Times New Roman" cs="Times New Roman"
  • These are explicit font names, NOT theme font references (minorHAnsi/minorEastAsia)

Document Generation Workflow

Step 1: Gather Required Materials

  1. Homework questions (PDF/DOCX) - assignment requirements
  2. Reference template - user-provided formatting base, if required by the course
  3. Student information and naming fields - ask for name (姓名), student ID (学号), and only the date/course prefix required by the current assignment; use [待补: ...] placeholders if a required field is missing

Step 2: Build Document Using Reference Template

Use the reference template as the ZIP base. Key principles:

Heading paragraphs (一级标题 like "一、XXX"):

<w:p>
  <w:pPr><w:pStyle w:val="1"/><w:spacing w:after="156"/></w:pPr>
  <w:r><w:t xml:space="preserve">一、菜单案</w:t></w:r>
</w:p>
  • Use pStyle="1" for 一级标题, pStyle="2" for 二级标题
  • Run does NOT need rPr — style provides sz=28/24 and bold
  • IMPORTANT: For a paragraph whose visible text already includes manual numbering, suppress inherited numbering directly on that paragraph while preserving its style. Modify a whole heading style only when the template proves that every paragraph using it is manually numbered.

Body paragraphs (正文):

<w:p>
  <w:pPr><w:spacing w:line="300" w:lineRule="auto" w:after="156"/>
    <w:ind w:firstLine="420"/><w:jc w:val="both"/></w:pPr>
  <w:r><w:rPr><w:rFonts w:hint="eastAsia"/></w:rPr>
    <w:t xml:space="preserve">正文内容...</w:t>
  </w:r>
</w:p>
  • NO pStyle (inherits Normal/a: sz=21, line=300)
  • Run rPr: only <w:rFonts w:hint="eastAsia"/> — NO explicit sz
  • Bold body runs: add <w:b/><w:bCs/> to rPr
  • First-line indent: 420 twips (≈2 chars)
  • Paragraph after: use 156 twips for generated homework body paragraphs. Although Normal style may show after=50, the course reference template's actual filled body paragraphs use after=156, and this is the safer value for submitted homework.
  • Alignment: set <w:jc w:val="both"/> explicitly to avoid Word/WPS drift.

Document title (split into multiple runs, hyphen in 宋体 font):

<w:p>
  <w:pPr>
    <w:spacing w:after="156"/>
    <w:ind w:firstLineChars="0" w:firstLine="0"/>
    <w:jc w:val="center"/>
    <w:rPr><w:sz w:val="30"/><w:szCs w:val="30"/></w:rPr>
  </w:pPr>
  <!-- 文字 run:hint eastAsia -->
  <w:r><w:rPr><w:rFonts w:hint="eastAsia"/><w:sz w:val="30"/>
    <w:szCs w:val="30"/><w:b/><w:bCs/></w:rPr>
    <w:t xml:space="preserve">当前作业要求的标题前缀</w:t></w:r>
  <!-- 连字符 run:显式 宋体 -->
  <w:r><w:rPr><w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:cs="宋体"
    w:hint="eastAsia"/><w:sz w:val="30"/><w:szCs w:val="30"/>
    <w:b/><w:bCs/></w:rPr>
    <w:t xml:space="preserve">-</w:t></w:r>
  <!-- 姓名 run -->
  <w:r><w:rPr><w:rFonts w:hint="eastAsia"/><w:sz w:val="30"/>
    <w:szCs w:val="30"/><w:b/><w:bCs/></w:rPr>
    <w:t xml:space="preserve">[待补: 姓名]</w:t></w:r>
  <!-- 连字符 run -->
  <w:r><w:rPr><w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:cs="宋体"
    w:hint="eastAsia"/><w:sz w:val="30"/><w:szCs w:val="30"/>
    <w:b/><w:bCs/></w:rPr>
    <w:t xml:space="preserve">-</w:t></w:r>
  <!-- 学号 run -->
  <w:r><w:rPr><w:rFonts w:hint="eastAsia"/><w:sz w:val="30"/>
    <w:szCs w:val="30"/><w:b/><w:bCs/></w:rPr>
    <w:t xml:space="preserve">[待补: 学号]</w:t></w:r>
</w:p>
  • NO pStyle, centered, sz=30 (小三号/15pt), bold
  • A date prefix is conditional, not universal. If the current course requires one, ask whether it represents the release date, due date, or another value instead of guessing.
  • IMPORTANT: Hyphen "-" must be in its own run with explicit 宋体 font (ascii/hAnsi/cs all set to "宋体")
  • IMPORTANT: pPr must include <w:ind w:firstLineChars="0" w:firstLine="0"/> and <w:rPr> block
  • Split the title into the runs needed by the current naming pattern. A prefix-name-ID pattern commonly uses five runs: prefix, hyphen, name, hyphen, student ID.

Footnote references (in body text):

<w:r>
  <w:rPr><w:rStyle w:val="ab"/></w:rPr>
  <w:footnoteReference w:id="4"/>
</w:r>
  • Use character style rStyle="ab" (superscript, 9pt)
  • Each footnoteReference must have a UNIQUE ID
  • The course reference template uses separator IDs -1 and 0; its sample regular footnote uses ID 1.
  • Starting newly generated footnotes at 4 is a conservative compatibility strategy for programmatic generation/repair, not a template requirement. It avoids collisions with legacy or AI-generated documents that misuse low IDs for separators or ordinary notes.
  • If preserving an existing clean template footnote, do not renumber it merely because it is ID 1; only ensure every footnoteReference has a matching footnote definition.

Footnote definitions (in footnotes.xml):

<w:footnote w:id="4">
  <w:p>
    <w:pPr>
      <w:pStyle w:val="a7"/>
      <w:spacing w:before="0" w:after="0" w:line="240" w:lineRule="auto"/>
      <w:ind w:left="0" w:right="0" w:firstLine="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r><w:rPr><w:rStyle w:val="ab"/></w:rPr><w:footnoteRef/></w:r>
    <w:r><w:t xml:space="preserve"> </w:t></w:r>
    <w:r><w:rPr><w:rFonts w:hint="eastAsia"/></w:rPr>
      <w:t xml:space="preserve">《民法典》第X条。</w:t>
    </w:r>
  </w:p>
</w:footnote>
  • Paragraph style: pStyle="a7" (sz=18/小五号, line=240/单倍)
  • footnoteRef: rStyle="ab" (superscript)
  • Text runs: only <w:rFonts w:hint="eastAsia"/>, sz=18 from a7 style
  • Separator: w:id="-1" (separator), w:id="0" (continuationSeparator)
  • If footnote text contains Chinese quotation marks, ensure the quote runs are also 小五: <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:eastAsia="宋体"/> plus <w:sz w:val="18"/>.
  • Nested Chinese quotation marks should be outer double and inner single, e.g. “违反‘打黑工’禁令的合同”.

Step 3: Heading Hierarchy

  • 文档主标题(居中): follow the current assignment's user-confirmed pattern; use placeholders for missing identity fields and do not default to a naming example from another course
  • 一级标题(左对齐): 一、XXX, 二、XXX, 四号, pStyle="1"
  • 二级标题(左对齐): (一)XXX, (二)XXX, 小四号, pStyle="2"
  • 三级标题及以下: 五号, pStyle="3"
  • 大纲/提纲: do not add a standalone outline section to the submitted document unless the assignment or user explicitly requests one

Step 4: Homework Table of Contents (目录)

Use this step when the user asks for 目录, TOC, "做目录", or when the assignment/template clearly expects a directory.

Authority and scope

  • This section is the canonical TOC profile for Chinese legal homework. If it conflicts with a generic Word-TOC workflow, this section controls.
  • Do not import a generic profile's \u switch, SDT wrapper, forced Heading1/2/3 styles, or unrelated tab-stop defaults into a homework document.

Core strategy

  • Use the homework template's TOC10, TOC1, TOC2, and TOC3 styles when they are available.
  • Choose the TOC depth deliberately. For an ordinary short homework, default to levels 1-2; include level 3 only when it represents a genuinely independent heading and the document, template, instructor, or user needs that detail.
  • Insert a clean ordinary Word TOC complex field matching the selected depth, normally TOC \o "1-2" \h \z; use TOC \o "1-3" \h \z only when level 3 is justified. Do not use \u when the document has a standalone title.
  • Generate static preview TOC entries from detected headings; Word/WPS can later update page numbers.
  • Keep the TOC field clean, but generate static preview entries with TOC1/TOC2/TOC3 style plus a paragraph-level right-aligned dot-leader tab stop at w:pos="8296". Some templates have TOC2/TOC3 indentation but no dot-leader tab, which makes preview page numbers appear beside the heading until Word updates the field.
  • Force the 目录 heading and all visible TOC entry/page-number runs to black (w:color="000000"), clearing theme or hyperlink-blue color inheritance. Verify the rendered first page rather than trusting the style name alone.
  • The \h switch is optional. If Word/WPS turns entries blue after "更新目录", rerun the helper with --no-hyperlinks rather than recoloring the document-wide Hyperlink character style; this preserves unrelated links.
  • Preserve untouched DOCX parts byte-for-byte when possible. If the document already has required TOC/heading styles and no updateFields, avoid rewriting unrelated parts.
  • Do not copy old PAGEREF _Toc... preview entries from a template; they may refer to missing bookmarks and produce Word errors.
  • When replacing a WPS-generated TOC, follow the outer TOC complex-field depth to its matching end. Do not stop at the first w:fldCharType="end"; each visible entry may contain nested HYPERLINK and PAGEREF fields with their own end markers.
  • Do not delete an SDT/content control merely because its visible text contains 目录; require a real TOC field instruction or a Table of Contents gallery marker.
  • Fail closed if ordinary body content or non-paragraph content appears before the supposed outer TOC end. Never guess the boundary or delete through the remainder of the document.
  • Do not set w:updateFields=true in word/settings.xml; it causes Word to ask whether to update fields.
  • Do not copy a whole w:sdt content-control TOC wrapper unless you have verified Word opens without repair prompts. A plain TOC field is safer.

TOC page layout

  • Keep the document title and 目录 on the first page.
  • Start the body on the next page by adding <w:pageBreakBefore/> to the first body paragraph.
  • Avoid inserting a visible page-break run (<w:br w:type="page"/>) after the TOC because Quick Look/Word may display a stray square or layout artifact.

Heading detection and repair

  • TOC levels map to common template styles:
    • 一、..., 二、... -> heading style 1 -> TOC1
    • (一)..., (二)... -> heading style 2 -> TOC2
    • independent 1. ..., 2. ... -> heading style 3 -> TOC3
  • Do not blindly trust existing Word styles. Users often hand-format headings, and converted documents may misuse styles.
  • Do not assume that style IDs 1/2/3 always mean heading levels 1/2/3. WPS may renumber style IDs (for example, 1 may be Normal). Match by visible numbering plus effective outline level/style name, and preserve the existing paragraph style when adding a direct outline level.
    • When a confirmed heading's visible text already carries 一、, (一), or 1. numbering, also suppress inherited automatic numbering at paragraph level so Word/WPS cannot display a doubled prefix; do not strip the paragraph style.
  • Use a double check:
    • If the effective outline level and text numbering agree, include it directly.
    • If a numbered paragraph has a corroborating heading-style name or another heading outline level but lacks the expected level, preserve its current style and add the direct outline level needed by the TOC.
    • A short 一、 / (一) / 1. prefix alone is not enough: an ordinary numbered list can look identical. Without corroborating style/outline or explicit template/user evidence, leave it unchanged and report it for confirmation.
    • If a paragraph has a heading/outline style but text does not look like a heading, do not include or silently downgrade it; leave it unchanged and report it for confirmation.
    • If uncertain, leave it out and report it as "需人工确认标题".
  • Do not include the document title, the 目录 title, a drafting-only 大纲/提纲, or body emphasis merely because a converter assigned it a heading style.
  • Do not include fourth-level or lower material. When the selected depth is 1-2, exclude level 3 even if it has a heading style.

Validation

  • Verify exactly one TOC field exists, its \o range matches the selected depth, and it does not contain \u when the document has a standalone title.
  • Verify the document title matches the final filename basename, the TOC title and entries render black, and the TOC has no unnecessary level or standalone outline entry.
  • If the user will update the field in Word/WPS, verify the post-update color too; use the non-hyperlinked field when the app reapplies blue hyperlink styling.
  • Verify PAGEREF, _Toc... anchors, and missing bookmarks are not present in the generated preview entries.
  • Verify generated w:pPr child order, especially w:pStyle before w:pageBreakBefore, and w:tabs before w:spacing.
  • Verify mc:Ignorable prefixes are declared and w:rPr child order is valid. Running docx_compat_check.py is useful; a repaired Word sample should not have undefined-prefix or rFonts ordering errors.
  • Verify body footnoteReference IDs and footnote text payload are unchanged unless the task also asked for footnote work. Byte-for-byte word/footnotes.xml equality may change if namespace prefixes are normalized to satisfy Word.
  • Open in Word as well as WPS when possible. If Word reports "unreadable content", first check mc:Ignorable undefined prefixes, w:rPr order, and w:pPr child order, then rebuild the TOC as clean plain field paragraphs and remove updateFields.

For a deterministic helper, use:

python3 scripts/add_homework_toc.py input.docx template.docx output.docx

The helper defaults to --max-level 2; pass --max-level 3 only when the third level is justified. Use --no-hyperlinks if a Word/WPS field update makes TOC entries blue.

Lessons From the 2026-06-09 TOC Regression Test

A regression test found that an automatically generated static TOC preview could differ from the TOC after Word updated the field: level-2 page numbers appeared immediately after the heading text instead of right-aligned with dot leaders. The cause was that the template's TOC2/TOC3 styles carried indentation but no right-aligned dot-leader tab. Word adds or normalizes the tab stop when the field is updated, so a static preview must add it explicitly.

Current TOC generation rule:

  • Insert one clean TOC field for the selected depth (normally levels 1-2), but do not set updateFields=true.
  • For every static preview entry, set TOC1/TOC2/TOC3 style and a paragraph-level right-aligned dot-leader tab stop at w:pos="8296".
  • Preserve level indentation: TOC2 uses w:left="420" / w:leftChars="200"; TOC3 uses w:left="840" / w:leftChars="400".
  • Normalize w:pPr child order automatically. Old or generated homework files may have w:ind before w:spacing; the helper must reorder rather than fail.
  • Validation target: generated preview should visually resemble the Word-updated TOC, while real page numbers may still require manual field update in Word.

Step 5: Legal Citation Format

脚注必要性原则:

  • 正文已完整引用法条原文 + 脚注无进一步说明 → 不设脚注(脚注无增量信息)
  • 正文仅提法条编号未引原文 → 设脚注,并附法条全文(这是课程助教明确提示过的点)
  • 同一法条多次出现:首次正文未引全文处设脚注(含全文);后续可不重复设注、重复简称条号,或在确有必要时写 同前注1 / 同前注〔1〕
  • 直接引用原文:正文加引号,脚注通常不用"参见"
  • 概括、转述、借鉴观点:脚注用"参见"
  • 法条脚注中若写第X条规定,...,必须先判断后文是不是官方原文:原文用规定:“……”;概括转述改成依/根据/参见第X条,可以说明……,不要把 AI 概括写成疑似法条原文
  • 引注标号位置:若引注支持整句,标号置于句末标点之后;若只支持句中某一词组或法条名称,标号紧随该引用对象之后
  • 脚注功能分离:不要为了减少脚注数量,把“案例出处”和“法条/司法解释依据”合并进同一个脚注;也不要把两个不同法条的全文塞进同一脚注。一个脚注原则上只服务一个引用点或同一命题下的同类来源。若正文已经概括或直接摘引法条内容,脚注可保留为简洁出处;若正文只写条号而未说明内容,再在脚注补足条文原文。

First citation: Full name + abbreviation in footnote

《中华人民共和国民法典》(以下简称《民法典》)第142条第1款。

Subsequent citations: Abbreviation only

《民法典》第147条。

Key rules:

  • Do NOT use "前引" or "同上". For repeat citations in this course, use either a repeated abbreviated citation or "同前注X"/"同前注〔X〕" where helpful.
  • Use 参见 for indirect citations
  • Statute numbers: Arabic numerals (第142条, not 第一百四十二条)
  • Case citations: full name on first use, full footnote format
  • 司法解释: single书名号 〈〉 inside double for nested references

Step 6: Verify Formatting

Checklist:

  1. Title format: current assignment naming convention, identical to final filename basename, correct identity fields or explicit placeholders, centered, sz=30
  2. All headings left-aligned, bold, correct sz (28/24)
  3. Body text: sz=21 (五号), firstLine indent, line=300 (1.25倍)
  4. Body paragraphs: spacing after=156 twips, justified
  5. Footnotes: sz=18 (小五号), single spacing, left aligned, no first-line indent, no before/after spacing, rStyle="ab" for markers
  6. Footnote quote runs: all “”‘’ in footnotes are 宋体 and sz=18
  7. All footnote IDs unique; template-style regular ID 1 is valid, while generated replacement notes may safely start at 4
  8. Heading styles do not auto-number if headings are manually numbered
  9. TOC requested: selected depth is justified, title and entries are black, clean TOC field has no \u for a standalone title, no drafting-only outline entry, right-aligned dot leaders on preview entries, no stale PAGEREF _Toc... references
  10. Citation placement: no adjacent footnote references at the same sentence-final position; same-claim multiple sources are bundled with semicolons
  11. Footnote text payloads: no leading/trailing whitespace beyond the normal delimiter after the footnote number
  12. Page numbers: bottom center when required by assignment length
  13. Open in both WPS and Word to verify

Important Notes

  1. Use a reference template as base when provided: do not assume any private course template exists.
  2. Do NOT use pStyle="1" from old assignment templates: old templates may have different style sizes (sz=44 instead of sz=28)
  3. Body runs inherit font size from Normal: don't set sz=21 explicitly on every body run
  4. Heading runs inherit everything from style: don't set rPr on heading runs
  5. rStyle for footnote reference is "ab": not "17" (old template) or "aa" (Hyperlink)
  6. Each footnoteReference needs a unique ID: Word renders only the first occurrence of each ID
  7. Template footnote IDs are -1/0/1: separators are -1 and 0; ID 1 is a valid regular footnote in the course template
  8. Use ID 4+ only as a safe generation convention: helpful when replacing all notes or repairing documents created by other tools, but not required by OOXML or the course template
  9. Suppress inherited numbering on confirmed manually numbered heading paragraphs: preserve their paragraph styles, and avoid global edits based only on numeric style IDs
  10. Remove each-page footnote restart: the course template may contain <w:numRestart w:val="eachPage"/>; delete it for continuous homework footnotes
  11. TOC static preview is not the authority for final page numbers: generate a clean preview with dot leaders, then let Word update the field for final pagination
  12. Run the compatibility check after footnotes: docx_compat_check.py warns about adjacent footnote references and footnote text that starts with an extra blank
  13. Verify in both WPS and Word: these applications handle certain features differently

Bundled Resources

Scripts

  • scripts/add_footnotes.py: Footnote automation utilities
  • scripts/add_homework_toc.py: add or rebuild a clean Word-compatible homework TOC with right-aligned dot leaders
  • scripts/test_add_homework_toc.py: regression tests for WPS nested/static TOC cleanup, manual-numbering suppression, and field switches; run with python3 -m unittest -v scripts/test_add_homework_toc.py from the skill directory
  • scripts/fix_pandoc_heading_artifacts.py: remove Pandoc/Word Heading1/Heading2/Title styles, theme colors, highlighting, shading, and auto-numbering from homework titles/headings
  • scripts/docx_compat_check.py: final Word/WPS compatibility check, including stale namespace and Pandoc heading-style warnings

References

  • references/format_requirements.md: Comprehensive formatting requirements

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.