Index of every page on this site: llms.txt
All skills
nealcaren avatar

/bibliography-builder

@527018c
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/nealcaren/social-data-analysis/bibliography-builder

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

phasesphase1-extraction.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Phase 1: Citation Extraction

Why This Phase Matters

Accurate extraction is the foundation. Missing a citation means an incomplete bibliography; mis-parsing a name means a failed library match. This phase uses pattern matching to find all citations and normalize them for lookup.

Your Tasks

1. Extract All Citations

First determine the citation format (from Phase 0 intake). Use the appropriate extraction strategy.

Pandoc Format Extraction (Primary)

If the manuscript uses [@citationKey] syntax (from our writing skills), extract keys directly:

import re

# Bracketed citations: [@key], [@key1; @key2], [@key, p. 45], [-@key]
bracketed = re.findall(r'\[[-]?@([a-zA-Z][a-zA-Z0-9]*(?:;\s*@[a-zA-Z][a-zA-Z0-9]*)*(?:,\s*p\.\s*\d+(?:[-–]\d+)?)?)\]', text)

# Parse individual keys from bracketed matches
citation_keys = set()
for match in bracketed:
    # Split multi-citations on '; @'
    for part in re.split(r';\s*@', match):
        key = re.match(r'([a-zA-Z][a-zA-Z0-9]*)', part.lstrip('@'))
        if key:
            citation_keys.add(key.group(1))

# Narrative citations: @key (not inside brackets)
narrative = re.findall(r'(?<!\[[-]?)(?<!\[)@([a-zA-Z][a-zA-Z0-9]+)(?!\])', text)
for key in narrative:
    citation_keys.add(key)

Output: A list of unique citation keys. No author/year parsing needed — keys are the identifiers.

Legacy Format Extraction (Fallback)

If the manuscript uses (Author Year) format, use the original regex patterns:

Parenthetical citations:

# Single author
r'\(([A-Z][a-zà-ÿ\-\']+)\s+(\d{4}[a-z]?)\)'
# Example: (Smith 2020), (García 2019a)

# Two authors with "and"
r'\(([A-Z][a-zà-ÿ\-\']+)\s+and\s+([A-Z][a-zà-ÿ\-\']+)\s+(\d{4}[a-z]?)\)'
# Example: (Smith and Jones 2020)

# Two authors with "&"
r'\(([A-Z][a-zà-ÿ\-\']+)\s+&\s+([A-Z][a-zà-ÿ\-\']+)\s+(\d{4}[a-z]?)\)'
# Example: (Smith & Jones 2020)

# Et al.
r'\(([A-Z][a-zà-ÿ\-\']+)\s+et\s+al\.?\s+(\d{4}[a-z]?)\)'
# Example: (Smith et al. 2020)

# With page numbers
r'\(([A-Z][a-zà-ÿ\-\']+(?:\s+(?:and|&)\s+[A-Z][a-zà-ÿ\-\']+)?(?:\s+et\s+al\.?)?)\s+(\d{4}[a-z]?)[,:]?\s*(?:pp?\.?\s*)?\d+(?:[-–]\d+)?\)'

Narrative citations:

# Author (Year)
r'([A-Z][a-zà-ÿ\-\']+(?:\s+(?:and|&)\s+[A-Z][a-zà-ÿ\-\']+)?(?:\s+et\s+al\.?)?)\s+\((\d{4}[a-z]?)\)'
# Example: Smith (2020), Smith and Jones (2020)

Multiple citations in one parenthetical:

# Split on semicolon first, then parse each
r'\(([^)]+;\s*[^)]+)\)'
# Then split contents on '; ' and parse individually

2. Normalize Each Citation

For each extracted citation, create a normalized record:

Field Description
raw Original text as found
first_author Last name of first author
second_author Last name of second author (if any)
et_al Boolean: true if "et al." present
year Publication year
year_suffix Letter suffix if present (a, b, c)
page Page number(s) if present

3. Deduplicate

  • Combine identical citations (same author(s) + year)
  • Track frequency (how many times each appears)
  • Note variations (same work cited with/without pages)

4. Sort Alphabetically

Sort by:

  1. First author last name
  2. Year
  3. Year suffix (a, b, c)

5. Flag Potential Issues

Mark citations that may cause problems:

  • Ambiguous names: Common surnames (Smith, Lee, etc.)
  • Et al. citations: Will need full author list from references.bib
  • Year suffixes: May indicate multiple works by same author
  • Unusual formats: Anything that didn't match standard patterns

6. Verify Extraction with Grep

Critical step: Use shell commands to independently verify the extraction caught everything. This catches citations that may have been missed by the initial regex patterns.

Run these verification commands:

# Find all parenthetical citations
grep -oE '\([A-Z][a-zA-Z-]+[^)]*[0-9]{4}[a-z]?\)' document.md | sort | uniq -c | sort -rn

# Find narrative citations (Author (Year) and Author's (Year))
grep -oE "[A-Z][a-zA-Z-]+[''']?s? \([0-9]{4}[a-z]?\)" document.md | sort | uniq

# Find all multi-citation parentheticals (contain semicolons)
grep -oE '\([^)]+;[^)]+\)' document.md | sort | uniq

# List all years mentioned (to cross-check against citations)
grep -oE '\b(19[89][0-9]|20[0-2][0-9])[a-z]?\b' document.md | sort | uniq -c | sort -rn

Compare results:

  1. Count unique citations from grep output
  2. Compare against your extracted list
  3. Investigate any discrepancies:
    • Years in document that aren't citations (historical dates, sample info)
    • Citations grep found that regex missed
    • Edge cases (hyphenated names, accented characters, possessives)

Common issues to check:

  • Names with internal capitals (McAdam, DeMichele, van Stekelenburg)
  • Possessive forms (McAdam's (1989))
  • Accented characters (García, Eklöf)
  • Hyphenated names (Corrigall-Brown, Cohen-Eick)
  • Three+ author citations with commas

If grep finds citations not in your list, add them before proceeding.

Output: Citations Extracted

Present extraction results in conversation using this format (do not save to a file):

**Document**: [filename]
**Total instances**: [X]
**Unique citations**: [X]

## Citation List

| # | Citation | First Author | Year | Frequency | Notes |
|---|----------|--------------|------|-----------|-------|
| 1 | Smith 2020 | Smith | 2020 | 5 | |
| 2 | Smith and Jones 2019 | Smith | 2019 | 2 | Two authors |
| 3 | García et al. 2021 | García | 2021 | 3 | Et al. - need full list |
| 4 | Lee 2020a | Lee | 2020a | 1 | Year suffix |
| ... | ... | ... | ... | ... | ... |

## Potential Issues

- **Common names**: Smith (3 different years), Lee (2 different works 2020)
- **Et al. citations**: 5 citations need full author lists
- **Unusual patterns**: [any that needed manual parsing]

## Grep Verification

**Parenthetical citations found:**
[paste grep output here]

**Narrative citations found:**
[paste grep output here]

**Verification result:** [X] citations extracted, [X] confirmed by grep. [Match/Discrepancies noted]

When You're Done

Present the extraction results in conversation. Ask:

  1. Are all citations captured?
  2. Any obvious misses or misparsings?
  3. Ready to proceed to references.bib matching?

Once confirmed, proceed to Phase 2: Library Matching.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    The bibliography-builder skill automates academic citation extraction and matching using standard tools like git, grep, and pandoc. While functional, it processes untrusted user-provided manuscript and BibTeX files, which creates an attack surface for indirect prompt injection and potential command injection.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at 527018c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated last month

README badge

README badge for nealcaren/social-data-analysis/bibliography-builder