book/tools/scripts/content/README_CITATION_VALIDATION.md
The citation validation script ensures that all @key citation references in .qmd files have corresponding entries in their associated .bib files. This prevents Quarto build failures caused by missing bibliography entries.
The validation runs automatically when you commit .qmd files:
git add myfile.qmd
git commit -m "Update chapter"
If there are missing citations, the commit will fail with output like:
❌ CITATION VALIDATION FAILED
The following .qmd files reference citations that are missing from their .bib files:
📄 quarto/contents/core/conclusion/conclusion.qmd:
❌ @koomey2011web
❌ @han2015deep
❌ @openai2023gpt4
❌ @vaswani2017attention
You can also run the validation manually:
python tools/scripts/content/validate_citations.py chapter.qmd
python tools/scripts/content/validate_citations.py -d quarto/contents/core/
python tools/scripts/content/validate_citations.py -d quarto/contents/ --quiet
bibliography: field from the .qmd file's YAML frontmatter.qmd file for all @key patterns@fig-, @tbl-, @sec-, etc..bib fileWhen validation fails, you have several options:
Search for the citation key in other .bib files:
grep -r "@article{koomey2011web" quarto/contents/
Copy the BibTeX entry to your chapter's .bib file
Use tools like:
If the citation is no longer needed, remove the @key reference from the .qmd file.
The validator recognizes various citation formats:
[@key] - Standard citation@key - Inline citation[@key1; @key2] - Multiple citations[-@key] - Suppress author citation[@key, p. 123] - Citation with page numbersThe validator filters out cross-references to figures, tables, sections, etc. These are not citations:
@fig-architecture ✓ (ignored)@tbl-results ✓ (ignored)@sec-introduction ✓ (ignored)@eq-formula ✓ (ignored)If you see:
❌ Bibliography file not found: chapter.bib
Make sure:
.bib file exists in the same directory as the .qmd filebibliography: field in the YAML frontmatter is correctThis validation runs before the Quarto build, catching issues early:
Pre-commit → Citation Validation → Git Commit → Quarto Build
This saves time by preventing failed builds due to missing citations.
$ python tools/scripts/content/validate_citations.py conclusion.qmd
✅ All citations validated successfully (1 files checked)
$ python tools/scripts/content/validate_citations.py conclusion.qmd
❌ CITATION VALIDATION FAILED
📄 quarto/contents/core/conclusion/conclusion.qmd:
❌ @smith2020deep
❌ @jones2021ml
To fix these issues:
1. Find the citation entry in another chapter's .bib file
2. Copy the BibTeX entry to the appropriate .bib file
3. Or remove the citation reference if it's no longer needed
clean_bibliographies.py - Remove unused entries from .bib filesfix_bibliography.py - Update citation key formats.pre-commit-config.yaml - Pre-commit hook configuration