# Using KaTeX in AutEng

> Practical guide to integrating mathematical equations in your documentation

## Why KaTeX for Documentation?

KaTeX is a fast, self-contained JavaScript library for rendering TeX math notation on the web. Unlike MathJax, KaTeX is designed for speed and doesn't require external fonts or network requests after initial load.

### AutEng Has KaTeX Built-In

- **No setup required:** KaTeX is fully integrated and configured in AutEng
- **Just start writing:** Use standard LaTeX math syntax in your markdown
- **Fast rendering:** Equations render instantly as you type
- **AI-powered generation:** AutEng can generate markdown with KaTeX equations
- **LaTeX compatibility:** Supports most common LaTeX math commands

For technical documentation, especially in fields like computer science, mathematics, physics, or data science, the ability to render equations inline with your prose is essential. AutEng makes this seamless with zero configuration.

## Using KaTeX in AutEng

AutEng has KaTeX fully integrated and configured. You don't need to install anything or configure any processors. Just start writing math equations using standard LaTeX syntax in your markdown documents.

### Quick Start

1. **Create a new document** in AutEng or open an existing one
2. **Write your markdown** with math equations using $...$ for inline or $$...$$ for display math
3. **See instant preview** - equations render automatically as you type
4. **Use AI generation** - Ask AutEng to generate markdown with mathematical equations

### AI-Powered Math Generation

AutEng's AI can generate markdown documents with properly formatted KaTeX equations. Try prompts like:

- "Generate a proof that √2 is irrational"
- "Create documentation for the gradient descent algorithm with equations"
- "Write a guide to Big O notation with mathematical examples"
- "Document the backpropagation algorithm with all the math"

## Math Syntax in Markdown

KaTeX uses standard LaTeX delimiters for inline and display math. Understanding these delimiters is crucial for proper rendering.

### Inline Math

Use single dollar signs $...$ for inline equations:

```markdown

The quadratic formula $x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$ solves quadratic equations.

Einstein's famous equation $E = mc^2$ relates energy and mass.

The derivative $\\frac{dy}{dx}$ represents the rate of change.

```

### Display Math (Block)

Use double dollar signs $$...$$ for centered display equations:

```markdown

$$
\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}
$$

$$
\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}
$$

$$
\\nabla \\times \\mathbf{E} = -\\frac{\\partial \\mathbf{B}}{\\partial t}
$$

```

### Multi-line Equations

Use the aligned environment for aligned equations:

```markdown

$$
\\begin{aligned}
f(x) &= x^2 + 2x + 1 \\\\
     &= (x + 1)^2 \\\\
     &= (x + 1)(x + 1)
\\end{aligned}
$$

```

## Common Use Cases

### Algorithm Complexity

### Probability & Statistics

### Linear Algebra

### Machine Learning

## Best Practices

### 1. Use Semantic Variable Names

Choose variable names that convey meaning, especially in documentation:

### 2. Add Explanatory Text

Always explain equations in prose. Don't assume readers understand notation:

### 3. Break Complex Equations

Split complex derivations into steps for clarity:

### 4. Use Consistent Notation

Maintain consistent notation throughout your documentation. If you use $\theta$ for parameters in one section, don't switch to $w$ in another without explanation.

### 5. Test Rendering

Always preview your equations in the actual rendering environment. What works in one KaTeX setup might not work in another due to configuration differences.

## Common Pitfalls & Solutions

### Pitfall: Escaping Backslashes

In many Markdown processors, backslashes need to be escaped:

### Pitfall: Underscore Conflicts

Underscores in math can conflict with Markdown emphasis:

### Pitfall: Unsupported Commands

KaTeX doesn't support all LaTeX commands. Check the [supported functions list](https://katex.org/docs/supported.html) .

### Pitfall: Missing CSS

If equations render as plain text or look broken, ensure you've imported the KaTeX CSS file. This is the most common setup issue.

## Advanced Techniques

### Custom Macros

Define custom macros for frequently used notation:

### Colored Equations

Use color to highlight parts of equations:

### Equation Numbering

Add equation numbers for reference:

## Performance Considerations

### Optimization Tips

- **Server-side rendering:** Pre-render equations on the server to reduce client-side processing
- **Lazy loading:** Load KaTeX only on pages that contain math
- **Caching:** Cache rendered equations to avoid re-rendering on every page load
- **Minimize equations:** Use inline math sparingly; too many equations can slow page rendering
- **Font subsetting:** If using custom fonts, subset them to include only needed glyphs
