Claude-skill-registry literate-programming
CRITICAL: ALWAYS activate this skill BEFORE making ANY changes to .nw files. Use proactively when: (1) creating, editing, reviewing, or improving any .nw file, (2) planning to add/modify functionality in files with .nw extension, (3) user asks about literate quality, (4) user mentions noweb, literate programming, tangling, or weaving, (5) working in directories containing .nw files, (6) creating new modules/files that will be .nw format. Trigger phrases: 'create module', 'add feature', 'update', 'modify', 'fix' + any .nw file. Never edit .nw files directly without first activating this skill to ensure literate programming principles are applied. (project, gitignored)
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/literate-programming" ~/.claude/skills/majiayu000-claude-skill-registry-literate-programming && rm -rf "$T"
skills/data/literate-programming/SKILL.mdLiterate Programming Skill
CRITICAL: This skill MUST be activated BEFORE making any changes to .nw files!
You are an expert in literate programming using the noweb system.
Reference Files
This skill includes detailed references in
references/:
| File | Content | Search patterns |
|---|---|---|
| Tangling, weaving, flags, troubleshooting | , , , |
| Test organization, placement, dependency testing | , , |
| Version control, .gitignore, pre-commit | , , |
| Large project organization, makefiles | , , , |
| Standard LaTeX preamble for documentation | , |
When to Use This Skill
Correct Workflow
- User asks to modify a .nw file
- YOU ACTIVATE THIS SKILL IMMEDIATELY
- You plan the changes with literate programming principles
- You make the changes following the principles
- You regenerate code with make/notangle
Anti-pattern (NEVER do this)
- User asks to modify a .nw file
- You directly edit the .nw file ← WRONG
- Later review finds literate quality problems
- You have to redo everything
Remember
- .nw files are NOT regular source code files
- They combine documentation and code for human readers
- Literate quality is AS IMPORTANT as code correctness
- Bad literate quality = failed task, even if code works
Planning Changes
When making changes to a .nw file:
- Read the existing file to understand structure and narrative
- Plan with literate programming in mind:
- What is the "why" behind this change?
- How does this fit into the existing narrative?
- What new chunks are needed? What are their meaningful names?
- Where in the pedagogical order should this be explained?
- Design documentation BEFORE writing code:
- Write prose explaining the problem and solution
- Use subsections to structure complex explanations
- Decompose code into well-named chunks:
- Each chunk = one coherent concept
- Names describe purpose, not syntax (like pseudocode)
- Write the code chunks
- Regenerate and test
Key principle: If you find yourself writing code comments to explain logic, that explanation belongs in the documentation chunks instead.
Reviewing Literate Programs
When reviewing, evaluate:
- Narrative flow: Coherent story? Pedagogical order?
- Variation theory: Contrasts used? "Whole, parts, whole" structure?
- Chunk quality: Meaningful names? Focused on single concepts?
- Explanation quality: Explains "why" not just "what"?
- Test organization: Tests after implementation, not before?
- Proper noweb syntax:
notation? Valid chunk references?[[code]]
Core Philosophy
Literate programming (Knuth) has two goals:
- Explain to human beings what we want a computer to do
- Present concepts in order best for human understanding (psychological order, not compiler order)
Variation Theory
Apply
variation-theory skill when structuring explanations:
- Contrast: Show what something IS vs what it is NOT
- Separation: Start with whole (module outline), then parts (chunks)
- Generalization: Show pattern across different contexts
- Fusion: Integrate parts back into coherent whole
CRITICAL: Show concrete examples FIRST, then state general principles. Readers cannot discern a pattern without first experiencing variation.
Noweb File Format
Documentation Chunks
- Begin with
followed by space or newline@ - Contain explanatory text (LaTeX, Markdown, etc.)
- Copied verbatim by noweave
Code Chunks
- Begin with
on a line by itself (column 1)<<chunk name>>= - End when another chunk begins or at end of file
- Reference other chunks using
<<chunk name>> - Multiple chunks with same name are concatenated
Syntax Rules
- Quote code in documentation using
(escapes LaTeX special chars)[[code]] - Escape:
for literal@<<
,<<
in column 1 for literal@@@
Writing Guidelines
- Start with the human story - problem, approach, design decisions
- Introduce concepts in pedagogical order - not compiler order
- Use meaningful chunk names - 2-5 word summary of purpose (like pseudocode)
- Decompose by concept, not syntax
- Explain the "why" - don't just describe what the code does
- Keep chunks focused - single, coherent idea each
- Use bucket chunks - accumulate
and<<functions>>=
throughout<<constants>>= - Define constants for magic numbers - never hardcode values
- Co-locate dependencies with features - feature's imports in feature's section
- Keep lines under 80 characters - both prose and code
LaTeX Documentation Quality
Apply
latex-writing skill. Most common anti-patterns in .nw files:
Lists with bold labels: Use
\begin{description} with \item[Label], NOT \begin{itemize} with \item \textbf{Label}:
Code with manual escaping: Use
[[code]], NOT \texttt{...\_...}
Manual quotes: Use
\enquote{...}, NOT "..." or ...'' ``
Manual cross-references: Use
\cref{...}, NOT Section~\ref{...}
Progressive Disclosure Pattern
When introducing high-level structure, use abstract placeholder chunks that defer specifics:
def cli_show(user_regex, <<options for filtering>>): <<implementation>> @ [... later, explain each option ...] \paragraph{The --all option} <<options for filtering>>= all: Annotated[bool, all_opt] = False, @
Benefits: readable high-level structure, pedagogical ordering, maintainability.
Chunk Concatenation Patterns
Use multiple definitions when building up a parameter list pedagogically:
\subsection{Adding the diff flag} <<args for diff>>= diff=args.diff, @ [... later ...] \subsection{Fine-tuning thresholds} <<args for diff>>= threshold=args.threshold @
Use separate chunks when contexts differ (different scopes):
<<args from command line>>= # Has args object diff=args.diff, @ <<params for recursion>>= # No args, only parameters diff=diff, @
Test Organization
CRITICAL: Tests appear AFTER implementation, not before.
See
references/testing-patterns.md for detailed patterns.
Key points:
- Distribute tests throughout file, near implementations
- Use single
chunk, concatenated<<test functions>> - Use
in test filefrom module import * - Frame tests pedagogically: "Let's verify this works..."
Multi-Directory Projects
For large projects (5+ .nw files), see
references/multi-directory-projects.md.
Key structure:
project/ ├── src/ # .nw files → .py + .tex ├── doc/ # Master document, preamble.tex ├── tests/ # Extracted test files └── makefiles/ # Shared build rules (noweb.mk, subdir.mk)
LaTeX-Safe Chunk Names
Use
[[...]] notation for Python chunks with underscores:
<<[[module_name.py]]>>= def my_function(): pass @
Extract with:
notangle -R"[[module_name.py]]" file.nw > module_name.py
Best Practices Summary
- Write documentation first - then add code
- Keep lines under 80 characters
- Check for unused chunks - run
to find typosnoroots - Keep tangled code in .gitignore - .nw is source of truth
- NEVER commit generated files - .py and .tex from .nw are build artifacts
- Test your tangles - ensure extracted code runs
- Keep docstrings independent from LaTeX - no
in docstrings\cref - Include table of contents - add
in documentation\tableofcontents
Git Workflow
See
references/git-workflow.md for details.
Core rules:
- Only commit .nw files to git
- Add generated files to .gitignore immediately
- Regenerate code with
after checkout/pullmake - Never commit generated .py or .tex files
Noweb Commands Quick Reference
See
references/noweb-commands.md for details.
# Tangling notangle -R"[[module.py]]" file.nw > module.py noroots file.nw # List root chunks # Weaving noweave -n -delay -x -t2 file.nw > file.tex # For inclusion noweave -latex -x file.nw > file.tex # Standalone
When Literate Programming Is Valuable
- Complex algorithms requiring detailed explanation
- Educational code where understanding is paramount
- Code maintained by others
- Programs where design decisions need documentation
- Projects combining multiple languages/tools