make_latex_model
Original:🇨🇳 Chinese
Translated
51 scripts
High-fidelity Optimizer for LaTeX Templates, supporting style parameter alignment, title text alignment, title format comparison (bold), HTML visualization reports, automatic LaTeX repair suggestions, and pixel-level PDF comparison verification for any LaTeX template
2installs
Added on
NPX Install
npx skill4agent add huangwb8/chineseresearchlatex make_latex_modelTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →NSFC LaTeX Template High-fidelity Optimizer
What You Should Read First
- Detailed Workflow (including commands and decision points):
skills/make_latex_model/docs/WORKFLOW.md - Word PDF Baseline Creation:
skills/make_latex_model/docs/BASELINE_GUIDE.md - Complete Script Usage:
skills/make_latex_model/scripts/README.md - Frequently Asked Questions:
skills/make_latex_model/docs/FAQ.md
In-depth References
- Specifications in CLAUDE.md and skills/README.md of this project
- Style definition pattern of in an existing project
@config.tex - ⚠️ Reference Scope for :
main.tex- ✅ Allowed to reference: ,
\section{}title texts in\subsection{}main.tex - ❌ Forbidden to reference: Main content files referenced by in
\input{}main.tex
- ✅ Allowed to reference:
Core Objective
Ensure pixel-level alignment between the PDF rendered by LaTeX and the PDF printed from the Word version:
Style Elements (Must Be Fully Consistent)
- Title hierarchy format (Level 1, 2, 3, 4)
- ⚠️ Title text content (Word template titles may vary each year)
- Font (Chinese KaiTi + English Times New Roman)
- Font size (Size 3, Size 4, Small Size 4, etc.)
- Color (MsBlue RGB 0,112,192)
- Spacing (line spacing, before/after paragraph spacing, indentation)
- List style (numbering format, indentation)
- Page settings (margins, text area)
⚠️ Key 1: Title Text Alignment
- Title text content must be exactly the same as Word
- Title numbering format must be exactly the same as Word (e.g., "1." vs "1.")
- Punctuation must be exactly the same as Word (e.g., full-width/half-width symbols)
- Example: If Word shows "1. Project Establishment Basis", LaTeX must be identical
⚠️ Key 2: Line-by-Line Word Count Alignment
- Word count per line must be exactly the same as Word
- Line break positions must be exactly the same as Word
- This requires precise adjustments: font size, character spacing, line spacing, paragraph spacing
Execution Mode (Brief)
This skill adopts a hybrid mode of "hard-coded tools + AI decision-making":
- Scripts handle deterministic tasks (extraction/comparison/validation/output artifact storage)
- AI handles heuristic decision-making (which parameter to adjust, how much to adjust, whether to roll back/continue iteration)
Workspace (artifacts are stored in by default) and more script details can be found in:
projects/{project}/.make_latex_model/skills/make_latex_model/docs/WORKFLOW.mdskills/make_latex_model/scripts/README.md
Trigger Conditions
Users trigger this skill in the following scenarios:
- NSFC releases a new annual Word template
- Obvious style differences exist between the current LaTeX template and the Word template
- Users actively request "align with Word style" or "update template format"
Input Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Project name (e.g., |
| string | Yes | Word template year (e.g., |
| string | No | Optimization level: |
| boolean | No | Preview mode, no actual file modification, default is |
Quick Start (Recommended Path)
- Pre-check:
bash
python3 skills/make_latex_model/scripts/check_state.py projects/{project}- Validation (the script parses , supports
--projectorNSFC_Young):projects/NSFC_Young
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}- For fine-grained alignment, run the iterative loop:
python3 skills/make_latex_model/scripts/enhanced_optimize.py --project projects/{project} --max-iterations 30 --report
Iterative Optimization Loop
This step implements a fully automated "optimize-compare-adjust" cycle, recommended for fine-grained adjustments.
One-click Startup
bash
# Fully automated iterative optimization
python3 skills/make_latex_model/scripts/enhanced_optimize.py \
--project projects/NSFC_Young \
--max-iterations 30 \
--reportTo enable the AI optimization loop of "Analyzer → Reasoner → Executor → Memory" (minimum viable version), add:
bash
python3 skills/make_latex_model/scripts/enhanced_optimize.py \
--project projects/NSFC_Young \
--max-iterations 30 \
--ai --ai-mode heuristicNote: The script currently uses heuristic decision-making by default; for "host AI full participation", use(which generates--ai-mode manual_file, waiting forprojects/<project>/.make_latex_model/iterations/iteration_XXX/ai_request.jsonto be written before continuing).ai_response.json
Convergence Conditions (Priority from High to Low)
| Condition | Threshold | Description |
|---|---|---|
| Compilation Failure | - | Stop immediately, manual repair required |
| Pixel Difference Convergence | | Achieve pixel-level alignment |
| No Continuous Improvement | 5 rounds | Metrics no longer optimize, convergence achieved |
| Maximum Iterations | 30 rounds | Force stop |
Related Scripts
| Script | Function |
|---|---|
| One-click iterative optimization entry |
| Preprocess/restore main.tex |
| Generate Word PDF baseline |
| Convergence detection and reporting |
| AI optimizer (single-round debugging entry) |
| Intelligent parameter adjustment suggestions (legacy heuristic, retained as fallback path) |
Output Specifications
Modification Records (Single Source of Truth)
- All traceable change history is recorded in the root of the repository
CHANGELOG.md - Only keep necessary explanatory comments in (do not maintain version history)
@config.tex
Code Changes
- Precisely modify , retaining:
projects/{project}/extraTex/@config.tex- Original comments
- Code style
- Conditional judgment structures (e.g., )
\ifwindows
- Allowed to modify title text in (only modify text in curly braces, do not touch
projects/{project}/main.tex)\input{}
Quick Validation (Recommended):
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}Core Principles (Bottom Line)
Absolute Forbidden Areas
⚠️ Never touch main paragraph content in
main.tex- Main content files referenced by in
\input{extraTex/*.tex}main.tex - User-written content in files
extraTex/*.tex - Main paragraphs, tables, images, formulas, etc.
✅ Allowed to modify title text in
main.tex- Title text in
\section{Title Text} - Title text in
\subsection{Title Text} - Title numbering format, punctuation, etc.
- Reason: The text structure of titles is also part of the template style and needs to align with the Word template
⚠️ Boundary Example:
latex
% ✅ Allowed modification: title text
\section{{\bfseries(一)立项依据与研究内容}(建议8000字以内):} % Modified to
\section{{\bfseries(一)研究依据与内容}(建议8000字以内):}
% ❌ Forbidden modification: main content
\input{extraTex/1.1.立项依据.tex} % Do not change the reference relationship
% Do not modify the specific content in extraTex/1.1.立项依据.texPrioritize Lightweight Modifications
- ✅ Adjust parameter values (font size pt value, color RGB value, spacing em/cm value)
- ✅ Add custom commands
- ❌ Delete or rename existing commands
- ❌ Change package loading order
- ❌ Refactor conditional judgment structures
Balance Between Fidelity and Stability
- Risk of over-development: Introduce bugs, break existing functions, increase maintenance costs
- Risk of under-development: Inconsistent styles, non-compliance with NSFC requirements
- Balance Strategy:
- Use level by default
moderate - Use level only when necessary
thorough - Retain the core architecture of the old style
- Use
Cross-platform Compatibility
- Retain conditional judgments
\ifwindows - Ensure correct compilation on Mac/Windows/Linux
- Keep external font paths unchanged ()
./fonts/
Acceptance Checklist (By Priority)
- Basic compilation: without errors
xelatex -> bibtex -> xelatex -> xelatex - Style parameters: Line spacing/font size/color/margins within tolerance (based on )
skills/make_latex_model/config.yaml - Title text: Exactly consistent with Word template (text/punctuation/numbering/bold position)
- Pixel comparison: Only as auxiliary; baseline must come from Word/LibreOffice (do not use QuickLook)
FAQ
See:
skills/make_latex_model/docs/FAQ.md