---
name: math-exam-generator
description: Generates Chinese junior high school math exam papers from text or images. Uses AI to solve problems step-by-step and formats them into a printable A4 exam paper using LaTeX and HTML.
---

# Math Exam Generator

This skill processes math problems (from text or images), solves them using AI with junior high school appropriate methods, and generates a professionally formatted exam paper in HTML/LaTeX style, suitable for printing on A4 paper.

## Workflow

1.  **Input Analysis**:
    *   If input is text, parse the problems.
    *   If input is image, use OCR to extract the math problems.
    *   Identify the type of problem (Calculation, Geometry, Word Problem, etc.).

2.  **AI Solving**:
    *   Solve each problem step-by-step.
    *   **Crucial**: Use methods and explanations suitable for Chinese junior high school students (e.g., clear logical steps, "解：" (Solution:), "证明：" (Proof:)).
    *   Format mathematical expressions using LaTeX (enclosed in `$$` for display or `$` for inline).

3.  **HTML Generation**:
    *   Read the template: `assets/exam_template.html`.
    *   Generate HTML for each problem using the structure below.
    *   Replace `<!-- PROBLEMS_CONTAINER -->` in the template with the generated content.

4.  **Output**:
    *   Save the result as an HTML file (e.g., `math_exam.html`).
    *   Present the file to the user for preview or printing.

## Problem HTML Structure

For each problem, generate a `div` with class `problem`.

```html
<div class="problem">
    <div class="problem-text">
        <span class="problem-number">1.</span>
        <!-- Problem Description with LaTeX -->
        Calculate: $$ \sqrt{12} + \sqrt{27} $$
    </div>
    <div class="solution-area">
        <span class="solution-label">解：</span>
        <div class="solution-content">
            <!-- Step-by-step solution with LaTeX -->
            $$ \begin{aligned} \text{Original} &= 2\sqrt{3} + 3\sqrt{3} \\ &= 5\sqrt{3} \end{aligned} $$
        </div>
    </div>
</div>
```

## Styling & Formatting Rules

*   **Language**: Simplified Chinese.
*   **Math**: Use standard LaTeX. ensure `\displaystyle` is used for fractions/integrals if needed for clarity.
*   **Junior High Style**:
    *   "Selection Questions" (选择题) usually don't need a large solution area, just the options.
    *   "Fill-in-the-blanks" (填空题) need a blank line `______`.
    *   "Calculation/Proof" (解答题) need `解：` or `证明：` at the start of the solution.
*   **Images**: If the problem includes a geometric figure, you can attempt to generate an SVG or use a placeholder if the original image cannot be extracted perfectly. (For this version, text description or placeholder is acceptable if image generation is too complex).

## Example Usage

**User**: "Help me make a math exam with these problems: 1. Solve x^2 - 5x + 6 = 0. 2. A triangle has sides 3, 4, 5, is it a right triangle?"

**Action**:
1.  Parse problems.
2.  Solve:
    *   1. $(x-2)(x-3)=0 \Rightarrow x_1=2, x_2=3$.
    *   2. $3^2+4^2=9+16=25=5^2$, so by Converse of Pythagorean theorem, yes.
3.  Read `assets/exam_template.html`.
4.  Insert formatted HTML.
5.  Save `math_exam.html`.
