# Latexify Skill

> LaTeXify Skill

- Skill: `yzdame/latexify-skill` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add yzdame/latexify-skill`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yzdame/latexify-skill/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: YZDame (https://skillmd.com/u/yzdame)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/yzdame/latexify-skill

---

# LaTeXify Skill

A specialized skill for processing and formatting LaTeX documents. This skill normalizes LaTeX code to follow best practices for mathematical and general documents.

## Features

### LaTeX Structure Organization
- Normalizes theorem, lemma, definition, and proof environments
- Configurable theorem styles (classic, simple, boxed)
- Consistent numbering and formatting

### Math Expression Formatting
- Converts `$$...$$` to `align/align*` environments
- Normalizes `\(...\)` to `$...$` inline math
- Removes `\boxed{}` commands with sensible alternatives

### Page Layout Configuration
- Adjustable paper size (a4, letter, b5)
- Configurable margins
- Line spacing control
- Font size options

### Safety Features
- Automatic backups before modification
- Dry-run mode for previewing changes
- Rollback capability (keeps last 3 backups)

## Installation

This skill is part of the Compound Engineering plugin collection. No additional installation required.

## Usage

### Command Line Interface

```bash
# Process a file with default settings
latexify input.tex

# Preview changes without saving
latexify input.tex --dry-run

# Use specific theorem style
latexify input.tex --style simple

# Remove \boxed commands
latexify input.tex --no-boxed

# Specify paper size and margins
latexify input.tex --paper a4 --margin 2.5cm

# Rollback to previous version
latexify input.tex --rollback
```

### Arguments

| Argument | Description | Default |
|----------|-------------|---------|
| `input` | Input LaTeX file | Required |
| `-o, --output` | Output file path | Overwrite input |
| `--style` | Theorem style (classic/simple/boxed) | classic |
| `--paper` | Paper size (a4/letter/b5) | a4 |
| `--margin` | Margin size | 2.5cm |
| `--line-spacing` | Line spacing multiplier | 1.5 |
| `--font-size` | Font size in pt | 10 |
| `--no-inline-fix` | Skip inline math fixes | False |
| `--no-display-fix` | Skip display math fixes | False |
| `--no-boxed` | Keep \boxed commands | False |
| `--dry-run` | Preview changes only | False |
| `--rollback` | Restore from backup | False |
| `--verbose` | Verbose output | False |

## Theorem Styles

### Classic Style (Default)
Traditional formatting:
- Bold theorem titles
- Chinese full-width colon (：) as separator
- Standard LaTeX numbering
- Example: `定理 1.1：内容...`

### Simple Style
Minimal formatting for clean appearance:
- No special title formatting
- Standard body text
- Clean, uncluttered look
- Example: `Theorem 1.1: Content...`

### Boxed Style
Enhanced visual separation:
- Shaded background
- Border boxes
- Clear visual hierarchy
- Requires `framed` or `mdframed` package

## Examples

### Before and After

**Before:**
```latex
Document was created with inconsistent math formatting.

\(a + b = c\)

$$
x^2 + y^2 = z^2
$$

\begin{theorem}
\label{th1}
给定 \(a, b, c\)，则...
\end{theorem}

Answer: \boxed{42}
```

**After (classic style):**
```latex
Document was created with inconsistent math formatting.

$a + b = c$

\begin{align}
x^2 + y^2 = z^2
\end{align}

\begin{theorem}[定理 1]
给定 $a, b, c$，则...
\end{theorem}

Answer: $42$
```

## Integration

### As a Python Module

```python
from latex_math_competition import (
    LaTeXParser,
    LaTeXTransformer,
    InlineMathRule,
    DisplayMathRule,
    BoxedRemovalRule,
    TheoremEnvRule
)

# Parse document
parser = LaTeXParser()
parsed = parser.parse(content)

# Transform document
transformer = LaTeXTransformer(parser)
rules = [
    InlineMathRule(),
    DisplayMathRule(),
    BoxedRemovalRule(),
    TheoremEnvRule(style='classic')
]
result = transformer.transform(content, rules)
```

### Preview Changes

```python
preview = transformer.preview_changes(content, rules)
print(preview['preview'])
print(f"Changes: {len(preview['changes'])} lines")
```

## Configuration Files

### Theorem Styles (`references/theorem-styles.json`)
Predefined theorem style configurations.

### Best Practices (`references/latex-best-practices.md`)
Comprehensive guide for LaTeX document formatting.

### Templates (`assets/templates/`)
Ready-to-use theorem templates:
- `classic-theorem.tex` - Classic Chinese style
- `simple-theorem.tex` - Minimal style
- `boxed-theorem.tex` - Boxed style

## Best Practices

### Inline Math
- Use `$...$` instead of `\(...\)`
- Add space after punctuation before math: `，$x$` not `，$x$`

### Display Math
- Use `align` for multi-line equations
- Use `equation` for single-line equations
- Avoid `$$...$$` (deprecated)

### Theorem Environments
- Use consistent naming (定理, 定义, 例, 练习)
- Include numbering by section
- Use Chinese punctuation in titles

### Avoid
- `\boxed{}` for inline math
- Mixed delimiters (`$$` vs `\[...\]`)
- Unicode characters in math mode
- Overusing display math for simple expressions

## Error Handling

### Common Issues

1. **File not found**: Check the input path
2. **Invalid style**: Use classic, simple, or boxed
3. **Backup errors**: Check file permissions

### Rollback

```bash
# List available backups
ls *.tex.*.bak

# Rollback to specific backup
latexify document.tex --rollback
```

## Performance

- Handles files up to 10MB efficiently
- Linear time complexity for transformations
- Memory efficient for large documents

## Dependencies

- Python 3.7+
- Standard library only (no external dependencies)

## License

Part of the Compound Engineering plugin collection.

## Contributing

Part of the Compound Engineering plugin collection. Issues and contributions welcome through the main repository.

