---
name: bibliography-builder
description: Build bibliographies from manuscript citations by extracting in-text citations, matching them against a references.bib file, identifying issues, and generating a formatted reference list.
title: bibliography-builder
canonical_url: https://skilld.dev/gh/nealcaren/social-data-analysis/bibliography-builder
last_updated: 2026-10-16T23:11:35.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [phases/phase0-intake.md](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/bibliography-builder/phases/phase0-intake.md), [phases/phase1-extraction.md](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/bibliography-builder/phases/phase1-extraction.md), [phases/phase2-matching.md](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/bibliography-builder/phases/phase2-matching.md), [phases/phase3-review.md](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/bibliography-builder/phases/phase3-review.md), [phases/phase4-generation.md](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/bibliography-builder/phases/phase4-generation.md).
>
> If the user asked to install this Skill, run `npx skilld install nealcaren/social-data-analysis/bibliography-builder`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/bibliography-builder`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/nealcaren/social-data-analysis/bibliography-builder) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/bibliography-builder`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/bibliography-builder --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/bibliography-builder --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Bibliography Builder

You help researchers **build bibliographies** from manuscript citations by extracting in-text citations, matching them against a local `references.bib` file, identifying issues, and generating a formatted reference list.

## Project Integration

This skill reads from `project.yaml` when available:

```yaml
# From project.yaml
paths:
  drafts: drafts/sections/
```

**Project type:** This skill works for **all project types**. Bibliography building is essential for any academic manuscript.

Updates `progress.yaml` when complete:
```yaml
status:
  bibliography: done
artifacts:
  bibliography: drafts/sections/bibliography.md
```

## File Management

This skill uses git to track progress across phases. Before modifying any output file at a new phase:
1. Stage and commit current state: `git add [files] && git commit -m "bibliography-builder: Phase N complete"`
2. Then proceed with modifications.

Do NOT create version-suffixed copies (e.g., `-v2`, `-final`, `-working`). The git history serves as the version trail.

## What This Skill Does

This is a **utility skill** that automates bibliography creation:

1. **Extract** all in-text citations from a document — supports both Pandoc `[@citationKey]` format and legacy `(Author Year)` format
2. **Match** each citation against the local `references.bib` file — direct `citationKey` lookup for Pandoc format, author+year string matching for legacy
3. **Review** for issues: missing items, ambiguous matches, duplicates
4. **Generate** a properly formatted bibliography in the requested style

## When to Use This Skill

Use this skill when you have:
- A **manuscript with in-text citations** — either Pandoc `[@citationKey]` format (from our writing skills) or legacy `(Author Year)` format
- A **`references.bib`** BibTeX file containing your library entries
- A need for a **formatted bibliography** (APA, ASA, Chicago, etc.)

**Pandoc format manuscripts** (written with our skills) get fast, deterministic matching via `citationKey` lookup directly in the `.bib` file. **Legacy format manuscripts** still work through author+year string matching against `.bib` entries.

## Requirements

- A **`references.bib`** BibTeX file containing the project's library entries. This file is typically located in the project root or a `references/` subdirectory and is populated by the local BibTeX pipeline (via `ingest.py`).
- **`pandoc`** installed with citeproc support (included by default in pandoc 2.11+). Used in Phase 4 to generate the formatted reference list.
- A **CSL style file** for the target citation style. Common styles:
  - ASA: `american-sociological-association.csl`
  - APA 7th: `apa.csl`
  - Chicago Author-Date: `chicago-author-date.csl`
  - Download from https://github.com/citation-style-language/styles if not already present. Place in project root or a `csl/` subdirectory.

## Workflow Phases

### Phase 0: Intake
**Goal**: Read the document and confirm citation style.

**Process**:
- Read the manuscript file
- Identify citation format (Author Year, Author-Year with comma, etc.)
- Count approximate citations
- Confirm output format (APA, ASA, Chicago Author-Date, etc.)

**Output**: Citation inventory with format confirmation.

> **Pause**: User confirms citation style and desired output format.

---

### Phase 1: Citation Extraction
**Goal**: Parse all in-text citations from the document.

**Process**:
- Use regex patterns to find Author-Year citations
- Handle variations:
  - Single author: `(Smith 2020)`
  - Two authors: `(Smith and Jones 2020)` or `(Smith & Jones 2020)`
  - Multiple authors: `(Smith et al. 2020)`
  - Multiple citations: `(Smith 2020; Jones 2019)`
  - Page numbers: `(Smith 2020, p. 45)` or `(Smith 2020: 45)`
  - Narrative citations: `Smith (2020) argues...`
- Deduplicate and sort alphabetically
- Create citation list with frequency counts
- **Verify with grep**: Run shell commands to independently confirm extraction caught all citations (catches edge cases like McAdam, hyphenated names, accented characters)

**Output**: Extraction results presented in conversation (not saved to a file).

> **Pause**: User reviews extracted citations for accuracy.

---

### Phase 2: BibTeX Matching
**Goal**: Find each citation in the local `references.bib` file.

**Process**:
- Read `references.bib` into memory
- For each extracted citation:
  - Pandoc format: look up `citationKey` directly against BibTeX entry keys
  - Legacy format: match author surname(s) and year against BibTeX `author` and `year` fields
  - Record match status: Found, Ambiguous, Not Found
- Build match table with BibTeX entry keys

**Output**: Match results presented in conversation (not saved to a file).

> **Pause**: User reviews matches, especially ambiguous/missing items.

---

### Phase 3: Issue Review
**Goal**: Identify and resolve problems.

**Process**:
- Flag issues:
  - **Missing**: Citations not found in `references.bib`
  - **Ambiguous**: Multiple possible matches (same author, year)
  - **Year mismatch**: Author found but year differs
  - **Name variations**: "Smith" vs "Smith, J." vs "Smith, John"
- Generate issue report with suggested actions
- User provides resolutions for ambiguous cases

**Output**: Issues presented in conversation (not saved to a file).

> **Pause**: User resolves any remaining issues.

---

### Phase 4: Bibliography Generation
**Goal**: Produce the formatted bibliography using pandoc with citeproc.

**Process**:
1. **Build a dummy markdown file** containing only the matched citation keys as pandoc citations:
   ```markdown
   ---
   bibliography: references.bib
   csl: american-sociological-association.csl
   nocite: |
     @smithHousing2020, @jonesUrban2019, @williamsRace2021
   ---
   # References
   ```
   The `nocite` field lists every matched citation key (from Phases 2–3). This tells pandoc to include them in the bibliography even though they're not cited inline.

2. **Run pandoc** to generate the formatted bibliography:
   ```bash
   pandoc dummy-refs.md --citeproc -o bibliography.md -t markdown
   ```
   Adjust the CSL file path as needed. Common styles:
   - ASA: `--csl american-sociological-association.csl`
   - APA 7th: `--csl apa.csl`
   - Chicago: `--csl chicago-author-date.csl`

3. **Clean up**: Remove the dummy file. Review `bibliography.md` for any citeproc warnings (missing fields, unresolved keys).

4. **Append unmatched citations** (from Phase 3) as a separate section at the end of `bibliography.md`:
   ```markdown
   ## Unmatched Citations (require manual lookup)
   - Smith (2020) — Not found in references.bib
   ```

**Output**: `bibliography.md` with pandoc/citeproc-formatted references.

**Why pandoc?** Pandoc's citeproc engine handles the full complexity of citation formatting — name particles, edited volumes, translations, sorting, punctuation — far more reliably than manual formatting. It uses the same CSL styles as Zotero, Mendeley, and other reference managers.

---

## Citation Pattern Reference

### Pandoc Format (Primary — from our writing skills)

| Pattern | Example | Regex |
|---------|---------|-------|
| Parenthetical | `[@smithHousing2020]` | `\[@([a-zA-Z0-9]+)\]` |
| Multiple | `[@smith2020; @jones2019]` | `\[@([a-zA-Z0-9]+(?:;\s*@[a-zA-Z0-9]+)*)\]` |
| With page | `[@smith2020, p. 45]` | `\[@([a-zA-Z0-9]+),\s*p\.\s*\d+\]` |
| Narrative | `@smithHousing2020 argues` | `(?<!\[)@([a-zA-Z0-9]+)(?!\])` |
| Suppress author | `[-@smith2020]` | `\[-@([a-zA-Z0-9]+)\]` |
| String modifiers | `[see @key1; cf. @key2]` | `\[(?:see\|e\.g\.,\|cf\.)\s*@` |

### Legacy Format (Fallback — for manuscripts not written with our skills)

| Pattern | Example | Regex |
|---------|---------|-------|
| Single author | `(Smith 2020)` | `\(([A-Z][a-z]+)\s+(\d{4})\)` |
| Two authors | `(Smith and Jones 2020)` | `\(([A-Z][a-z]+)\s+(?:and|&)\s+([A-Z][a-z]+)\s+(\d{4})\)` |
| Et al. | `(Smith et al. 2020)` | `\(([A-Z][a-z]+)\s+et\s+al\.?\s+(\d{4})\)` |
| Multiple citations | `(Smith 2020; Jones 2019)` | Split on `;\s*` then parse each |
| With page | `(Smith 2020, p. 45)` | `\(([A-Z][a-z]+)\s+(\d{4}),?\s*p?p?\.?\s*\d+\)` |
| Narrative | `Smith (2020)` | `([A-Z][a-z]+)\s+\((\d{4})\)` |

### Edge Cases (Legacy Format)

- **Hyphenated names**: `(García-López 2020)` - include hyphen in author pattern
- **Particles**: `(van der Berg 2020)` - lowercase particles before surname
- **Organizations**: `(WHO 2020)` - all-caps or mixed case organizations
- **No date**: `(Smith n.d.)` - handle "n.d." as year placeholder
- **Forthcoming**: `(Smith forthcoming)` - handle non-numeric years

## Output Formats

Formatting is handled entirely by pandoc's citeproc engine using CSL style files. You do **not** need to manually format entries. Simply specify the correct CSL file for the target style:

| Style | CSL file | Notes |
|-------|----------|-------|
| ASA | `american-sociological-association.csl` | Default for sociology journals |
| APA 7th | `apa.csl` | Psychology and interdisciplinary |
| Chicago Author-Date | `chicago-author-date.csl` | History, some social sciences |

Download CSL files from https://github.com/citation-style-language/styles if not already present in the project.

## File Structure

```
project/
├── manuscript.md           # Input: document with citations
├── bibliography/
│   └── bibliography.md     # Final output (Phase 4)
```

Phases 1–3 produce conversation output only. No intermediate files are saved.

## Key Reminders

- **`references.bib` must be present** and readable in the project directory
- **Author names vary**: Match flexibly against the BibTeX `author` field (last name + year first, then refine)
- **Multiple matches are possible**: Same author may have multiple works per year in the `.bib` file
- **Missing items**: User may need to add entries to `references.bib` before proceeding
- **Format matters**: Confirm desired style before generating bibliography

## Starting the Process

When the user is ready to begin:

1. **Ask for the manuscript**:
   > "Please share the path to your manuscript file (markdown, .docx, or .txt)."

2. **Confirm citation style**:
   > "I'll extract Author-Year citations. What bibliography format do you need? (APA, ASA, Chicago, other)"

3. **Locate `references.bib`**:
   > "Let me verify the `references.bib` file is present. Is it in the project root or a `references/` subdirectory?"

4. **Proceed with Phase 0** to read the document and inventory citations.
