# How the AI Job Search Framework Handles LaTeX and Typst Document Templates

> Discover how the AI Job Search framework uses LaTeX and Typst templates to generate PDFs for CVs and cover letters via a command-line toolchain and registration system.

- Repository: [Mads Lorentzen/ai-job-search](https://github.com/MadsLorentzen/ai-job-search)
- Tags: internals
- Published: 2026-09-03

---

**The AI Job Search framework treats CVs and cover letters as template-driven documents that compile to PDF via any command-line toolchain, with built-in support for LaTeX and Typst through a registration and manifest system.**

The MadsLorentzen/ai-job-search repository implements a flexible document generation pipeline where users can bring their own LaTeX or Typst designs into the automated job application workflow. By treating templates as pluggable components with mandatory compilation testing, the framework ensures that every document renders correctly before it reaches the `/apply` stage.

## Template Registration via the `/add-template` Command

The `/add-template` command, defined in [[`.claude/commands/add-template.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/commands/add-template.md)](https://github.com/MadsLorentzen/ai-job-search/blob/master/.claude/commands/add-template.md), serves as the entry point for integrating custom document designs.

When you invoke this command, the system:

1. Parses arguments to determine template type (CV or cover letter)
2. Collects metadata including source extension, compile command, fonts, and page limits
3. Stores files under the `templates/` directory with a mandatory test compile step

The registration process enforces a **mandatory test compile** (Step 4 in the specification) to guarantee that the template builds successfully on your local machine before activation. This prevents runtime failures during the actual job application phase.

## The TEMPLATE.md Manifest System

Every registered template folder contains a [`TEMPLATE.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/TEMPLATE.md) manifest file that records the collected metadata and exact compile command. This manifest acts as the single source of truth for the compilation engine.

The framework reads this manifest during the `/apply` execution to determine which engine to invoke:

- `lualatex` for LaTeX templates
- `typst compile` for Typst documents
- User-defined commands for custom toolchains

By externalizing the build configuration into the manifest, the system decouples document drafting from rendering, allowing the same profile data to populate different template engines without code changes.

## Template Activation via Managed Blocks

When a template is activated, the framework injects a **managed block** into the corresponding guidance file—either [`05-cv-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/05-cv-templates.md) or [`06-cover-letter-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/06-cover-letter-templates.md) located in `.claude/skills/job-application-assistant/`.

This managed block tells `/apply` exactly where to find the skeleton file (`templates/<type>/<name>/template<ext>`) and which compile command to execute. The block format appears as:

```markdown
<!-- BEGIN ACTIVE-TEMPLATE (managed by /add-template - do not edit by hand) -->
> **Active template override: `my-awesome-cv`**
>
> - **Template skeleton:** `templates/cv/my-awesome-cv/template.tex`
> - **Compile command:** `lualatex -interaction=nonstopmode <file>.tex`
> - **Page limit:** exactly 2 page(s)
<!-- END ACTIVE-TEMPLATE -->

```

Because the active template is referenced only within this managed block, switching templates becomes atomic and reversible without modifying core workflow logic.

## Compilation and PDF Verification

During the `/apply` execution, the framework drafts a LaTeX or Typst source file populated with your profile data, then executes the compile command recorded in the manifest.

After compilation, [`tools/verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/tools/verify_pdf.py) inspects the generated PDF to enforce quality constraints:

- **Page count verification** against declared limits
- **Extractable text validation** to ensure ATS readability

This verification step ensures that custom templates meet the same quality standards as the stock `moderncv` and `cover.cls` templates shipped with the framework.

## Extensibility Beyond LaTeX and Typst

While the stock templates use LaTeX (moderncv for CVs and custom `cover.cls` for cover letters), the registration flow supports any toolchain that produces PDF from the command line.

To add a custom pipeline (such as a Pandoc workflow), you only need to provide:

- The appropriate `source-extension` (e.g., `.md`)
- The `compile-command` that generates the PDF
- A successful test compile during registration

All other workflow components—ranking algorithms, drafting logic, and reviewer feedback—remain unchanged, treating the final PDF as the universal artifact regardless of its source format.

## Practical Examples

### Registering a Custom LaTeX Template

```bash
/add-template

# → Select type: "CV"

# → Provide path to your moderncv-style .tex file

# → System infers engine: lualatex -interaction=nonstopmode <file>.tex

# → Complete metadata and test compile

```

### Registering a Typst Template

```bash
/add-template

# → Select type: "Cover letter"

# → Provide source: my_cover.typ

# → Auto-detected compile command: typst compile <file>.typ <file>.pdf

# → Test compile validates the template

```

### Switching Between Templates

```bash

# Activate a previously registered template

/add-template --use my-awesome-cv

# Revert to stock templates

/add-template --use default

```

## Summary

- The **template registration workflow** (`/add-template`) requires a mandatory test compile before activation, ensuring reliability.
- Each template stores metadata in a **[`TEMPLATE.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/TEMPLATE.md) manifest** that records the exact compile command for later use by `/apply`.
- **Managed blocks** in guidance files ([`05-cv-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/05-cv-templates.md) and [`06-cover-letter-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/06-cover-letter-templates.md)) provide atomic template switching without core workflow modifications.
- Post-compilation verification via **[`tools/verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/tools/verify_pdf.py)** enforces page limits and ATS readability standards.
- The architecture supports **any command-line PDF toolchain**, including LaTeX, Typst, or custom pipelines like Pandoc, through configurable source extensions and compile commands.

## Frequently Asked Questions

### Can I use Typst instead of LaTeX for my CV?

Yes. The framework treats Typst as a first-class citizen alongside LaTeX. When you register a `.typ` file via `/add-template`, the system auto-detects `typst compile` as the build command and stores it in the template's [`TEMPLATE.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/TEMPLATE.md) manifest. The `/apply` command will then invoke Typst rather than LaTeX when generating your documents.

### How does the framework ensure my custom template actually works?

The `/add-template` command enforces a **mandatory test compile** during registration (Step 4 in the specification). Before the template is activated, the framework attempts to build it using your provided compile command. If the test fails, registration aborts, preventing broken templates from entering the production workflow.

### What happens if I want to revert to the default templates?

You can reset to the stock templates at any time by running `/add-template --use default`. This command removes the managed block from the guidance files, causing `/apply` to fall back to the built-in moderncv (for CVs) and cover.cls (for cover letters) templates located in `cv/main_example.tex` and `cover_letters/cover.cls`.

### Can I use a document generation tool other than LaTeX or Typst?

Yes. The framework's architecture supports any toolchain that produces PDF via command-line execution. During registration, simply provide your custom `source-extension` (e.g., `.html`, `.md`) and the appropriate `compile-command` (e.g., `pandoc <file>.md -o <file>.pdf`). As long as the mandatory test compile succeeds, the framework will treat the output identically to LaTeX or Typst generated PDFs.