技能圖譜SKILLSGROVE
技能圖譜/效率工具/libinyam/mathtranslations-skill/mathtranslation-cls-v31-upgrade

mathtranslation-cls-v31-upgrade

安裝

$npx skills add https://github.com/libinyam/mathtranslations-skill --skill mathtranslation-cls-v31-upgrade
$git clone --depth 1 https://github.com/libinyam/mathtranslations-skill.git /tmp/mathtranslations-skill && mkdir -p ~/.claude/skills && cp -r /tmp/mathtranslations-skill/skills/mathtranslation-cls-v31-upgrade ~/.claude/skills/mathtranslation-cls-v31-upgrade
請幫我安裝這個 Agent Skill:https://github.com/libinyam/mathtranslations-skill/tree/8f4ebf796d7f29d88ca3438b6ff4926c615b733d/skills/mathtranslation-cls-v31-upgrade ,先閱讀它的 SKILL.md 和指令碼,確認安全後再安裝到我的技能目錄。

簡介

原文描述 · MITUse when migrating a Chinese math-book translation from the OLD mathtranslation template (v1.x, ctexart-based, single-file or thin wrapper) onto the NEW mathtranslation.cls v3.1 (ctexbook-based, kvoptions class options). Covers the three-layer heading remap (Section->Chapter->Subsection), continuous equation numbering on ctexbook, the shared-theorem-counter / \@addtoreset hook traps, the \printterminology unnumbered-chapter override, and the pymupdf-based regression audit that proves nothing was lost.
以下 SKILL.md 內容轉載自 libinyam/mathtranslations-skill(提交 8f4ebf7),依據 MIT 許可證轉載正文(文字未改動;僅省略檔案頭後設資料、將圖片顯示為連結,超長內容會截斷);版權歸 2026 MathTranslations and mathtranslations-skill contributors 所有。許可證:LICENSE。僅展示說明檔案,附帶指令碼請在原倉庫檢視。

Migrate a translation to mathtranslation.cls v3.1

Purpose

The old mathtranslation templates wrap ctexart with a hand-rolled compatibility layer (\ChapterSectionLabel, \sectionbreak{\clearpage}, mybibliography, a \titleformat{\section}[display] that paints "Chapter N" headings). mathtranslation.cls v3.1 wraps ctexbook and exposes real class options via kvoptions. The visible layout is intentionally similar, but the underlying counters and hooks are different, so a naive \documentclass swap compiles yet silently mangles numbering. This skill is the safe, auditable recipe.

When to use

  • A translation uses the old ctexart template and must move to .../mathtranslations-translation-template/mathtranslation.cls (v3.1).
  • The old source uses \section for chapters (because old \section rendered like a chapter).
  • Symptom that this skill is needed: after the swap, equations become (n.m), theorem numbers restart inside chapters, or "术语索引" becomes "第 N 章".

Step 0 — Identify the target and the old style

  1. Confirm the reference class: md5(or normalized content) of the target mathtranslation.cls. Compare with line endings normalized (b.replace(b'\r\n', b'\n')) — a raw md5 mismatch is usually just CRLF vs LF (699 lines ⇒ 699-byte delta), NOT a content difference.
  2. Grep the old project for the old-template fingerprints: \ChapterSectionLabel, \sectionbreak, mybibliography, \chapter absent, ctexart.

Step 1 — Class line

Replace the old \documentclass[UTF8,11pt,fontset=none]{ctexart} (+ inlined defs) with:

\documentclass[BookTitleCN={...},BookTitleEN={...},OriginalAuthor={...},
  HeadingFont=hei,Biblatex=true,BibStyle=numeric-comp]{mathtranslation}
  • Biblatex=false ⇒ the class falls back to bibtex; use it when the body has literal \bibitems and no .bib. v3.1 has no mybibliography environment — use thebibliography (the class already patches the heading / TOC entry / bookmark / header for it).
  • Keep per-project extras the class lacks, e.g. \usepackage{esint}.

Step 2 — Heading remap (three layers)

Because the old \section rendered as a chapter, shift everything down one level. Include the toc layer:

old new
\section / \section* \chapter / \chapter*
\subsection \section
\subsubsection \subsection
\addcontentsline{toc}{section} \addcontentsline{toc}{chapter}

Do it as a single regex pass, then prove it lossless: apply the inverse map to the new files and diff against the backup — it must restore byte-for-byte. Watch for \subsubsection inside comment lines (harmless, but count it so your roundtrip check is exact).

Step 3 — Equation numbering (ctexbook regression)

ctexbook numbers equations per chapter by default (\theequation = \thechapter.\arabic{equation}). The old ctexart numbered them continuously. Restore continuity explicitly:

\makeatletter
\@removefromreset{equation}{chapter}
\renewcommand{\theequation}{\arabic{equation}}
\makeatother

Also swap any old \numberwithin{X}{section} → {chapter} (otherwise on ctexbook you get n.m.k).

Step 4 — Theorem counters (the two traps)

Trap A — a shared counter has no register

\newtheorem{proposition}[theorem]{命题} does not create \c@proposition; it only makes \theproposition point at \thetheorem. hyperref / cleveref still evaluate \the\c@proposition, and if that register is \relax you get You can't use \relax after \the.

When you tear down the class's theorem defs and rebuild them:

\def\MT@undefthm#1{%
  \expandafter\let\csname #1\endcsname\relax
  \expandafter\let\csname end#1\endcsname\relax
  \expandafter\let\csname c@#1\endcsname\relax}
% ... rebuild with \newtheorem{theorem}{定理}[chapter] then aliases [theorem] ...
% then re-point each alias register at the shared one:
\makeatletter
\let\c@definition\c@theorem  \let\c@lemma\c@theorem
\let\c@corollary\c@theorem   \let\c@proposition\c@theorem
% ... one line per alias ...
\makeatother

Trap B — residual \@addtoreset survives the redefine

Redefining a theorem does not clear the class's \@addtoreset{X}{section} hook registered on \cl@section. After the remap, \section means a subsection, so every theorem counter resets on each subsection ⇒ visible number churn (1.1, 1.1, 1.1 …).

Fix per-counter:

\makeatletter
\@removefromreset{theorem}{section}
\@removefromreset{definition}{section}  % ... etc ...
\makeatother

Do NOT clear the whole \cl@section list. It also carries book-class native hooks (subsection, exercise, …); wiping it stops subsubsections from resetting per section and introduces a new bug. On TeX Live 2026 \@removefromreset performs a precise list surgery — use it.

Step 5 — Unnumbered 术语索引 / 参考文献 chapters

\printterminology emits \chapter{术语索引}. If the document has no \appendix, that chapter gets numbered and the index appears as "第 N 章". Override the chapter command locally:

\let\MTOrigChapter\chapter
\newcommand{\MTStarChapter}[1]{\MTOrigChapter*{#1}\phantomsection\addcontentsline{toc}{chapter}{#1}}
\let\MTOrigPrintTerminology\printterminology
\renewcommand{\printterminology}{%
  \begingroup\let\chapter\MTStarChapter\MTOrigPrintTerminology\endgroup}

(When \appendix is present, the class's default is correct and you should not override.)

Step 6 — Body skeleton

\makecover            % NOT \maketitle — v3.1 redefines it to the book cover
\frontmatter
  % 获奖说明 / \chapter*{译者说明} / \tableofcontents
\mainmatter
  \chapter{...} ...   % content, \input files
\backmatter
  \chapter*{参考文献}\nocite{*}\printbibliography[...]
  \printterminology

Step 7 — Verify (do not trust "rc=0")

  1. Build with the project driver (xelatex ×3 + biber/bibtex; texindy for the index). Require errors=0, undefined=0; treat overfull/underfull as cosmetic only.
  2. Regression-audit the PDF against the pre-swap baseline with pymupdf (text, since the renderer cannot see images):
    • Record and compare: heading sequence; equation-label multiset; theorem/lemma/prop numbering multiset; figure count; citation count; and the \envenddiamond glyph \u22c4 count.
    • Normalize with re.sub(r'\s+','', text) and compare title sequences item-by-item — footnotes get extracted adjacent to body text and create "phantom differences" that vanish under whitespace normalization.
  3. Intended visual changes (v3.1 makes \headfont a real hei font, chapter label layout differs) are expected and must not be "fixed".

Environment notes (this Windows/WorkBuddy box)

  • dirname/head/ls/wc/tail are broken in the Bash tool. Use Python for all file work: C:/Users/asus/.workbuddy/binaries/python/versions/3.13.12/python.exe.
  • TeX binaries live in D:\texlive\2026\bin\windows\.
  • Preserve each source file's original line endings (many are CRLF); do not let an editor flip them.
  • Deleting many temp files (_cltest*) can trip SAFE_DELETE_BULK_CONFIRM_REQUIRED; just re-issue the build instead of chaining a big delete.
檢視許可證全文(MIT)
MIT License

Copyright (c) 2026 MathTranslations and mathtranslations-skill contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
檢視 NOTICE 宣告
# Attribution

This independent Codex skill was derived from the public workflow described in:

- MathTranslations, "Guide / 数学翻译指南"
- <https://mathtranslations.org/guide/>
- Accessed 2026-08-22

The repository paraphrases the workflow and adds an original skill structure,
review references, and a deterministic LaTeX audit script. It does not include
a copy of the site's live terminology database.

The MathTranslations template profile was also derived by inspecting the
user-supplied archive `MathTranslations-Template.c9598d4a8d56.zip` on
2026-08-22. Its SHA-256 was
`F74809A3B63F2AE1FD8C7554EF3B43D8AD8C7240969838DB928BD3CF529BF2EF`.
The archive contained `MathTranslations-Template.tex`,
`MathTranslations-Template.pdf`, and `logo.pdf`.

The MathTranslations founder and copyright holder authorized
`MathTranslations-Template.tex` and `logo.pdf` for inclusion and distribution
in this repository under the MIT License. The compiled example PDF is not
included because it is not required by the skill.

The official archive was renamed to `mathtranslations-translation-template.zip`
and re-inspected on 2026-08-23 (SHA-256
`4C2E5AD1C81646B4E8AD53F4B5FD5BAA7D477C749915E32CF52B5EE71F85F12E`). The
updated `assets/mathtranslations-translation-template.tex` derives from that
authorized archive under the same MIT-License authorization, and the earlier
`MathTranslations-Template.*` name refers to previous releases of the same
template.

MathTranslations and its website are not affiliated with or responsible for
this repository.