AI Textbook Automation Workflow for Developers: Claude Code + Pandoc
You used ChatGPT to generate a complete course syllabus, excitedly pasted the content into Google Docs, spent 45 minutes adjusting heading formats, fixing the table of contents, and unifying font sizes—only to spot a major error in Chapter 3 that requires a rewrite. You regenerate, copy-paste again, and adjust formatting again. This loop repeats every time you produce a new textbook.
This is the hidden cost of no-code tools: formatting time often exceeds content generation time. Even worse, without version control, you don't know what changed last time; without batch automation, ten textbooks mean manual operations ten times.
If you have basic knowledge of Python and command line, this article shows you how to build a "set once, use forever" automation pipeline: Claude Code Generation → Markdown Management → Pandoc Conversion → EPUB/PDF Output.
🚀 If you don't want to code: If you just want to quickly try AI textbook generation without version control or batch automation, check out the No-Code AI Textbook Generator Guide. That path only takes 1-2 hours with zero coding, and you can always come back here to upgrade to the developer workflow.
TL;DR
📌 Key Takeaways
- Problem: No-code tools lack version control, automation, and batch generation support.
- Solution: Claude Code + Markdown + Pandoc + Python automation pipeline.
- Core Advantages: Full format control, Git version management, reusable scripts.
- Time Investment: Initial setup approx. 2-4 hours, then 1-2 hours per new textbook.
- Cost: Claude Pro ($20/mo, optional); Pandoc, Python, Git are free.
- Who is this for: Developers familiar with CLI, technical writers, power users needing batch generation or customization.
- Real Case: nihongo-claude — An N3 Japanese learning material planned and generated by Claude Code based on requirements.
When to Choose the Developer Workflow?
Before starting, confirm if this path suits you.
Choose the developer workflow if you:
- ✅ Need version control — want to track changes or revert to previous versions.
- ✅ Plan to generate multiple textbooks — want reusable scripts.
- ✅ Want full format control — custom CSS, EPUB metadata, cover images.
- ✅ Prefer CLI tools and are familiar with basic Python or Shell Script.
- ✅ Need automated deployment — e.g., auto-regenerate EPUB on every Git commit.
Do not choose this path if:
- ❌ Just want to quickly generate one textbook (one-off project).
- ❌ Don't want to touch the terminal or write any scripts.
- ❌ Have limited time and want a finished product today.
⚠️ Cost Warning: The developer path has higher upfront investment. If you only need a textbook occasionally, the ROI of the No-Code Solution is usually higher. This article assumes you are familiar with Git, Markdown, and CLI operations.
System Architecture: From Requirements to eBook
The entire pipeline has only three core steps:
Learning Requirements
↓
Claude Code (Plan Course Structure + Generate Markdown Content)
↓
Markdown Files (Git Version Control)
↓
Pandoc (Conversion)
├──→ EPUB (Primary format, for all modern ebook readers)
├──→ PDF (Print / Tablet reading)
└──→ MOBI (Optional, only for pre-2021 Kindles)
Important Notes on Tool Selection:
- Pandoc is the workhorse, generating high-quality EPUB directly; sufficient for most cases.
- Calibre is optional, only needed if you require MOBI format (old Kindles); new Kindles (2022+) accept EPUB (Amazon auto-converts to their proprietary format), so you can skip Calibre.
- AI Tool Flexibility: This article uses Claude Code as an example, but the workflow applies equally to ChatGPT API, Gemini API, or other LLMs — use what you're comfortable with.
Technical Requirements
| Tool | Necessity | Installation |
|---|---|---|
| Git | ✅ Required | System built-in or brew install git |
| Python 3.8+ | ✅ Required | python.org or brew install python |
| Pandoc | ✅ Required | brew install pandoc / apt install pandoc |
| Claude Code CLI | ✅ Recommended | `curl -fsSL https://claude.ai/install.sh |
| Calibre | ❌ Optional | brew install calibre (Only if MOBI is needed) |
Step 1: generating Structured Content with Claude Code
Why Claude Code instead of Web UI?
Claude.ai web UI is great for interactive chat, but has limitations for textbook generation:
- Inconvenient Output: Requires manual copy-pasting to text editor.
- No File Access: Web UI cannot control local filesystem.
- Limited Context: Maintaining consistency across chapters is harder.
Claude Code (Local CLI) solves these problems:
- Runs directly in your project directory, generated Markdown files are saved locally automatically.
- Can read your
outline.mdand reference materials, maintaining consistent style. - Integrates naturally with Git workflow.
Setup Project Directory
# Create project
mkdir my-textbook && cd my-textbook
git init
# Create basic directory structure
mkdir -p chapters assets output scripts
# Initialize Python environment (Recommended)
python3 -m venv venv
source venv/bin/activate
pip install ebooklib markdown2 weasyprint
Create Course Outline (Let AI Plan Structure)
This is the core difference of the developer path: You don't need prepared materials. Just describe your learning needs and let Claude Code plan the entire course structure.
Create REQUIREMENTS.md:
# Learning Requirements
## What I Want to Learn
Data Analysis Introduction (Product Manager Perspective)
## My Background
- Current Role: Software Engineer, transitioned to PM 6 months ago
- Known: Python basics, basic SQL queries
- Weakness: Statistics concepts, A/B test design, Data visualization
## Learning Goals
After completion, be able to:
1. Independently design A/B tests and interpret results
2. Analyze user behavior funnels using GA4
3. Create clear data visualizations for non-tech audiences
## Course Specs
- Chapters: 8-10
- Length per chapter: Approx. 1,500-2,000 words
- Language: English
- Example Context: SaaS products, E-commerce platforms
Let Claude Code Plan the Course Structure
Start Claude Code in the project directory:
claude
After Claude Code starts, enter the following command:
Please read REQUIREMENTS.md, then:
1. Design an 8-10 chapter course structure, save to outline.md
2. Each chapter includes: learning objectives, core concepts (3-5), real case topics, self-check quiz (3 questions)
3. Ensure difficulty progresses logically, suitable for learners with Python/SQL basics but weak statistics
Claude Code will automatically read requirements, plan the structure, and write outline.md to your directory.
Generate Content Chapter by Chapter
After verifying the structure, let Claude Code generate each chapter:
Please generate the complete content for Chapter 1 based on the structure in outline.md.
Formatting requirements:
- Use Markdown format
- H2 for chapter main title, H3 for sections
- Attach a real SaaS product case for each core concept
- End with 3 self-check questions (with answers)
Save result to chapters/chapter-01.md
Repeat this step to complete all chapters. Git commit after finishing each chapter:
git add chapters/chapter-01.md
git commit -m "feat: add chapter 1 - data-driven decision framework"
💡 Quality Control Tip: After generating each chapter, ask Claude Code to do a "Reverse Review" — ask it to point out potential errors, unclear points, or oversimplifications in the chapter. This is more efficient than manual proofreading. If you are interested in more applications of Claude Code in software development, check out the Claude Code PRD Workflow.
Step 2: Pandoc Conversion — From Markdown to EPUB
Pandoc is the core conversion tool of this pipeline. It's open-source, free, supports dozens of formats, CLI-friendly, and perfect for automation.
Simplest Conversion Command
Check if Pandoc is installed correctly:
pandoc --version
Basic conversion:
pandoc chapters/chapter-01.md -o output/textbook.epub \
--toc \
--metadata title="Data Analysis 101: PM Guide"
In seconds, you have an EPUB readable on any ebook reader.
Complete Production-Grade Conversion Command
In a real project, you need more parameters:
pandoc \
chapters/chapter-*.md \
-o output/my-textbook.epub \
--toc \
--toc-depth=2 \
--epub-cover-image=assets/cover.jpg \
--css=assets/styles.css \
--metadata title="Data Analysis 101: PM Guide" \
--metadata author="Your Name" \
--metadata lang=en \
--metadata date="2026-02-17"
Parameter Explanation:
| Parameter | Usage |
|---|---|
--toc | Generate Table of Contents |
--toc-depth=2 | TOC Depth (H1 and H2) |
--epub-cover-image | Cover Image (1600×2560 px optimal) |
--css | Custom layout styles |
--metadata lang=en | Set language (affects font rendering) |
Custom CSS Layout
Create assets/styles.css to give your textbook a professional look:
/* Basic Layout */
body {
font-family: "Noto Sans", "Source Sans Pro", sans-serif;
line-height: 1.8;
color: #333;
max-width: 680px;
margin: 0 auto;
}
/* Chapter Titles */
h1 {
color: #2c3e50;
border-bottom: 3px solid #3498db;
padding-bottom: 10px;
margin-top: 2em;
}
h2 {
color: #34495e;
margin-top: 1.8em;
}
/* Code Blocks */
pre {
background: #f8f9fa;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
font-size: 0.9em;
}
code {
background: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-size: 0.9em;
}
/* Blockquotes */
blockquote {
border-left: 4px solid #3498db;
margin-left: 0;
padding: 10px 20px;
background: #ecf9ff;
border-radius: 0 6px 6px 0;
}
/* Tables */
table {
width: 100%;
border-collapse: collapse;
margin: 1.5em 0;
}
th, td {
border: 1px solid #ddd;
padding: 10px 14px;
text-align: left;
}
th {
background: #f2f4f7;
font-weight: 600;
}
Batch Automation Script
Create scripts/convert.sh for one-click generation of all formats:
#!/bin/bash
# Configuration
TITLE="Data Analysis 101: PM Guide"
AUTHOR="Your Name"
OUTPUT_DIR="output"
COVER="assets/cover.jpg"
CSS="assets/styles.css"
# Ensure output dir exists
mkdir -p "$OUTPUT_DIR"
echo "🔄 Starting conversion..."
# Convert to EPUB (Primary format)
pandoc chapters/chapter-*.md \
-o "${OUTPUT_DIR}/textbook.epub" \
--toc --toc-depth=2 \
--epub-cover-image="$COVER" \
--css="$CSS" \
--metadata title="$TITLE" \
--metadata author="$AUTHOR" \
--metadata lang=en
echo "✅ EPUB generated: ${OUTPUT_DIR}/textbook.epub"
# Convert to PDF (via HTML intermediate)
pandoc chapters/chapter-*.md \
-o "${OUTPUT_DIR}/textbook.html" \
--standalone \
--css="$CSS" \
--metadata title="$TITLE"
python3 -m weasyprint "${OUTPUT_DIR}/textbook.html" "${OUTPUT_DIR}/textbook.pdf"
rm "${OUTPUT_DIR}/textbook.html"
echo "✅ PDF generated: ${OUTPUT_DIR}/textbook.pdf"
echo ""
echo "📂 Output Directory:"
ls -lh "${OUTPUT_DIR}/"
Execute:
chmod +x scripts/convert.sh
./scripts/convert.sh
Output Structure:
output/
├── textbook.epub ← E-reader (Primary)
└── textbook.pdf ← Print / Tablet
Step 3 (Optional): Calibre — Only for Kindle MOBI
⚠️ Note: Most users DO NOT need this step.
When do you need Calibre?
| Device | Supported Formats | Need Calibre? |
|---|---|---|
| Kindle Paperwhite (Post-2022) | ✅ Accepts EPUB (Auto-convert) | ❌ No |
| Kobo, Apple Books, Google Play | ✅ Supports EPUB | ❌ No |
| Browser Reading (Tablet) | ✅ Supports EPUB/PDF | ❌ No |
| Old Kindle (Pre-2021) | ❌ Only MOBI | ✅ Yes |
Only install Calibre and run the following if your readers use old Kindles:
# Install Calibre
brew install calibre # macOS
sudo apt install calibre # Linux
# EPUB → MOBI Conversion
ebook-convert output/textbook.epub output/textbook.mobi \
--output-profile kindle
Conclusion: Unless you have specific needs, simply generating EPUB with Pandoc is sufficient. No need to introduce extra tool dependencies.
Case Study: nihongo-claude — Requirements-Driven Material Generation
nihongo-claude is an open-source project and a real implementation of this workflow. It best illustrates the core advantage of the "developer path."
Key Features: From Scratch, Requirements-Driven
Biggest difference from general AI textbook tools: This project started with zero prepared materials — no PDF, no notes, no syllabus.
The process went like this:
- Define Requirements: "I want to learn N3 Japanese, currently at N4 level, aim to reach N3 in 3 months."
- Claude Code Plans Structure: AI automatically designed a complete course structure with 4 phases and 30 lessons.
- Generate Content: Each lesson includes vocabulary, grammar, real conversation scenarios, and quizzes.
- Automated Output: Python script + Pandoc one-click EPUB/PDF generation.
This verifies a key hypothesis: You don't need to be a Japanese teacher to generate reasonably structured Japanese materials — providing you can clearly define learning needs and quality standards.
Project Structure
nihongo-claude/
├── REQUIREMENTS.md # Requirements definition
├── lessons/
│ ├── phase-1/ # Phase 1: Basic Grammar (L1-8)
│ │ ├── lesson-01.md
│ │ ├── lesson-02.md
│ │ └── ...
│ ├── phase-2/ # Phase 2: Advanced Grammar (L9-16)
│ ├── phase-3/ # Phase 3: Context Application (L17-24)
│ └── phase-4/ # Phase 4: Mock Exams (L25-30)
├── scripts/
│ ├── convert_to_epub.py # Python EPUB script
│ ├── generate_pdf.py # PDF generation script
│ └── quick-convert.sh # One-click script
├── assets/
│ ├── styles.css # Custom CSS
│ └── cover.jpg # Cover image
└── output/
├── nihongo-n3.epub
└── nihongo-n3.pdf
Core Script Analysis
1. convert_to_epub.py — Python EPUB Generation
import glob
from ebooklib import epub
import markdown2
def build_epub():
book = epub.EpubBook()
book.set_identifier('nihongo-n3-v1')
book.set_title('Japanese N3 Complete Guide')
book.set_language('ja')
book.add_author('Your Name')
chapters = []
lesson_files = sorted(glob.glob('lessons/**/*.md', recursive=True))
for i, lesson_path in enumerate(lesson_files, start=1):
with open(lesson_path, 'r', encoding='utf-8') as f:
md_content = f.read()
# Markdown → HTML
html_content = markdown2.markdown(md_content, extras=['tables', 'fenced-code-blocks'])
# Create EPUB Chapter
chapter = epub.EpubHtml(
title=f'Lesson {i:02d}',
file_name=f'lesson_{i:02d}.xhtml',
lang='ja'
)
chapter.content = f'<html><body>{html_content}</body></html>'
book.add_item(chapter)
chapters.append(chapter)
# Set TOC and Nav
book.toc = chapters
book.spine = ['nav'] + chapters
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
epub.write_epub('output/nihongo-n3.epub', book)
print('✅ EPUB generated: output/nihongo-n3.epub')
if __name__ == '__main__':
build_epub()
2. quick-convert.sh — Interactive One-Click Script
#!/bin/bash
echo "Select output format:"
echo "1) EPUB (Recommended)"
echo "2) PDF"
echo "3) All"
read -p "Enter option (1-3): " choice
case $choice in
1)
python3 scripts/convert_to_epub.py
;;
2)
python3 scripts/generate_pdf.py
;;
3)
python3 scripts/convert_to_epub.py
python3 scripts/generate_pdf.py
echo "✅ All formats generated"
;;
*)
echo "❌ Invalid option"
exit 1
;;
esac
Three Lessons from nihongo-claude
1. Requirements Definition Determines Content Quality
It's not about the AI tool, but how you describe requirements. "I want to learn Japanese" vs "I am N4 level, aim to pass N3 in 3 months, 1 hour daily study, need emphasis on listening and reading" — these generate disparate quality materials.
2. Modular Design Makes Maintenance Easy
Saving each lesson as an independent Markdown file means:
- Finding an error requires modifying only one file, not affecting others.
- Can A/B test different teaching methods (using Git branches).
- Adding new courses just means adding Markdown files; the script includes them automatically.
3. This Pipeline Applies to Any Topic
You can Fork this repo, modify REQUIREMENTS.md with your own learning needs, and let Claude Code plan a new course structure — whether it's machine learning, financial analysis, or product management, the pipeline is identical.
Advanced: GitHub Actions for Full Automation
If your textbook needs continuous updates (e.g., tracking tech changes), set up a CI/CD pipeline: GitHub automatically regenerates EPUB/PDF on every Markdown update commit.
Create .github/workflows/build-ebook.yml:
name: Build eBook
on:
push:
branches: [main]
paths:
- 'chapters/**'
- 'assets/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Pandoc
run: |
sudo apt-get update
sudo apt-get install -y pandoc
- name: Install Python dependencies
run: pip install ebooklib markdown2 weasyprint
- name: Generate EPUB
run: python scripts/convert_to_epub.py
- name: Generate PDF
run: |
pandoc chapters/chapter-*.md \
-o output/textbook.html \
--standalone --css=assets/styles.css \
--metadata title="My Textbook"
python3 -m weasyprint output/textbook.html output/textbook.pdf
rm output/textbook.html
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ebooks
path: output/
- name: Create Release (on tag)
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: output/*
Usage:
- Modify Markdown content in
chapters/. git commit && git push.- GitHub Actions runs automatically, generating new EPUB/PDF versions.
- For formal release, tag it:
git tag v1.1.0 && git push --tags. - GitHub automatically creates a Release with download links.
💡 Pro Tip: Add a Markdown linter (e.g.,
markdownlint) in GitHub Actions to ensure every commit meets formatting standards, preventing conversion errors.
Risks & Limitations
Technical Complexity
- Learning Curve: Requires familiarity with CLI, Git, and basic Python. Setup might take half a day for beginners.
- Debugging: EPUB format issues (CSS incompatibility, image paths) can be hard to trace.
- Pandoc Versions: Slight parameter differences between versions; upgrades need testing.
Tool Dependencies
- Python Package Conflicts:
ebooklib,weasyprintmight conflict; usevenv. - EPUB Compatibility: CSS support varies by reader; test on multiple devices.
- weasyprint Fonts: Chinese PDFs need font installation (e.g., Noto Sans CJK) to avoid tofu boxes (missing characters).
Cost Considerations
- Claude Pro Subscription: For mass generation of high-quality content, Claude Pro ($20/mo) offers higher limits than free tier; ChatGPT Plus or Gemini Advanced are alternatives.
- Dev Time: Initial setup takes 2-4 hours more than no-code, but it's a one-time investment.
- GitHub Actions Limits: 2,000 free minutes/month (generating a book takes <10 mins).
When NOT to Use This Path
⚠️ Honestly: If you just want to generate one textbook, the upfront effort here is likely not worth it. The No-Code Solution can finish the first book today with zero setup. Come back here when you confirm the need for mass generation or version control.
Conclusion: Build Your Textbook Factory
If you've reached here, you now possess:
- Claude Code Gen Workflow: Requirements → Plan → Generate, AI-assisted.
- Pandoc Conversion Pipeline: Markdown → EPUB/PDF, one command.
- Version Control Integration: Git tracking, revertible, collaborative.
- Optional CI/CD: Auto-generate on commit.
The real value isn't "generating a book," but reusability: The script and workflow you build work for the next book, just changing requirements and metadata.
Suggested Start:
- Fork nihongo-claude → Study structure.
- Modify
REQUIREMENTS.mdfor your learning needs. - Start Claude Code to plan the course.
- Run
./scripts/quick-convert.shto generate your first EPUB. - Open in a reader and feel the accomplishment of "self-generated."
💡 Final Reminder: Tools are means, content quality is the end. Regardless of the AI tool, manual review, fact-checking, and personalization are essential. AI is a powerful assistant, but judging what knowledge is valuable relies on you.
If you haven't tried AI textbook generation, start with the No-Code Version — finish your first book today. Come back to build this automation system once familiar. The two paths complement, not compete.
FAQ
What is the main difference between this workflow and the no-code approach?
The no-code approach is ideal for quickly generating a single textbook without any technical background. The developer workflow excels at version control (Git tracks every change), batch automation (scripts are reusable across multiple books), and full format control (custom CSS, EPUB metadata). If you only need a book occasionally, the no-code approach has better ROI; if you plan to continuously generate or maintain multiple textbooks, the developer workflow saves significant time in the long run.
How long does the initial setup take, and how much time per new book after that?
Initial setup (installing tools, creating directory structure, configuring scripts) takes approximately 2-4 hours, depending on your familiarity with command-line tools. After that, each new textbook only requires modifying REQUIREMENTS.md with your learning needs, letting Claude Code plan and generate content, and running the conversion script — roughly 1-2 hours total.
Do I have to use Claude Code? Can I use other AI tools instead?
Absolutely. The core of this pipeline is Markdown files plus Pandoc conversion — the AI tool is interchangeable. ChatGPT, Gemini, or any LLM that outputs Markdown can plug into this workflow. This article uses Claude Code because the nihongo-claude case study used it, and Claude Code CLI can directly read and write files in your local directory, integrating conveniently with Git workflows.
Should I use Pandoc or Python ebooklib for EPUB generation?
Beginners should start with Pandoc — one command handles the conversion, and while CSS customization is limited, it is usually sufficient. If you need finer control (e.g., custom chapter ordering, metadata, navigation structure), switch to Python ebooklib. Start with Pandoc for quick prototyping, then move to ebooklib when you confirm the need for advanced control.
Will the generated EPUB display consistently across different e-readers?
EPUB is a standard format, but CSS support varies by reader. Kindle has limited CSS support — avoid flexbox or grid layouts. Apple Books and Kobo offer more complete CSS support. Use conservative CSS settings (fonts, colors, basic spacing) and test on multiple devices to confirm rendering.



