Update a thesis master .docx directly from revised Markdown chapters while preserving the document's existing heading and paragraph style system as much as possible. Use this skill when Codex needs to inspect a Word thesis outline, locate a chapter or section by heading text, and sync Markdown content back into the target .docx without manually copy-pasting into Word. Use only for .docx workflows; convert legacy .doc first.
Sync one heading-bounded section of a thesis .docx from Markdown instead of manually copying revised chapter text back into Word.
Keep the workflow narrow and safe: inspect the Word outline, target one existing heading, render Markdown with pandoc --reference-doc, and replace only that XML block inside the master document.
.docx, not legacy .doc.python skills/thesis-docx-sync/scripts/dump_docx_outline.py path/to/master.docx
--drop-leading-heading so the temporary sync file is still produced entirely by Python instead of manual editing. Keep the temporary file near the source chapter files so relative image paths still resolve:python skills/thesis-docx-sync/scripts/build_markdown_chapter.py ^
--output writing/_chapter4_sync_tmp.md ^
--title "Chapter 4 Title" ^
--rewrite-rules skills/thesis-docx-sync/references/thesis_word_rewrites.json ^
writing/chapter4_4.1.md ^
writing/chapter4_4.2.md ^
writing/chapter4_4.3.md ^
writing/chapter4_4.4.md
For a single source chapter file:
python skills/thesis-docx-sync/scripts/build_markdown_chapter.py ^
--output writing/_chapter2_sync_tmp.md ^
--title "第二章 等离子体电磁特性与LFMCW诊断机理" ^
--drop-leading-heading ^
--shift-headings 0 ^
--rewrite-rules skills/thesis-docx-sync/references/thesis_word_rewrites.json ^
writing/第2章_等离子体电磁特性与LFMCW诊断机理_final.md
For front matter, always build a temporary sync file instead of syncing the raw source Markdown directly:
python skills/thesis-docx-sync/scripts/build_markdown_chapter.py ^
--output writing/_thanks_sync_tmp.md ^
--title "致谢" ^
--shift-headings 0 ^
writing/致谢.md
python skills/thesis-docx-sync/scripts/build_markdown_chapter.py ^
--output writing/_author_bio_sync_tmp.md ^
--title "作者简介" ^
--drop-leading-heading ^
--shift-headings 0 ^
--demote-headings-to-strong 2,3 ^
writing/作者简介.md
For 作者简介, do not map ## / ### to Word heading styles. The thesis template's Heading 5/6 numbering belongs to the body chapters and will turn manual items such as 1. 基本情况 into chapter-style numbers such as 6.4.
For 致谢 and 作者简介, explicitly cross-check the canonical reference pair under resources/word2md/:
基于线性调频连续波的等离子体诊断系统设计-终稿-曹杠.docx基于线性调频连续波的等离子体诊断系统设计-终稿-曹杠.md
Treat them as the style authority for these two front-matter sections. The target output should preserve the same front-matter role split: a visible top title using the non-numbered title style, followed by body content / subordinate items that visually match the reference thesis rather than inheriting live chapter numbering from the current working DOCX.final_output_doc, which flags risky inline math and forbidden helper assets:python skills/thesis-docx-sync/scripts/preflight_markdown_sync.py ^
--markdown writing/_chapter4_sync_tmp.md ^
--profile final_output_doc ^
--fail-on-warning
.docx is an old template, verify the target block by position and neighboring chapter headings, not by chapter number alone. Do not assume the requested Markdown chapter maps to the current fourth Heading 1 in Word.python skills/thesis-docx-sync/scripts/sync_markdown_to_docx.py ^
--docx path/to/master.docx ^
--markdown path/to/chapter.md ^
--match-heading "Target Heading" ^
--level 1 ^
--missing-images placeholder ^
--output path/to/master_synced.docx
python skills/thesis-docx-sync/scripts/postprocess_styles.py ^
--docx path/to/master_synced.docx ^
--in-place
temp_outline.txt) created during the workflowbuild_markdown_chapter.py (e.g., writing/正式参考文献版/_chapter3_sync_tmp.md)versions/final_name.bak-*.docx)sync_markdown_to_docx.py, postprocess_styles.py, update_cover_info.py, or fix_header_borders.py backup DOCX files in versions/ once the final output has been verified*.bak-*.docx set封面信息.md, update the working DOCX cover after the section sync:python skills/thesis-docx-sync/scripts/update_cover_info.py ^
--docx path/to/master_synced.docx ^
--cover-markdown writing/正式参考文献版/封面信息.md
When the thesis has switched to another official cover variant, replace the cover/title-page block from the canonical template before filling metadata:
python skills/thesis-docx-sync/scripts/update_cover_info.py ^
--docx path/to/master_synced.docx ^
--cover-markdown writing/正式参考文献版/封面信息.md ^
--cover-template-docx writing/2、西安电子科技大学专业学位硕士学位论文封面及中英文题名页模板(2015年版)-2022.11修订.docx
For this thesis repository, when 封面信息.md states 申请学位类别:工程硕士 or otherwise indicates the professional-degree cover, treat the first 7 pages as a special front-matter block: replace them from the official professional-master template first, then fill the metadata fields. Do not keep the academic-master front pages from resources/word2md/ in that case.
If Word is locking the target output during cover replacement, write to a new filename first (for example versions/codexv1_engineering_cover.docx), then overwrite the canonical working file only after the user closes the locked document.
.docx as the layout authority.--reference-doc against the target .docx or a style-identical template so pandoc emits compatible heading and paragraph styles.figures/....resources/word2md/ as the layout mother file when front-matter headers, section breaks, TOC pages, and page styles must match the school template exactly.preflight_markdown_sync.py before every real sync when the chapter contains figures or dense math..md file. Do not restrict images to a single canonical directory.sync_fig*.png or _preview_*.png inside figure directories. Temporary conversions, previews, and staged copies must live under a temp directory only.$d\tau_g/df$, $2\pi B/T_m$, or $d(f_p/f)^2/(2c)$ when that improves Word readability.skills/thesis-docx-sync/references/thesis_word_rewrites.json as the first pass for Word readability rewrites; extend that file when the same pattern recurs.\frac, \dfrac, \underbrace, \left...\right, or long nested expressions inside inline math when a simpler body-text form is available.第二章, 2.1, or 2.4.1 before rendering when the target Word template already applies automatic heading numbering.CRITICAL: Figure and table captions must NOT include number prefixes.
The Word template's 标题-图 and 标题-表格 styles apply automatic numbering (图3.1, 表4.2, etc.). If the Markdown caption also includes the number, the output will show duplicated numbering like "图3.1 图3.1 caption text".
 — not caption text on the line before the table — not 表4.1 caption text**表4.2 title** must also be stripped to just title参考文献.md must have a heading.
The file writing/参考文献.md must start with # 参考文献 on the first line. Without it, the sync script replaces the heading text in Word with the first reference entry.
Complex inline math may be invisible in Word.
Inline math ($...$) containing \frac, \sqrt, or \boxed may render as invisible zero-height OMML in Word. Before sync:
$$...$$)$\frac{a}{b}$ → $a/b$\boxed{} from any formula (use plain display math instead)python skills/thesis-docx-sync/scripts/dump_docx_outline.py path/to/master.docx
python skills/thesis-docx-sync/scripts/build_markdown_chapter.py ^
--output path/to/chapter_merged.md ^
--title "Chapter Title" ^
--rewrite-rules skills/thesis-docx-sync/references/thesis_word_rewrites.json ^
path/to/section1.md ^
path/to/section2.md
python skills/thesis-docx-sync/scripts/preflight_markdown_sync.py ^
--markdown path/to/chapter_merged.md ^
--profile final_output_doc ^
--fail-on-warning
python skills/thesis-docx-sync/scripts/sync_markdown_to_docx.py ^
--docx path/to/master.docx ^
--markdown path/to/chapter.md ^
--match-heading "Target Heading" ^
--level 1 ^
--missing-images placeholder ^
--output path/to/master_synced.docx
python skills/thesis-docx-sync/scripts/postprocess_styles.py ^
--docx path/to/synced.docx ^
--in-place
python skills/thesis-docx-sync/scripts/postprocess_styles.py ^
--docx path/to/synced.docx ^
--no-headers ^
--in-place
python skills/thesis-docx-sync/scripts/fix_header_borders.py ^
--docx path/to/synced.docx ^
--in-place
作者简介 paragraph styles from the reference thesis:python skills/thesis-docx-sync/scripts/apply_reference_author_bio_style.py ^
--docx path/to/synced.docx ^
--reference-docx resources/word2md/基于线性调频连续波的等离子体诊断系统设计-终稿-曹杠.docx ^
--in-place
python skills/thesis-docx-sync/scripts/set_math_font.py ^
--docx path/to/synced.docx ^
--font "Times New Roman" ^
--in-place
Times New Roman (preferred over set_math_font.py):python skills/thesis-docx-sync/scripts/force_math_font_tnr.py ^
--docx path/to/synced.docx ^
--in-place
python skills/thesis-docx-sync/scripts/strip_symbol_table_units.py ^
--docx path/to/synced.docx ^
--in-place
scripts/dump_docx_outline.py to discover stable anchors before any edit.scripts/build_markdown_chapter.py when one logical chapter is stored as several Markdown files.scripts/preflight_markdown_sync.py to catch off-policy image paths and inline-math readability risks before rendering.scripts/sync_markdown_to_docx.py for section replacement.scripts/docx_figure_catalog.py to inspect which figure numbers a source DOCX can provide before relying on DOCX-backed image fallback.scripts/postprocess_styles.py after every sync — it is the single comprehensive post-processor that handles style remapping, caption detection, table formatting (三线表), image layout, and page headers.scripts/update_cover_info.py when the thesis keeps cover metadata in Markdown and the target DOCX cover/front-matter must be refreshed together with the body chapters.scripts/fix_header_borders.py after any sync or cover replacement if page headers lose their bottom border line. The thesis template defines a double bottom border on the header style (style-id ae); pandoc or manual editing may reset header paragraphs to a4 (Normal Indent) which lacks the border.scripts/apply_reference_author_bio_style.py after postprocess_styles.py when the DOCX includes 作者简介. It copies the canonical reference thesis paragraph styles for that section's subheadings and strips temporary manual numbering prefixes so the final display matches the school thesis sample more closely.scripts/force_math_font_tnr.py after the main sync/postprocess pass to force all OMML math runs and their adjacent boundary runs to Times New Roman. It rewrites every m:r element's w:rFonts in document.xml, footnotes, endnotes, and headers/footers; sets ascii/hAnsi/cs on w:r runs immediately adjacent to inline m:oMath so the cursor at formula edges also shows Times New Roman; and updates the default math font in settings.xml. This is the preferred math-font post-processor for this thesis.scripts/set_math_font.py only when metadata-level OMML math-font alignment is sufficient (settings.xml only, does not touch individual math runs).scripts/strip_symbol_table_units.py when the 符号对照表 should show only symbol and description columns (no unit column). The script removes the unit text and the third tab from every aff2-styled paragraph between the and headings.IMPORTANT: Abstract files must be split into separate files.
摘要_中文.md) and English abstract (摘要_英文.md) MUST be stored as separate Markdown files.# 摘要 or # ABSTRACT).--level flag (the CLI does not accept --level 0). The heading text 摘要 or ABSTRACT is unique enough for matching.IMPORTANT: Chapter title matching.
--title parameter, NOT just "第3章".IMPORTANT: Full multi-chapter sync workflow.
When syncing all chapters at once, follow this order:
.docx to a working copy (never overwrite the master directly).--match-heading "摘要", no --level) → English (--match-heading "ABSTRACT", no --level).符号对照表 and 缩略语对照表 (--match-heading, no --level).--in-place on the working copy. Use --match-heading with the exact heading text from the Word outline, not the Markdown heading.参考文献 (--match-heading "参考文献", no --level).致谢 (--match-heading "致谢", no --level) and 作者简介 (--match-heading "作者简介", no --level) from the temporary files built above, not from the raw Markdown sources.postprocess_styles.py --in-place once on the final working copy.apply_reference_author_bio_style.py --in-place so 作者简介 matches the canonical reference thesis styles.force_math_font_tnr.py --in-place for this thesis repository's final equation-font requirement (rewrites every OMML math run to Times New Roman).strip_symbol_table_units.py --in-place for this thesis repository's final two-column 符号对照表 layout.fix_header_borders.py --in-place to restore the bottom border on all page headers.工程硕士 / professional master, run update_cover_info.py --cover-template-docx ...专业学位硕士学位论文封面及中英文题名页模板... after the body sync and verify that the first 7 pages now match the professional-master format instead of the academic-master mother file.IMPORTANT: Heading-to-file mapping for this thesis.
| Word heading text (--match-heading) | --level | Markdown source |
|---|---|---|
| 摘要 | (omit) | writing/摘要_中文.md |
| ABSTRACT | (omit) | writing/摘要_英文.md |
| 绪论 | 1 | writing/第1章_绪论_v1.md |
| 等离子体诊断原理及线性调频连续波诊断原理 | 1 | writing/第2章_等离子体电磁特性与LFMCW诊断机理_final.md |
| 诊断系统硬件设计 | 1 | (merge 第3章_3.2~3.5_final.md, title: 第三章 宽带信号在色散介质中的传播机理与方法失效分析) |
| 系统差频信号数据处理 | 1 | (merge 第4章_4.2~4.5_final.md, title: 第四章 基于滑动时频特征的贝叶斯反演算法与等离子体仿真验证) |
| 系统标定及诊断实验 | 1 | (merge 第5章_5.2~5.5_final.md, title: 第五章 宽带LFMCW诊断系统扩频设计与色散等效实验验证) |
| 总结与展望 | 1 | writing/第6章_总结与展望_final.md |
| 参考文献 | (omit) | writing/参考文献.md |
| 致谢 | (omit) | build: --title "致谢" --shift-headings 0 — always build a temp file first because writing/致谢.md may contain body text only and must still render a visible 致谢 title |
| 作者简介 | (omit) | build: --title "作者简介" --drop-leading-heading --shift-headings 0 --demote-headings-to-strong 2,3 — keep 1. 基本情况 / 3.1 发表学术论文 as manual bold items instead of Word headings, so they do not inherit chapter numbering |
IMPORTANT: Pandoc style mismatch — postprocess_styles.py is mandatory.
Full style remapping table:
| pandoc generates | postprocess remaps to | Detection method |
|---|---|---|
Body Text (a8) | Normal(正文) | Style ID match |
FirstParagraph | Normal(正文) | Style ID match |
Compact | Normal(正文) | Style ID match |
CaptionedFigure | Normal(正文) | Style ID match |
Figure | Normal(正文) | Style ID match |
ImageCaption | 标题-图 (-0) | Style ID match |
| (paragraph after image) | 标题-图 (-0) | Position: prev sibling has drawing |
| (paragraph before table) | 标题-表格 (-) | Position: next sibling is w:tbl |
| (after 参考文献 heading) | 参考文献 (a) | Section: after -1 styled 参考文献 |
| (contains m:oMathPara) | 公式 (aff1) | Content: has display math |
| (all w:tbl elements) | 三线表 formatting | Element type |
--image-source-docx over hand-copying figures from Word.scripts/build_markdown_chapter.py to create a temporary merged chapter file before sync.摘要ABSTRACTHeading 1\tag{...}; the script preprocesses those two cases before rendering.--image-source-docx. The script will fall back to that DOCX and match figures by number such as 图5-1. when the source Markdown should not depend on a local image file path.--missing-images placeholder to replace those image nodes with visible placeholder text in the output DOCX.#anchor jump links generated by pandoc.参考文献.md#ref-12, retarget them to internal Word bookmarks like ref-12 instead of leaving file links or dropping click-through entirely..doc, convert it to .docx first instead of attempting direct .doc editing.标题-无编号 sections such as 摘要, ABSTRACT, 符号对照表, or 缩略语对照表; otherwise Word headers can drift to the wrong section.作者简介, keep nested sub-items inside the same replacement block. The section must end at the next peer front-matter title or chapter title, not at the first internal subheading._sync_tmp.md files and DOCX backups matching the current output stem such as versions/论文名.bak-*.docx.致谢, the heading must visually match the reference thesis front matter: keep a standalone visible 致谢 title in 标题-无编号 style, then body paragraphs in the normal body-text style. A raw body-only Markdown file is not enough; build a temporary file with the title before sync.作者简介, use the reference thesis as a style sample but not as a literal heading-depth prescription. The reference .md shows #####/###### because the original mother file stored those lines with Heading 5/6 formatting, but when that numbering chain is live in the working DOCX, directly reusing Heading 5/6 causes wrong labels such as 6.4. In that case, preserve the reference section's visual hierarchy with manual numbered bold paragraphs or another non-numbered equivalent, instead of inheriting chapter counters.apply_reference_author_bio_style.py on the final DOCX so the 作者简介 subheading paragraphs are re-mapped to the canonical reference thesis styles instead of staying as plain bold body text.符号对照表 should omit the 单位 column by default. Run strip_symbol_table_units.py on the final DOCX unless the user explicitly asks to keep the three-column layout.Times New Roman. Run force_math_font_tnr.py --in-place as a post-processing step. It performs three actions: (a) update the default math font in settings.xml, (b) rewrite every OMML math run (m:r) 's w:rFonts to Times New Roman, and (c) set ascii/hAnsi/cs on regular w:r runs that are immediately adjacent to inline m:oMath blocks so the cursor at formula boundaries also shows Times New Roman instead of the paragraph's default font (e.g. 宋体). CJK eastAsia font hints are preserved on adjacent runs.set_math_font.py only updates settings.xml metadata and may not be sufficient — Word can still render existing OMML runs with Cambria Math. Prefer force_math_font_tnr.py which explicitly sets font on every m:r element and adjacent boundary runs.force_math_font_tnr.py Word still shows Cambria Math for some equations, those equations may need a live Word/MathType reflow pass.封面信息.md fields.writing/2、西安电子科技大学专业学位硕士学位论文封面及中英文题名页模板(2015年版)-2022.11修订.docx is the default cover source whenever the requested degree type is 工程硕士 / professional master.resources/word2md/, use that reference DOCX as the cover source and adapt its labels/fields to the requested degree type instead of switching to another school template.学位论文独创性(或创新性)声明; otherwise Word may insert extra blank pages between the English cover and the declaration pages.符号对照表 and 缩略语对照表, treat Markdown tables as source data only. The synced DOCX should flatten those tables into paragraph-style line entries consistent with the reference thesis, not keep them as Word tables.符号对照表, preserve OMML/math nodes from the first column instead of extracting only plain w:t text; otherwise symbols such as $n_e$ or $\tau_g(\omega)$ disappear.缩略语对照表, keep the mother template's tab-stop layout and acronym character style instead of emitting plain left-aligned text.fix_header_borders.py should run after any sync or cover replacement. The thesis template's header style (id ae) defines a double bottom border. After pandoc-based sync, some header XML paragraphs may be reset to style a4 (Normal Indent) which has no border, causing the underline to disappear. This script auto-detects the correct header style id and rewrites all non-conforming header paragraphs. Run it once on the final output after all syncs and post-processing are complete.strip_symbol_table_units.py removes the unit column from the 符号对照表. The symbol table uses a 3-column tab layout (symbol / unit / description). This script removes the middle column by deleting the unit text and the third tab character, leaving a 2-column layout (symbol / description). It handles inline OMML math in the symbol column and preserves bookmarks. It keeps only the first "符号 物理含义" header row and deletes all duplicate header rows that repeat mid-table. Run it once after syncing; it is idempotent on already-stripped files (entries with fewer than 3 tabs are skipped).postprocess_styles.py is mandatory after every sync. It now handles ALL of the following:
标题-图)w:tbl elements → 标题-表格)参考文献 heading → 参考文献)参考文献.md#ref-* links so正文引文 can jump to internal bibliography bookmarksm:oMathPara → 公式)sectPr that actually controls that chapter's pagespostprocess_styles.py once on the final output. Running it per-chapter is also fine but unnecessary.--level CLI argument for sync_markdown_to_docx.py only accepts values 1–9. For level-0 headings (e.g., 摘要, ABSTRACT with 标题-无编号 style), omit the --level flag entirely — the heading text alone is sufficient for unique matching.符号对照表缩略语对照表references/workflow.md when the user needs scope, constraints, or failure handling.