mathtranslation-cls-v31-upgrade
Skill5 starsChanged 57 days agoMITView on GitHub
Migrate a Chinese LaTeX translation from a legacy ctexart MathTranslations template to a supplied mathtranslation.cls v3.1 book class when requested. Preserve heading hierarchy, equation/theorem counters, bibliography, terminology index, and content through regression review.
In this repository12 other files it gives its agents.
- aimath-translations-skillSkill
- latex-array-diagram-auditSkill
- latex-bookmark-anchor-auditSkill
- latex-display-layout-auditSkill
- latex-eq-numbering-auditSkill
- latex-footnote-fidelity-auditSkill
- latex-ocr-math-defect-auditSkill
- latex-translation-fidelity-auditSkill
- math-pdf-bookmarkSkill
- mathtranslation-build-verifySkill
- mathtranslation-hardrefSkill
- pdf-scanned-ocr-bookmarkSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 50
Keep per-project extras the class lacks, e.g.
- Distinctive: line 122
Use a targeted reset operation supported by the actual toolchain, then verify the reset boundary and displayed/hyperlink representations …
- Distinctive: line 174
Use the supplied class's actual interface.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
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
\sectionfor chapters (because old\sectionrendered 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
- Inspect the target
mathtranslation.cls, declared version, and actual interface. Record a hash for file identity, then compare content with the supplied reference when available. A raw hash mismatch can reflect line endings or substantive changes; do not infer its cause from the hash. Compare both raw and line-ending- normalized content (b.replace(b'\r\n', b'\n')) to establish which differences are present. A remembered line count or byte delta is not version evidence. - Grep the old project for the old-template fingerprints:
\ChapterSectionLabel,\sectionbreak,mybibliography,\chapterabsent,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 nomybibliographyenvironment — usethebibliography(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} |
Apply the map only to confirmed structural commands in included document files. Protect verbatim/listing/algorithm content, literal examples, comments, macro definitions, and generated files; a single global regex can damage them even when its inverse restores the bytes. Preview proposed edits and review each changed heading/TOC entry against the old hierarchy. An inverse-map diff can detect unintended textual loss, but it does not prove semantic correctness.
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}}
\makeatotherInspect every old \numberwithin{X}{section} against the source counter model.
Change it to {chapter} only when that counter should follow the remapped
chapter level; definitions or other objects may intentionally remain section-based.
Step 4 — Theorem counters (the two traps)
Trap A — shared and independent counters need different treatment
\newtheorem{proposition}[theorem]{命题} uses the shared theorem counter rather
than allocating an independent proposition counter. Inspect the actual theorem
package, environment definitions, \c@..., \the..., hyperlink representations,
and reference wrappers before changing them. A wrapper assuming an independent
register can fail, but that is not a universal defect in shared-counter environments.
Preserve existing counter registers and sharing relationships. Do not undefine
\c@<name>, allocate a replacement register, or force aliases merely to redefine
an environment. Prefer changing display/reset behavior through the project's
supported interface. If environment replacement is genuinely required, limit
it to identified environment definitions, retain the original counter state,
and verify all wrappers and hyperlink targets. Compare rendered numbers with the
baseline and source before adopting any new sharing model.
Trap B — residual \@addtoreset survives the redefine
An existing reset hook can survive an environment redefinition. Inspect the
actual reset lists and intended source numbering first: after heading remapping,
a reset on section may be correct for one counter and incorrect for another.
Repeated visible numbers can indicate an inappropriate reset, but require
checking the shared counter and source edition before changing it.
For a confirmed counter that should no longer reset by section, remove only that relationship (example, not an instruction to change all environments):
\makeatletter
\@removefromreset{theorem}{section}
\makeatotherDo NOT clear the whole \cl@section list. It also carries book-class native hooks
(subsection, exercise, …); wiping it introduces unrelated numbering defects.
Use a targeted reset operation supported by the actual toolchain, then verify
the reset boundary and displayed/hyperlink representations across sections,
chapters, and appendices. Shared counters need one change to the underlying
counter, not blind changes to every environment name.
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[...]
\printterminologyStep 7 — Verify (do not trust "rc=0")
- Build with the project driver (
xelatex×3 +biber/bibtex;texindyfor the index). Require errors=0, undefined=0. Review overfull/underfull findings on the affected pages: some are harmless spacing warnings, while others indicate clipped formulas, overlapping text, or lost readability and need repair. - Regression-audit the PDF against the pre-swap baseline with
pymupdf(text plus rendered page inspection when available):- Record and compare: heading sequence; equation-label multiset; theorem/lemma/prop numbering
multiset; figure count; citation count; and the
\envenddiamondglyph\u22c4count. - 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.
- Record and compare: heading sequence; equation-label multiset; theorem/lemma/prop numbering
multiset; figure count; citation count; and the
- Intended visual changes (v3.1 makes
\headfonta real hei font, chapter label layout differs) are expected and must not be "fixed".
Portability And Review
- Locate the available Python and TeX tools instead of copying a private machine path.
- Preserve the existing encoding and line endings.
- Use the supplied class's actual interface; this migration is optional and must not be triggered simply because a translation concerns AI or mathematics.
- Render changed pages when visual tools are available and report any missing visual pass. Do not treat historical text-only limitations as current facts.
- Scope cleanup to generated artifacts and temporary files from this migration.
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
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.

