check-labels-and-refs
Scan LaTeX files for label/reference consistency, orphan labels/refs, and non-pinpoint cross-references
- License 许可
- GPL-3.0
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- check-labels-and-refs
- status
- PRELIMINARY (DRY-RUN ONLY)
- description
- Scan LaTeX files for label/reference consistency, orphan labels/refs, and non-pinpoint cross-references
02 资源文件 1
- 脚本check-labels-and-refs.sh5.2 KB
03 SKILL.md 正文
Check LaTeX Labels and References
Scans LaTeX documents for \label{}, \ref{}, \eqref{}, \autoref{} patterns to identify:
- Orphan labels: Labels defined but never referenced
- Orphan refs: References to undefined labels
- Non-pinpoint refs: Bare text references (e.g., "see Section 2" instead of
\ref{sec:foo})
Handles \input and \include closure up to depth 2.
Usage
check-labels-and-refs <tex-file-path> [output-dir]
Arguments
<tex-file-path>— Root LaTeX file to scan (required)[output-dir]— Output directory for JSON report (optional, defaults to <city-root>/tmp-for-review/)
Output
Produces check-labels-and-refs-report.json with structure:
{
"file": "<path-to-root-file>",
"sha": "<git-sha-of-file>",
"scan_depth": 2,
"verdict": "PASS|FAIL",
"labels": {
"<label-name>": {
"location": "<file>:<line>",
"referenced_from": ["<file>:<line>", ...]
}
},
"references": {
"<label-name>": {
"locations": ["<file>:<line>", ...],
"label_found": true|false,
"reference_type": "ref|eqref|autoref"
}
},
"orphan_labels": ["<label-name>", ...],
"orphan_refs": ["<label-name>", ...],
"non_pinpoint_refs": [
{
"file": "<file>",
"line": <line-number>,
"context": "<quoted-text>",
"pattern": "bare-section|bare-theorem|bare-equation"
}
],
"counts": {
"total_labels": <int>,
"total_refs": <int>,
"orphan_label_count": <int>,
"orphan_ref_count": <int>,
"non_pinpoint_count": <int>
}
}
Implementation
The skill uses bash/grep to scan LaTeX files. For each .tex file:
- Collect labels: Extract all
\label{<name>}patterns - Collect references: Extract all
\ref{<name>},\eqref{<name>},\autoref{<name>}patterns - Cross-reference: Match refs to labels
- Detect orphans: Find labels with no refs and refs with no labels
- Detect non-pinpoint: Grep for bare-text patterns like "Section \d+", "Theorem \d+", "Equation \d+"
- Handle closure: Recursively scan
\input{<file>}and\include{<file>}up to depth 2
Limitations
- Depth cap: Only scans
\input/\includeto depth 2. References to depth-3+ files are silently ignored. Report header documents this cap. - Comments: Does not skip LaTeX comments (
%...), so commented-out\label{}/\ref{}may be incorrectly counted. - \cite{}: Does NOT scan citation patterns (
\cite{}). That is the domain of check-citations skill. - Macros: Does not expand LaTeX macros, so references inside macro expansions may be missed.
- Non-ASCII: Assumes UTF-8 encoding.
Notes
- Non-pinpoint detection ships with examples only in v0. FP-converge refines enumeration.
- Verdict = FAIL if any-of: orphan_label_count > 0, orphan_ref_count > 0, non_pinpoint_count > 0.
- Cross-ref-parity-depth-2 is union of three detectors: orphan-label + orphan-ref + non-pinpoint.
Examples
Example 1: Hyperboloid.tex Test
ROOT=$HOME/gt/.gc/worktrees/hecke/polecats/gc.run-operator/worktrees/he-d4l
check-labels-and-refs $ROOT/latex/notes/hyperboloid.tex <city-root>/tmp-for-review/he-ja26/
# Produces: <city-root>/tmp-for-review/he-ja26/check-labels-and-refs-report.json
Expected checks:
- Scans hyperboloid.tex + \input closure
- Reports orphan labels (labels without refs)
- Reports orphan refs (refs to undefined labels)
- Flags non-pinpoint patterns
- Verdict: PASS (no orphans or non-pinpoint issues) or FAIL (issues found)
04 同仓库更多 Skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
verification-before-completion
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
using-superpowers
Use when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions
using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code