# How AI Job Search Maintains Professional Document Quality: A Technical Deep Dive

> Discover how AI Job Search ensures professional document quality using LaTeX templates, automated checks, ATS verification, and content trimming. Learn the technical pipeline.

- Repository: [Mads Lorentzen/ai-job-search](https://github.com/MadsLorentzen/ai-job-search)
- Tags: deep-dive
- Published: 2026-08-25

---

**AI Job Search maintains professional document quality through a defense-in-depth pipeline combining authoritative LaTeX templates, automated compile-and-inspect loops, ATS-aware verification, and relevance-weighted content trimming.**

The `MadsLorentzen/ai-job-search` repository implements a rigorous document generation system that ensures every CV and cover letter meets professional publishing standards. By integrating template-based formatting with automated validation workflows, the system produces ATS-compatible PDFs that adhere to strict page budgets and typography conventions.

## LaTeX Templates as the Foundation for Professional Layout

The system relies on fixed LaTeX sources to enforce consistent visual standards across all generated documents. These templates eliminate variability in fonts, spacing, and page structure.

### CV Templates with moderncv

The repository uses the **moderncv** document class for curriculum vitae, defined in [`.claude/skills/job-application-assistant/05-cv-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/skills/job-application-assistant/05-cv-templates.md). This template enforces a strict **two-page maximum** through fixed LaTeX preamble settings that control margins, section spacing, and font hierarchies.

The template also defines **language-aware headings** to prevent mismatched bilingual documents. When the CV language differs from English, section titles like "Professional Experience" must be translated to match the document's primary language, ensuring semantic consistency throughout.

### Cover Letter Templates with cover.cls

For cover letters, the system employs a custom `cover.cls` template defined in [`.claude/skills/job-application-assistant/06-cover-letter-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/skills/job-application-assistant/06-cover-letter-templates.md). This class enforces a **single-page constraint** through optimized vertical spacing rules and prevents overflow through automatic font size adjustments and paragraph tightening.

## The Compile-and-Inspect Loop for Layout Validation

After each draft generation, the system executes a compile-and-inspect loop that validates document integrity before proceeding to the next workflow stage.

### Page Count Enforcement

The workflow invokes specific LaTeX engines based on document type:

```bash
cd cv && lualatex -interaction=nonstopmode main_acme_corporation_software_engineer.tex

```

For cover letters, the system uses `xelatex` to handle custom font requirements. The compilation must complete without errors and produce output matching the exact page budget—**two pages for CVs, one page for cover letters**. The system parses the compilation log for the string `Output written on …pdf (2 pages, …)` to confirm compliance.

### Dynamic Layout Adjustments

When preliminary compilation exceeds page limits, the system automatically injects spacing commands. The template documentation specifies using `\needspace{5\baselineskip}` to prevent orphaned section headers or `\enlargethispage{2-3\baselineskip}` to slightly extend text areas when content barely overflows.

## ATS Verification Through PDF Text Layer Analysis

The repository includes [`tools/verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/tools/verify_pdf.py), a Python utility that validates the machine-readability of generated documents—critical for Applicant Tracking System (ATS) compatibility.

### verify_pdf.py Implementation

The verification script performs three distinct checks:

1. **Page count validation** using `pdfinfo` to confirm exact page numbers
2. **Text layer extraction** using `pdftotext` to verify the PDF contains sufficient extractable content
3. **Content presence verification** to ensure required fields (name, email, phone) appear in the text extraction

### Text Extraction and Validation

Invoke the verifier with specific constraints:

```bash
python3 tools/verify_pdf.py cv/main_acme_corporation_software_engineer.pdf \
    --pages 2 \
    --min-chars 100 \
    --contains "John Doe" \
    --contains "john.doe@example.com"

```

The script raises a `VerificationError` if the PDF fails any criterion. This catches silent LaTeX bugs such as unescaped special characters that render visually but disappear from the text layer, or missing contact information caused by template syntax errors.

## Content Optimization Through Relevance-Weighted Cutting

When CV content exceeds the two-page budget, the system implements **relevance-weighted cutting** rather than arbitrary truncation. As detailed in the CV template file, each line receives a score based on:

- **Relevance to the target posting**: Alignment with job requirements
- **Uniqueness**: Distinctiveness compared to other entries
- **Cover letter dependence**: Whether the detail is elaborated elsewhere

The lowest-scoring lines are removed iteratively until the document fits the page constraint, ensuring only the most pertinent professional information survives the editing process.

## Special Character Handling and Internationalization

The system prevents compilation failures and content loss through rigorous preprocessing of input text.

### LaTeX Escaping Rules

A defined escape table in the CV template documentation requires preprocessing all user input and job posting data before LaTeX insertion:

```python
def escape_latex(text: str) -> str:
    return text.replace('%', r'\%') \
               .replace('&', r'\&') \
               .replace('$', r'\$') \
               .replace('#', r'\#') \
               .replace('_', r'\_')

```

This function ensures that symbols originating from external sources never break compilation or silently drop content—particularly critical for the percent symbol (`%`), which LaTeX interprets as a comment starter unless escaped.

### Language-Aware Section Headings

The CV template enforces translation requirements for section headings. When generating a document in Danish, for example, "Professional Experience" must become "Erhvervserfaring". This validation occurs during the drafting phase to prevent mixed-language documents that appear unprofessional to recruiters.

## The /apply Command: Orchestrating the Quality Pipeline

The `/apply` command, defined in [`.claude/commands/apply.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/commands/apply.md), implements a **drafter-reviewer pattern** that orchestrates the entire quality assurance pipeline:

```bash
claude

# Inside Claude Code:

/apply https://jobindex.dk/job/1234567

```

This command automatically:
1. Generates initial drafts using the LaTeX templates
2. Spawns a reviewer agent to critique content relevance
3. Invokes the compile-and-inspect loop with `lualatex` or `xelatex`
4. Executes [`verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/verify_pdf.py) for ATS compatibility checking
5. Applies relevance-weighted cutting if page limits are exceeded
6. Returns polished PDFs only after all validation layers pass

## Summary

- **Authoritative LaTeX templates** in [`.claude/skills/job-application-assistant/05-cv-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/skills/job-application-assistant/05-cv-templates.md) and [`06-cover-letter-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/06-cover-letter-templates.md) enforce strict typography and page layout standards.
- **Compile-and-inspect loops** using `lualatex` and `xelatex` validate that CVs occupy exactly two pages and cover letters exactly one page.
- **ATS verification** via [`tools/verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/tools/verify_pdf.py) confirms text layer integrity and required field presence using `pdfinfo` and `pdftotext`.
- **Relevance-weighted cutting** prioritizes job-specific content when trimming excess material to meet page budgets.
- **Special-character escaping** prevents LaTeX compilation errors and silent content loss from unescaped `%`, `&`, `$`, `#`, and `_` characters.
- **The `/apply` command** automates the entire quality pipeline, ensuring every generated document meets professional standards before delivery.

## Frequently Asked Questions

### How does AI Job Search ensure CVs don't exceed two pages?

The system enforces a hard constraint through the moderncv template configuration and the compile-and-inspect loop. After each `lualatex` compilation, the workflow checks the output log for the exact page count. If the document exceeds two pages, the relevance-weighted cutting algorithm removes the lowest-scoring content lines until the document fits, then recompiles.

### What prevents special characters from breaking LaTeX compilation?

All input text passes through the `escape_latex()` function before template insertion, which escapes LaTeX-reserved characters including `%`, `&`, `$`, `#`, and `_` with backslash prefixes. This preprocessing happens automatically during the drafting phase, ensuring that job posting descriptions or user profile data containing these symbols render correctly in the PDF and remain present in the text layer.

### How does the system verify ATS compatibility?

The [`verify_pdf.py`](https://github.com/MadsLorentzen/ai-job-search/blob/main/verify_pdf.py) tool extracts the text layer from generated PDFs using `pdftotext` and validates three criteria: exact page count (using `pdfinfo`), minimum character count (to detect missing text), and presence of required strings like candidate name and email. This catches formatting errors where visual content exists but machine-readable text is absent or corrupted.

### Where are the template definitions stored in the repository?

Template specifications reside in [`.claude/skills/job-application-assistant/05-cv-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/skills/job-application-assistant/05-cv-templates.md) for CVs (using moderncv) and [`.claude/skills/job-application-assistant/06-cover-letter-templates.md`](https://github.com/MadsLorentzen/ai-job-search/blob/main/.claude/skills/job-application-assistant/06-cover-letter-templates.md) for cover letters (using a custom `cover.cls`). These files define LaTeX preamble settings, special character escape rules, language translation requirements, and the relevance-weighted cutting algorithm parameters.