LaTeX Citation Intake Inserter
Overview
Use this skill after citation recommendations have been recorded in a Markdown intake sheet and the corresponding BibTeX entries are already present or have just been added. The goal is to update the LaTeX source cleanly without changing the prose beyond citation insertion.
Workflow
- Read the citation-intake Markdown file and preserve its row order.
- Read the target
.texfile and the target.bibfile. - For each intake row, map
Paper titleto the BibTeX citation key by title-first matching in the.bibfile.- Prefer an existing earlier key if the same title appears more than once.
- If a title is missing from the
.bibfile, add it with the BibTeX reference-adder workflow before editing the.texfile.
- Use the
Suggested insertion locationandSource text anchorfields to locate the target sentence or phrase in the.texfile. - Insert citations in intake-row order, using LaTeX nonbreaking citation style:
- Sentence-end support:
... claim~\cite{key}. - Phrase-level support before punctuation:
... phrase~\cite{key}, ... - Existing citation group: merge keys into the existing
\cite{...}instead of creating adjacent citations.
- Sentence-end support:
- Keep citations close to the supported claim; do not move citations to the end of a paragraph unless the intake sheet says so.
- Avoid duplicate citation commands for the same claim and key.
- Validate the result:
- Extract all
\cite{...}keys from the.texfile. - Extract all entry keys from the
.bibfile. - Report any missing keys and fix them before finishing.
- Extract all
Mapping Guidelines
- Match titles case-insensitively and ignore light differences in punctuation, braces, hyphenation, and capitalization.
- When multiple BibTeX entries match the same paper, use the key that best fits the existing chapter's citation style, usually the earliest non-duplicate key in the bibliography.
- Preserve all existing LaTeX commands, citation keys, labels, figures, and bibliography style.
- Do not edit unrelated grammar or content unless the user explicitly asks.
- After insertion, summarize the key mappings used and the validation result.
Useful Validation Commands
PowerShell citation-key check:
$tex = Get-Content -Raw -LiteralPath '<path-to-tex>'
$bib = Get-Content -Raw -LiteralPath '<path-to-bib>'
$citeKeys = [regex]::Matches($tex, '\\cite\{([^}]+)\}') | ForEach-Object { $_.Groups[1].Value -split '\s*,\s*' } | Sort-Object -Unique
$bibKeys = [regex]::Matches($bib, '@\w+\{([^,]+),') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique
$citeKeys | Where-Object { $_ -notin $bibKeys }