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_model

SKILL.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
    @config.tex
    in an existing project
  • ⚠️ Reference Scope for
    main.tex
    :
    • Allowed to reference:
      \section{}
      ,
      \subsection{}
      title texts in
      main.tex
    • Forbidden to reference: Main content files referenced by
      \input{}
      in
      main.tex

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
projects/{project}/.make_latex_model/
by default) and more script details can be found in:
  • skills/make_latex_model/docs/WORKFLOW.md
  • skills/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

ParameterTypeRequiredDescription
project
stringYesProject name (e.g.,
NSFC_Young
,
NSFC_General
)
word_template_year
stringYesWord template year (e.g.,
2025
)
optimization_level
stringNoOptimization level:
minimal
(minimal changes)|
moderate
(medium)|
thorough
(complete), default is
moderate
dry_run
booleanNoPreview mode, no actual file modification, default is
false

Quick Start (Recommended Path)

  1. Pre-check:
bash
python3 skills/make_latex_model/scripts/check_state.py projects/{project}
  1. Validation (the script parses
    --project
    , supports
    NSFC_Young
    or
    projects/NSFC_Young
    ):
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}
  1. 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 \
  --report
To 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 heuristic
Note: The script currently uses heuristic decision-making by default; for "host AI full participation", use
--ai-mode manual_file
(which generates
projects/<project>/.make_latex_model/iterations/iteration_XXX/ai_request.json
, waiting for
ai_response.json
to be written before continuing).

Convergence Conditions (Priority from High to Low)

ConditionThresholdDescription
Compilation Failure-Stop immediately, manual repair required
Pixel Difference Convergence
changed_ratio < 0.01
Achieve pixel-level alignment
No Continuous Improvement5 roundsMetrics no longer optimize, convergence achieved
Maximum Iterations30 roundsForce stop

Related Scripts

ScriptFunction
enhanced_optimize.py
One-click iterative optimization entry
prepare_main.py
Preprocess/restore main.tex
generate_baseline.py
Generate Word PDF baseline
convergence_detector.py
Convergence detection and reporting
run_ai_optimizer.py
AI optimizer (single-round debugging entry)
intelligent_adjust.py
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
    CHANGELOG.md
    of the repository
  • Only keep necessary explanatory comments in
    @config.tex
    (do not maintain version history)

Code Changes

  • Precisely modify
    projects/{project}/extraTex/@config.tex
    , retaining:
    • Original comments
    • Code style
    • Conditional judgment structures (e.g.,
      \ifwindows
      )
  • Allowed to modify title text in
    projects/{project}/main.tex
    (only modify text in curly braces, do not touch
    \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
    \input{extraTex/*.tex}
    in
    main.tex
  • User-written content in
    extraTex/*.tex
    files
  • 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.立项依据.tex

Prioritize 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
      moderate
      level by default
    • Use
      thorough
      level only when necessary
    • Retain the core architecture of the old style

Cross-platform Compatibility

  • Retain
    \ifwindows
    conditional judgments
  • Ensure correct compilation on Mac/Windows/Linux
  • Keep external font paths unchanged (
    ./fonts/
    )

Acceptance Checklist (By Priority)

  1. Basic compilation:
    xelatex -> bibtex -> xelatex -> xelatex
    without errors
  2. Style parameters: Line spacing/font size/color/margins within tolerance (based on
    skills/make_latex_model/config.yaml
    )
  3. Title text: Exactly consistent with Word template (text/punctuation/numbering/bold position)
  4. Pixel comparison: Only as auxiliary; baseline must come from Word/LibreOffice (do not use QuickLook)

FAQ

See:
skills/make_latex_model/docs/FAQ.md