McGuffey's First Eclectic Reader (ABC Books rebuild guide) 10OCT2026

Book 2 of ABC Books: all 63 lessons of the 1879 First Reader, read in Eloquence, with tracing and blackboard copy work

Posted on 10th Oct 2026

The second book in ABC Books is McGuffey’s First Eclectic Reader, Revised Edition (1879), all 63 lessons. It’s the blue book on the shelf at https://games.503mail.com/abcbooks/, next to the Primer. Every lesson plays the same way as the Primer’s: new words, listen, read aloud, trace in print and cursive, and the blackboard. This post covers what’s special about this book and how to add it. The app itself is rebuilt in the Primer post. Every block has a Copy button.

The book

  • McGuffey’s First Eclectic Reader, Revised Edition, copyright 1879, 1896, 1907 and 1920, from Project Gutenberg #14640 (public domain).
  • 63 lessons. It starts where the Primer ends (“The dog. The dog ran.”) and grows into real little stories: Rab the dog, Kitty’s pet bird, the white kitten, Willie’s rabbits, Rose and Willie finding a bird’s nest, Frank’s willow whistle, and Chippy and the old hen at the brook. The last lesson says goodbye to the book and points to the Second Reader.
  • Every few lessons is a review that lists the words to practise again.
  • Many lessons end with slate work: a script (cursive) exercise. In the app, those become the cursive tracing pages. When a lesson is only a poem in script (like “The White Kitten” or “When the stars at set of sun”), the poem becomes the reading too.
  • About 2,650 different things to say per speed (lines, words, letters, instructions), recorded in ETI-Eloquence like the Primer: about 30 MB at “normal” speed and 25 MB at “faster”.

What the converter had to clean up

The Gutenberg text keeps the book’s printing marks, which the Primer mostly didn’t have. make-book.ps1 turns them into plain words:

  • Accent marks in the new-word lists: cun'ning, bro'ken, fin'ished become cunning, broken, finished. Real contractions keep their apostrophe: I've, can't, didn't (printed did n't).
  • Syllable breaks: be cause', a go', him self', o bey' become because, ago, himself, obey.
  • Pronunciation notes in brackets are dropped: once(wuns), a'gain (a gen'), whis'tle (whis'l).
  • Phrases in the word list like a black hen the nest aren’t new words, so they’re skipped.
  • “O” at the start of the word list (as in “O Ben!”) is a word, not the letter o.
  • Story titles in capitals (“THE WHITE KITTEN.”) show as a heading above the lesson instead of a line to read.
  • The phonics chart at the end of the book isn’t a lesson, so the converter stops at “PHONIC CHART.”
  • “SLATE WORK.” headings are removed; their script exercises become the cursive pages.

Add this book to ABC Books

You need the app from the Primer post and its C:\ABCBooks folder on the PC (with ETI-Eloquence installed). The app already lists this book on its shelf; it just needs the lesson file and the recordings.

1. The converter

If your C:\ABCBooks\tools\make-book.ps1 is older than this post, replace it. Proxmox host shell, then copy it to the PC the same way as in the Primer post (the scp and arrange-rebuild.ps1 steps):

mkdir -p /root/abcbooks-rebuild
cat > /root/abcbooks-rebuild/make-book.ps1 <<'EOF'
# Builds public/books/<book>.json from a Project Gutenberg text of a McGuffey Reader.
# Usage: powershell -ExecutionPolicy Bypass -File ABCBooks\tools\make-book.ps1 -Book primer1881
#        powershell -ExecutionPolicy Bypass -File ABCBooks\tools\make-book.ps1 -Book first1879
param([ValidateSet('primer1881', 'first1879', 'second1879', 'third1879', 'fourth1879', 'fifth1879', 'sixth1879', 'spell1867', 'grimm1884')] [string]$Book = 'primer1881')
$root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
$books = @{
  # Grimm's Fairy Tales: source/grimm.txt made by tools/split-grimm.ps1 from the Maplewood PDF (Hunt 1884 + Rackham pictures).
  # Only the tales in "pick" go in, in that order; each tale is cut into parts of about 250 words (one lesson each).
  grimm1884  = @{ tales = $true; file = 'grimm.txt'; title = "Grimm's Fairy Tales"; sub = 'Margaret Hunt translation, 1884'; color = '#9b2335'
                  source = "Grimm's Household Tales, translated by Margaret Hunt (1884), pictures by Arthur Rackham (1909), public domain"
                  pick = @('The Elves', 'The Frog-King, or Iron Henry', 'Little Red-Cap', 'The Bremen Town-Musicians', 'Rumpelstiltskin',
                           'Mother Holle', 'Briar-Rose', 'Rapunzel', 'Cinderella', 'Hansel and Grethel',
                           'The Wolf and the Seven Little Kids', 'Little Snow-white', 'The Golden Goose', 'The Shoes That Were Danced to Pieces', 'Thumbling',
                           'Cat and Mouse in Partnership', "Our Lady's Child", 'The Story of the Youth Who Went Forth to Learn What Fear Was', 'Faithful John', 'The Good Bargain',
                           'The Wonderful Musician', 'The Twelve Brothers', 'The Pack of Ragamuffins', 'Little Brother and Little Sister', 'The Three Little Men in the Wood',
                           'The Three Spinners', 'The Three Snake-Leaves', 'The White Snake', 'The Straw, the Coal, and the Bean', 'The Fisherman and His Wife',
                           'The Valiant Little Tailor', 'The Riddle', 'The Mouse, the Bird, and the Sausage', 'The Seven Ravens', 'The Singing Bone',
                           'The Devil With the Three Golden Hairs', 'The Louse and the Flea', 'The Girl Without Hands', 'Clever Hans', 'The Three Languages',
                           'Clever Elsie', 'The Tailor in Heaven', 'The Wishing-Table, the Gold-Ass, and the Cudgel in the Sack', 'The Wedding of Mrs. Fox', 'The Robber Bridegroom',
                           'Herr Korbes', 'The Godfather', 'Frau Trude', 'Godfather Death', 'Thumbling as Journeyman',
                           "Fitcher's Bird", 'The Juniper-Tree', 'Old Sultan', 'The Six Swans', 'Fundevogel (Bird-foundling)',
                           'King Thrushbeard', 'The Knapsack, the Hat, and the Horn', 'Sweetheart Roland', 'The Golden Bird', 'The Dog and the Sparrow',
                           'Frederick and Catherine', 'The Two Brothers', 'The Little Peasant', 'The Queen Bee', 'The Three Feathers',
                           'Allerleirauh', "The Hare's Bride", 'The Twelve Huntsmen', 'The Thief and his Master', 'Jorinda and Joringel',
                           'The Three Sons of Fortune', 'How Six Men Got on in the World', 'The Wolf and the Man', 'The Wolf and the Fox', 'The Fox and His Cousin',
                           'The Fox and the Cat', 'The Pink', 'Clever Grethel', 'The Old Man and His Grandson', 'The Water-Nix',
                           'The Death of the Little Hen', 'Brother Lustig', 'Gambling Hansel', 'Hans in Luck', 'Hans Married',
                           'The Gold-Children', 'The Fox and the Geese', 'The Poor Man and the Rich Man', 'The Singing, Springing Lark', 'The Goose-Girl',
                           'The Young Giant', 'The Gnome', 'The King of the Golden Mountain', 'The Raven', "The Peasant's Wise Daughter",
                           'Old Hildebrand', 'The Three Little Birds', 'The Water of Life', 'Doctor Knowall', 'The Spirit in the Bottle',
                           "The Devil's Sooty Brother", 'Bearskin', 'The Willow-Wren and the Bear', 'Sweet Porridge', 'Wise Folks',
                           'Stories about Snakes', "The Poor Miller's Boy and the Cat", 'The Two Travellers', 'Hans the Hedgehog', 'The Shroud',
                           'The Skilful Huntsman', 'The Flail From Heaven', "The Two Kings' Children", 'The Cunning Little Tailor', 'The Bright Sun Brings It to Light',
                           'The Blue Light', 'The Wilful Child', 'The Three Army-Surgeons', 'The Seven Swabians', 'The Three Apprentices',
                           "The King's Son Who Feared Nothing", 'Donkey Cabbages', 'The Old Woman in the Wood', 'The Three Brothers', 'The Devil and his Grandmother',
                           'Ferdinand the Faithful', 'The Iron Stove', 'The Lazy Spinner', 'The Four Skilful Brothers', 'One-eye, Two-eyes, and Three-eyes',
                           'Fair Katrinelje and Pif-Paf-Poltrie', 'The Fox and the Horse', 'The Six Servants', 'The White Bride and the Black One', 'Iron John',
                           'The Three Black Princesses', 'Knoist and his Three Sons', 'The Maid of Brakel', 'Domestic Servants', 'The Lambkin and the Little Fish',
                           'Simeli Mountain', 'Going A-Travelling', 'The Donkey', 'The Ungrateful Son', 'The Turnip',
                           'The Old Man Made Young Again', "The Lord's Animals and the Devil's", 'The Beam', 'The Old Beggar-Woman', 'The Three Sluggards',
                           'The Twelve Idle Servants', 'The Shepherd Boy', 'The Star-Money', 'The Stolen Farthings', 'Brides On Their Trial',
                           'Odds And Ends', 'The Sparrow And His Four Children', 'The Story of Schlauraffen Land', 'The Ditmarsch Tale of Wonders', 'A Riddling Tale',
                           'Snow-White and Rose-Red', 'The Wise Servant', 'The Glass Coffin', 'Lazy Harry', 'The Griffin',
                           'Strong Hans', 'The Peasant in Heaven', 'Lean Lisa', 'The Hut in the Forest', 'Sharing Joy and Sorrow',
                           'The Willow-Wren', 'The Sole', 'The Bittern and the Hoopoe', 'The Owl', 'The Moon',
                           'The Duration of Life', "Death's Messengers", "Master Pfriem (Master Cobbler's Awl)", 'The Goose-Girl at the Well', "Eve's Various Children",
                           'The Nix of the Mill-Pond', "The Little Folks' Presents", 'The Giant and the Tailor', 'The Nail', 'The Poor Boy in the Grave',
                           'The True Sweethearts', 'The Hare and the Hedgehog', 'The Spindle, The Shuttle, and the Needle', 'The Peasant and the Devil', 'The Crumbs on the Table',
                           'The Sea-Hare', 'The Master-Thief', 'The Drummer', 'The Ear of Corn', 'The Grave-Mound',
                           'Old Rinkrank', 'The Crystal Ball', 'Maid Maleen', 'The Boots of Buffalo-Leather', 'The Golden Key',
                           'St. Joseph in the Forest', 'The Twelve Apostles', 'The Rose', 'Poverty and Humility Lead to Heaven', "God's Food",
                           'The Three Green Twigs', "Our Lady's Little Glass", 'The Aged Mother', 'The Heavenly Wedding', 'The Hazel-Branch',
                           'The Jew Among Thorns')
                  emoji = @{ 'The Elves' = '๐Ÿ‘ž'; 'The Frog-King, or Iron Henry' = '๐Ÿธ'; 'Little Red-Cap' = '๐Ÿบ'; 'The Bremen Town-Musicians' = '๐Ÿ“'
                             'Rumpelstiltskin' = '๐Ÿงต'; 'Mother Holle' = 'โ„๏ธ'; 'Briar-Rose' = '๐ŸŒน'; 'Rapunzel' = '๐Ÿ—ผ'; 'Cinderella' = '๐Ÿ‘ '; 'Hansel and Grethel' = '๐Ÿฌ'
                             'The Wolf and the Seven Little Kids' = '๐Ÿ'; 'Little Snow-white' = '๐ŸŽ'; 'The Golden Goose' = '๐Ÿฆข'; 'The Shoes That Were Danced to Pieces' = '๐Ÿ‘‘'; 'Thumbling' = '๐Ÿ‘'
                             'Cat and Mouse in Partnership' = '๐Ÿฑ'; "Our Lady's Child" = '๐Ÿ”‘'; 'The Story of the Youth Who Went Forth to Learn What Fear Was' = '๐Ÿ˜จ'; 'Faithful John' = '๐Ÿค'; 'The Good Bargain' = '๐Ÿ„'
                             'The Wonderful Musician' = '๐ŸŽป'; 'The Twelve Brothers' = '๐ŸŒท'; 'The Pack of Ragamuffins' = '๐Ÿ”'; 'Little Brother and Little Sister' = '๐ŸฆŒ'; 'The Three Little Men in the Wood' = '๐Ÿ“'
                             'The Three Spinners' = '๐Ÿงถ'; 'The Three Snake-Leaves' = '๐Ÿ'; 'The White Snake' = '๐Ÿ’'; 'The Straw, the Coal, and the Bean' = '๐ŸŒฑ'; 'The Fisherman and His Wife' = '๐ŸŸ'
                             'The Valiant Little Tailor' = 'โœ‚๏ธ'; 'The Riddle' = 'โ“'; 'The Mouse, the Bird, and the Sausage' = '๐Ÿญ'; 'The Seven Ravens' = '๐Ÿฆ'; 'The Singing Bone' = '๐Ÿฆด'
                             'The Devil With the Three Golden Hairs' = '๐Ÿ˜ˆ'; 'The Louse and the Flea' = '๐Ÿž'; 'The Girl Without Hands' = '๐Ÿ'; 'Clever Hans' = '๐Ÿงบ'; 'The Three Languages' = '๐Ÿ•'
                             'Clever Elsie' = '๐Ÿบ'; 'The Tailor in Heaven' = 'โ˜๏ธ'; 'The Wishing-Table, the Gold-Ass, and the Cudgel in the Sack' = '๐Ÿฝ๏ธ'; 'The Wedding of Mrs. Fox' = '๐ŸฆŠ'; 'The Robber Bridegroom' = '๐Ÿš๏ธ'
                             'Herr Korbes' = '๐Ÿ'; 'The Godfather' = '๐Ÿท'; 'Frau Trude' = '๐Ÿ”ฅ'; 'Godfather Death' = '๐Ÿ’€'; 'Thumbling as Journeyman' = '๐ŸŽ’'
                             "Fitcher's Bird" = '๐Ÿฅš'; 'The Juniper-Tree' = '๐ŸŒฒ'; 'Old Sultan' = '๐Ÿถ'; 'The Six Swans' = '๐Ÿ•Š๏ธ'; 'Fundevogel (Bird-foundling)' = '๐Ÿฃ'
                             'King Thrushbeard' = '๐Ÿคด'; 'The Knapsack, the Hat, and the Horn' = '๐ŸŽฉ'; 'Sweetheart Roland' = '๐ŸŒธ'; 'The Golden Bird' = '๐Ÿค'; 'The Dog and the Sparrow' = '๐Ÿž'
                             'Frederick and Catherine' = '๐Ÿง€'; 'The Two Brothers' = '๐Ÿ‰'; 'The Little Peasant' = '๐Ÿฎ'; 'The Queen Bee' = '๐Ÿ'; 'The Three Feathers' = '๐Ÿƒ'
                             'Allerleirauh' = '๐Ÿ‘—'; "The Hare's Bride" = '๐Ÿ‡'; 'The Twelve Huntsmen' = '๐Ÿน'; 'The Thief and his Master' = '๐ŸŽ“'; 'Jorinda and Joringel' = '๐ŸŒบ'
                             'The Three Sons of Fortune' = '๐Ÿˆ'; 'How Six Men Got on in the World' = '๐Ÿ’ช'; 'The Wolf and the Man' = '๐Ÿ—ก๏ธ'; 'The Wolf and the Fox' = '๐Ÿฅฉ'; 'The Fox and His Cousin' = '๐Ÿ‘'
                             'The Fox and the Cat' = '๐ŸŒณ'; 'The Pink' = '๐Ÿ’'; 'Clever Grethel' = '๐Ÿ–'; 'The Old Man and His Grandson' = '๐Ÿ‘ด'; 'The Water-Nix' = '๐ŸŒŠ'
                             'The Death of the Little Hen' = '๐Ÿฅ'; 'Brother Lustig' = '๐Ÿ˜‡'; 'Gambling Hansel' = '๐Ÿƒ'; 'Hans in Luck' = '๐Ÿ€'; 'Hans Married' = '๐Ÿ '
                             'The Gold-Children' = '๐ŸŒŸ'; 'The Fox and the Geese' = '๐Ÿฆ†'; 'The Poor Man and the Rich Man' = '๐Ÿ’ฐ'; 'The Singing, Springing Lark' = '๐Ÿฆ'; 'The Goose-Girl' = '๐Ÿด'
                             'The Young Giant' = '๐Ÿ—ฟ'; 'The Gnome' = '๐Ÿ•ณ๏ธ'; 'The King of the Golden Mountain' = 'โ›ฐ๏ธ'; 'The Raven' = '๐Ÿ–ค'; "The Peasant's Wise Daughter" = '๐Ÿ’ก'
                             'Old Hildebrand' = 'โ›ช'; 'The Three Little Birds' = '๐ŸŽถ'; 'The Water of Life' = '๐Ÿ’ง'; 'Doctor Knowall' = '๐Ÿ’Š'; 'The Spirit in the Bottle' = '๐Ÿพ'
                             "The Devil's Sooty Brother" = '๐Ÿ‘น'; 'Bearskin' = '๐Ÿป'; 'The Willow-Wren and the Bear' = 'โš”๏ธ'; 'Sweet Porridge' = '๐Ÿฒ'; 'Wise Folks' = '๐Ÿค”'
                             'Stories about Snakes' = '๐Ÿฅ›'; "The Poor Miller's Boy and the Cat" = '๐Ÿ˜บ'; 'The Two Travellers' = '๐Ÿšถ'; 'Hans the Hedgehog' = '๐Ÿ–'; 'The Shroud' = '๐Ÿ•ฏ๏ธ'
                             'The Skilful Huntsman' = '๐ŸŽฏ'; 'The Flail From Heaven' = '๐ŸŒง๏ธ'; "The Two Kings' Children" = '๐Ÿ’’'; 'The Cunning Little Tailor' = '๐Ÿ‘”'; 'The Bright Sun Brings It to Light' = 'โ˜€๏ธ'
                             'The Blue Light' = '๐Ÿ’™'; 'The Wilful Child' = '๐Ÿ‘ถ'; 'The Three Army-Surgeons' = 'โš•๏ธ'; 'The Seven Swabians' = '๐Ÿ”ฑ'; 'The Three Apprentices' = '๐Ÿ“œ'
                             "The King's Son Who Feared Nothing" = '๐Ÿ›ก๏ธ'; 'Donkey Cabbages' = '๐Ÿ'; 'The Old Woman in the Wood' = '๐Ÿ‚'; 'The Three Brothers' = '๐Ÿ‡'; 'The Devil and his Grandmother' = '๐Ÿ‘ต'
                             'Ferdinand the Faithful' = '๐Ÿ“'; 'The Iron Stove' = 'โ™จ๏ธ'; 'The Lazy Spinner' = '๐Ÿ˜ด'; 'The Four Skilful Brothers' = '๐Ÿ”ญ'; 'One-eye, Two-eyes, and Three-eyes' = '๐Ÿ‘๏ธ'
                             'Fair Katrinelje and Pif-Paf-Poltrie' = '๐Ÿ’ƒ'; 'The Fox and the Horse' = '๐ŸŽ'; 'The Six Servants' = '๐Ÿ‘‚'; 'The White Bride and the Black One' = 'โšช'; 'Iron John' = 'โ›“๏ธ'
                             'The Three Black Princesses' = 'โšซ'; 'Knoist and his Three Sons' = '๐ŸŽญ'; 'The Maid of Brakel' = '๐Ÿ™'; 'Domestic Servants' = '๐Ÿก'; 'The Lambkin and the Little Fish' = '๐Ÿ '
                             'Simeli Mountain' = 'โ›๏ธ'; 'Going A-Travelling' = '๐Ÿ—บ๏ธ'; 'The Donkey' = '๐ŸŽธ'; 'The Ungrateful Son' = '๐Ÿ˜ '; 'The Turnip' = '๐Ÿฅ•'
                             'The Old Man Made Young Again' = 'โณ'; "The Lord's Animals and the Devil's" = '๐Ÿ‚'; 'The Beam' = '๐Ÿ—๏ธ'; 'The Old Beggar-Woman' = 'โ˜‚๏ธ'; 'The Three Sluggards' = '๐Ÿ›Œ'
                             'The Twelve Idle Servants' = '๐Ÿ’ค'; 'The Shepherd Boy' = '๐Ÿ'; 'The Star-Money' = 'โญ'; 'The Stolen Farthings' = '๐Ÿ’ฒ'; 'Brides On Their Trial' = '๐Ÿ‘ฐ'
                             'Odds And Ends' = '๐ŸŽ€'; 'The Sparrow And His Four Children' = '๐Ÿ’'; 'The Story of Schlauraffen Land' = '๐Ÿฐ'; 'The Ditmarsch Tale of Wonders' = '๐Ÿ™ƒ'; 'A Riddling Tale' = '๐ŸŒผ'
                             'Snow-White and Rose-Red' = 'โ›„'; 'The Wise Servant' = '๐Ÿ™‹'; 'The Glass Coffin' = '๐Ÿบ'; 'Lazy Harry' = '๐Ÿ›‹๏ธ'; 'The Griffin' = '๐Ÿฆ…'
                             'Strong Hans' = '๐Ÿ‹๏ธ'; 'The Peasant in Heaven' = '๐ŸŒˆ'; 'Lean Lisa' = '๐Ÿฅ–'; 'The Hut in the Forest' = 'โ›บ'; 'Sharing Joy and Sorrow' = '๐Ÿ˜ข'
                             'The Willow-Wren' = '๐ŸŽ‹'; 'The Sole' = '๐Ÿก'; 'The Bittern and the Hoopoe' = '๐Ÿž๏ธ'; 'The Owl' = '๐Ÿฆ‰'; 'The Moon' = '๐ŸŒ™'
                             'The Duration of Life' = 'โŒ›'; "Death's Messengers" = '๐Ÿ“ฏ'; "Master Pfriem (Master Cobbler's Awl)" = '๐Ÿ”จ'; 'The Goose-Girl at the Well' = '๐Ÿ’Ž'; "Eve's Various Children" = '๐Ÿ‘ช'
                             'The Nix of the Mill-Pond' = '๐ŸŒ€'; "The Little Folks' Presents" = '๐ŸŽ'; 'The Giant and the Tailor' = '๐Ÿ‘ฃ'; 'The Nail' = '๐Ÿ“Œ'; 'The Poor Boy in the Grave' = 'โšฐ๏ธ'
                             'The True Sweethearts' = '๐Ÿ’•'; 'The Hare and the Hedgehog' = '๐Ÿƒ'; 'The Spindle, The Shuttle, and the Needle' = '๐Ÿ“'; 'The Peasant and the Devil' = '๐ŸŒฝ'; 'The Crumbs on the Table' = '๐Ÿช'
                             'The Sea-Hare' = '๐Ÿš'; 'The Master-Thief' = '๐Ÿ•ต๏ธ'; 'The Drummer' = '๐Ÿฅ'; 'The Ear of Corn' = '๐ŸŒพ'; 'The Grave-Mound' = '๐ŸŒš'
                             'Old Rinkrank' = '๐Ÿ”๏ธ'; 'The Crystal Ball' = '๐Ÿ”ฎ'; 'Maid Maleen' = '๐Ÿฐ'; 'The Boots of Buffalo-Leather' = '๐Ÿ‘ข'; 'The Golden Key' = '๐Ÿ—๏ธ'
                             'St. Joseph in the Forest' = 'โœจ'; 'The Twelve Apostles' = 'โœ๏ธ'; 'The Rose' = '๐Ÿต๏ธ'; 'Poverty and Humility Lead to Heaven' = '๐ŸŒ…'; "God's Food" = '๐Ÿฏ'
                             'The Three Green Twigs' = '๐ŸŒฟ'; "Our Lady's Little Glass" = '๐Ÿฅ‚'; 'The Aged Mother' = '๐Ÿ•ฐ๏ธ'; 'The Heavenly Wedding' = '๐Ÿ””'; 'The Hazel-Branch' = '๐ŸŒฐ'
                             'The Jew Among Thorns' = '๐ŸŒต' }
                  # flagged tales stay in the book with their original text, but the app leaves them out until a grown-up includes them
                  flag = @{ 'The Jew Among Thorns' = 'antisemitic: a Jewish man is the villain, beaten and hanged' }
                  short = @{ 'The Frog-King, or Iron Henry' = 'The Frog-King'; 'The Shoes That Were Danced to Pieces' = 'The Dancing Shoes'
                             'The Story of the Youth Who Went Forth to Learn What Fear Was' = 'The Youth Who Learned Fear'
                             'The Wishing-Table, the Gold-Ass, and the Cudgel in the Sack' = 'The Wishing-Table'; 'Fundevogel (Bird-foundling)' = 'Fundevogel'; "Master Pfriem (Master Cobbler's Awl)" = 'Master Pfriem' }
                  after = @('primer1881', 'first1879', 'second1879', 'third1879', 'fourth1879', 'fifth1879', 'sixth1879') }
  # Spell & Read: the 1867 Pictorial Primer, hand-corrected from a scan into source/spell1867.txt (no Gutenberg text exists)
  spell1867  = @{ hand = $true; file = 'spell1867.txt'; title = 'Spell & Read'; sub = 'Pictorial Primer, 1867'; color = '#5b6f3a'
                  source = 'McGuffey''s Pictorial Eclectic Primer, 1867 (archive.org mcguffeyspictori00mcgu, public domain), hand-corrected' }
  primer1881 = @{ gutenberg = 14642; file = 'primer.txt'; title = "McGuffey's Eclectic Primer"; sub = 'Revised Edition, 1881'; color = '#b5562c'
                  end = 'SLATE EXERCISES'; pics = @{ 27 = '๐Ÿž๏ธ'; 46 = 'โœ๏ธ' } }
  first1879  = @{ gutenberg = 14640; file = 'first.txt'; title = "McGuffey's First Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#2c6fb5'
                  end = 'PHONIC CHART.'; pics = @{} }
  second1879 = @{ gutenberg = 14668; file = 'second.txt'; title = "McGuffey's Second Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#3f8f4f'
                  end = '*** END OF THE PROJECT GUTENBERG'; pics = @{} }
  # prose = later Readers: no word lists in Gutenberg's copy (new words are worked out), printed page headers to remove,
  # numbered paragraphs that run on without blank lines, plays ("Rose. ...") and an author line under poems
  third1879  = @{ gutenberg = 14766; file = 'third.txt'; title = "McGuffey's Third Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#7b4fb5'
                  end = '*** END OF THE PROJECT GUTENBERG'; pics = @{}; prose = $true; pageRx = 'ECLECTIC SERIES|THIRD READER'
                  after = @('primer1881', 'first1879', 'second1879') }
  # Fourth Reader: headings carry the title ("I. PERSEVERANCE. (25)"), and each lesson ends with DEFINITIONS (the book's
  # own new words, with meanings), EXERCISES (questions to talk about) and sometimes NOTES
  fourth1879 = @{ gutenberg = 14880; file = 'fourth.txt'; title = "McGuffey's Fourth Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#b5892c'
                  end = '*** END OF THE PROJECT GUTENBERG'; pics = @{}; prose = $true; pageRx = 'ECLECTIC SERIES|FOURTH READER'
                  start = 'I. PERSEVERANCE. (25)'; tocStart = 'SELECTIONS IN PROSE AND POETRY.'; tocEnd = 'LIST OF ILLUSTRATIONS'
                  headRx = '(?m)^([IVXLCl]+)[.:][ \t]+([A-Z][^a-z\n]*?(?:\((?:Concluded|Continued)\.?\))?[^a-z\n]*?)[ \t]*(?:\(\d+\))?[ \t]*$'
                  after = @('primer1881', 'first1879', 'second1879', 'third1879') }
  # Fifth Reader: like the Fourth, but headings have no page number ("II. THE BLUEBELL.") and the first one is scanned as "1."
  fifth1879  = @{ gutenberg = 15040; file = 'fifth.txt'; title = "McGuffey's Fifth Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#2c9bb5'
                  end = '*** END OF THE PROJECT GUTENBERG'; pics = @{}; prose = $true; pageRx = 'ECLECTIC SERIES|FIFTH READER'
                  start = '1. THE GOOD READER.'
                  headRx = '(?m)^(\d+|[IVXLCl]+)[.:][ \t]+(["\u201c]?[A-Z][^a-z\n]*?(?:\((?:Concluded|Continued)\.?\))?[^a-z\n]*?)[ \t]*(?:\(\d+\))?[ \t]*$'
                  tocEnd = 'LIST OF ILLUSTRATIONS'
                  after = @('primer1881', 'first1879', 'second1879', 'third1879', 'fourth1879') }
  # Sixth Reader: headings with page numbers like the Fourth; the lessons start after the chapters on reading aloud
  sixth1879  = @{ gutenberg = 16751; file = 'sixth.txt'; title = "McGuffey's Sixth Eclectic Reader"; sub = 'Revised Edition, 1879'; color = '#8f3f5f'
                  end = '*** END OF THE PROJECT GUTENBERG'; pics = @{}; prose = $true; pageRx = 'ECLECTIC SERIES|SIXTH READER'
                  start = 'I. ANECDOTE OF THE DUKE OF NEWCASTLE.'
                  headRx = '(?m)^(\d+|[IVXLCl]+)[.:][ \t]+(["\u201c]?[A-Z][^a-z\n]*?(?:\((?:Concluded|Continued)\.?\))?[^a-z\n]*?)[ \t]*(?:\(\d+\))?[ \t]*$'
                  tocEnd = 'LIST OF ILLUSTRATIONS'
                  after = @('primer1881', 'first1879', 'second1879', 'third1879', 'fourth1879', 'fifth1879') }
}
$cfg = $books[$Book]
$pics = [ordered]@{ 'rat'='๐Ÿ€'; 'cat'='๐Ÿˆ'; 'kitten'='๐Ÿฑ'; 'dog'='๐Ÿ•'; 'frog'='๐Ÿธ'; 'chick'='๐Ÿค'; 'hen'='๐Ÿ”'; 'fox'='๐ŸฆŠ'; 'duck'='๐Ÿฆ†'; 'owl'='๐Ÿฆ‰'; 'bird'='๐Ÿฆ'; 'cow'='๐Ÿ„';
  'rabbit'='๐Ÿ‡'; 'pig'='๐Ÿ–'; 'lamb'='๐Ÿ‘'; 'kite'='๐Ÿช'; 'sled'='๐Ÿ›ท'; 'top'='๐ŸŽฉ'; 'ball'='โšฝ'; 'squirrel'='๐Ÿฟ๏ธ'; 'bee'='๐Ÿ'; 'boat'='โ›ต';
  'ship'='โ›ต'; 'skat'='โ›ธ๏ธ'; 'horse'='๐ŸŽ'; 'train'='๐Ÿš‚'; 'goat'='๐Ÿ'; 'burning'='๐Ÿ”ฅ'; 'school'='๐Ÿซ'; 'quail'='๐Ÿฆ'; 'baby'='๐Ÿ‘ถ'; 'lighthouse'='๐Ÿ—ผ';
  'sheep'='๐Ÿ‘'; 'snow'='โ˜ƒ๏ธ'; 'fishing'='๐ŸŽฃ'; 'doll'='๐Ÿช†'; 'sawing'='๐Ÿชš'; 'lamp'='๐Ÿช”'; 'seashore'='๐Ÿ–๏ธ'; 'blind'='๐Ÿฆฏ'; 'mill'='๐Ÿž๏ธ';
  'sunset'='๐ŸŒ…'; 'woman'='๐Ÿ‘ฉ'; 'wagon'='๐ŸŽ'; 'acorn'='๐ŸŒฐ'; 'drum'='๐Ÿฅ'; 'lake'='๐ŸŒŠ'; 'writing'='โœ๏ธ'; 'man'='๐Ÿ‘ด'; 'girl'='๐Ÿ‘ง'; 'boy'='๐Ÿ‘ฆ'; 'children'='๐Ÿ‘ง' }
if ($cfg.tales) {
  # Tale book (source/<file> from split-grimm.ps1): "= Title", "@ page", "% n" picture, "! legend", one paragraph per line.
  # Lesson = one part of a tale: L.tale / L.part / L.parts (BlockCraft unlocks a tale's place when its last part is done),
  # L.img = a Rackham picture (pics/grimm/rackham-NN.jpg), shown over the text in Listen.
  $tales = [ordered]@{}; $t = $null
  foreach ($ln in [IO.File]::ReadAllLines("$root\source\$($cfg.file)")) {
    if (-not $ln.Trim() -or $ln.StartsWith('#')) { continue }
    if ($ln -match '^= (.+)$') { $t = @{ pics = @(); paras = New-Object Collections.Generic.List[string] }; $tales[$Matches[1]] = $t; continue }
    if ($ln -match '^@ \d+$' -or $ln -match '^! ') { continue }
    if ($ln -match '^% (\d+)$') { $t.pics += [int]$Matches[1]; continue }
    # a line that starts in lowercase goes on from the one before (a paragraph that wrapped short, or "she said" after a song)
    if ($t.paras.Count -and $ln -cmatch '^[a-z]' -and $t.paras[$t.paras.Count - 1] -cnotmatch '^[A-Z][A-Z ]+$') { $t.paras[$t.paras.Count - 1] += ' ' + $ln.Trim() }
    else { $t.paras.Add($ln.Trim()) }
  }
  function TaleSentences($para) {
    # one line per sentence (a quote that holds several sentences is split too, so a line stays short enough to read
    # aloud); a sentence over 28 words is cut again at "; " so the mic check doesn't time out
    $p = ($para -replace '\s+', ' ').Trim()
    foreach ($s in [regex]::Split($p, '(?<!\b(?:Mr|Mrs|Dr|St))(?<=[.!?][''"]?)\s+(?=[''"]?[A-Z])')) {
      if (-not $s) { continue }
      Chop $s 0
    }
  }
  function Chop($s, $level) {
    # cut a long sentence at ; or :, then at ", and/but/then...", then at any comma; pieces of at least 10 words
    if (($s -split ' ').Count -le 28 -or $level -gt 2) { return $s }
    $rx = @('(?<=[;:]) ', '(?<=,) (?=(?:and|but|or|so|then|when|while|which|who|that|for|as|until|because)\b)', '(?<=,) ')[$level]
    $buf = ''; $outp = @()
    foreach ($piece in [regex]::Split($s, $rx)) {
      $nb = if ($buf) { "$buf $piece" } else { $piece }
      if ($buf -and ($nb -split ' ').Count -gt 28 -and ($buf -split ' ').Count -ge 10) { $outp += $buf; $buf = $piece } else { $buf = $nb }
    }
    if ($buf) { if ($outp.Count -and ($buf -split ' ').Count -lt 6) { $outp[$outp.Count - 1] += " $buf" } else { $outp += $buf } }
    foreach ($x in $outp) { Chop $x ($level + 1) }
  }
  $lessons = @(); $n = 0; $taleKeys = @($tales.Keys)   # taleNo = the tale's number in the whole collection (book order), shown as "Tale 39 of 211"
  foreach ($name in $cfg.pick) {
    $t = $tales[$name]; if (-not $t) { throw "Tale not found in $($cfg.file): $name" }
    # cut into parts: end a part at the first paragraph end after 200 words, or at a sentence end after 330 words;
    # a sub-heading ("SECOND STORY") always starts a new part
    $parts = @(); $cur = @(); $wc = 0
    foreach ($para in $t.paras) {
      if ($para -cmatch '^[A-Z][A-Z ]+$') {
        if ($cur.Count) { if ($wc -lt 80 -and $parts.Count) { $parts[$parts.Count - 1] += $cur } else { $parts += ,$cur } }
        $cur = @(); $wc = 0; continue
      }
      foreach ($s in (TaleSentences $para)) {
        $cur += $s; $wc += ($s -split ' ').Count
        if ($wc -ge 330) { $parts += ,$cur; $cur = @(); $wc = 0 }
      }
      if ($wc -ge 200) { $parts += ,$cur; $cur = @(); $wc = 0 }
    }
    if ($cur.Count) { if ($wc -lt 80 -and $parts.Count) { $parts[$parts.Count - 1] += $cur } else { $parts += ,$cur } }   # a tiny last piece joins the part before
    $short = if ($cfg.short[$name]) { $cfg.short[$name] } else { $name }
    # spread the tale's pictures over its parts (picture 1 on part 1)
    $imgAt = @{}; for ($k = 0; $k -lt $t.pics.Count; $k++) { $imgAt[[int][math]::Floor($k * $parts.Count / $t.pics.Count)] = 'pics/grimm/rackham-{0:D2}.jpg' -f $t.pics[$k] }
    for ($i = 0; $i -lt $parts.Count; $i++) {
      $n++
      $o = [ordered]@{ n = $n; pic = $cfg.emoji[$name]; picText = ''; words = @(); letters = @(); lines = @($parts[$i])
                       title = $(if ($parts.Count -gt 1) { "$short, part $($i + 1) of $($parts.Count)" } else { $short }); tale = $name; taleNo = [array]::IndexOf($taleKeys, $name) + 1; part = $i + 1; parts = $parts.Count }
      if ($imgAt.ContainsKey($i)) { $img = $imgAt[$i] } elseif ($i -eq 0) { $img = $null }
      if ($img) { $o.img = $img }   # a part without its own picture keeps the tale's last one
      if ($cfg.flag -and $cfg.flag[$name]) { $o.flag = $cfg.flag[$name] }   # grown-ups decide on the home screen whether a flagged tale shows
      $lessons += $o
    }
  }
  # New words = words not met in the McGuffey books or earlier parts, up to 10 per part (same rule as the prose Readers)
  $seen = New-Object 'System.Collections.Generic.HashSet[string]' ([StringComparer]::OrdinalIgnoreCase)
  $wordRx = "[A-Za-z]+(?:'[A-Za-z]+)?"
  foreach ($prev in $cfg.after) {
    $pj = Get-Content "$root\public\books\$prev.json" -Raw -Encoding UTF8 | ConvertFrom-Json
    foreach ($PL in $pj.lessons) { foreach ($s in @($PL.lines) + @($PL.words) + @($PL.script)) { foreach ($m in [regex]::Matches("$s", $wordRx)) { [void]$seen.Add($m.Value) } } }
  }
  foreach ($o in $lessons) {
    $text = $o.lines -join ' '; $new = @()
    foreach ($m in [regex]::Matches($text, $wordRx)) {
      $w = $m.Value
      if ($w.Length -lt 2 -or -not $seen.Add($w)) { continue }
      if (-not ($text -cmatch "[a-z]\s+$([regex]::Escape($w))\b") -or ($text -cmatch "\b$([regex]::Escape($w.ToLower()))\b")) { $w = $w.ToLower() }
      $new += $w
    }
    $o.words = @($new | Select-Object -First 10)
  }
  # copy the pictures these lessons use from source/grimm/pics (split-grimm.ps1) into public/pics/grimm
  New-Item -ItemType Directory -Force "$root\public\pics\grimm" | Out-Null
  foreach ($u in ($lessons | Where-Object { $_.img } | ForEach-Object { $_.img } | Sort-Object -Unique)) { Copy-Item "$root\source\grimm\pics\$(Split-Path $u -Leaf)" "$root\public\$u" -Force }
  $out = [ordered]@{ title = $cfg.title; sub = $cfg.sub; color = $cfg.color; source = $cfg.source; taleCount = $taleKeys.Count; lessons = $lessons }
  [IO.File]::WriteAllText("$root\public\books\$Book.json", ($out | ConvertTo-Json -Depth 6), (New-Object Text.UTF8Encoding $false))
  "$($lessons.Count) lessons, $(($lessons | ForEach-Object { $_.lines.Count } | Measure-Object -Sum).Sum) lines"
  $lessons | ForEach-Object { "{0,3} {1} {2,-40} lines={3,2} words={4,3} max={5,2} {6} w[{7}]" -f $_.n, $_.pic, $_.title, $_.lines.Count, (($_.lines -join ' ') -split ' ').Count, (($_.lines | ForEach-Object { ($_ -split ' ').Count }) | Measure-Object -Maximum).Maximum, $_.img, ($_.words -join ' ') }
  return
}
if ($cfg.hand) {
  # Hand-corrected book (source/<file>): "= n" starts a lesson, "words:" is its spelling list, "?" lines are notes, "#" comments
  $lessons = @(); $o = $null
  foreach ($ln in [IO.File]::ReadAllLines("$root\source\$($cfg.file)")) {
    $l = $ln.Trim()
    if (-not $l -or $l.StartsWith('#')) { continue }
    if ($l -match '^=\s*(\d+)') { if ($o) { $lessons += $o }; $o = [ordered]@{ n = [int]$Matches[1]; pic = '๐Ÿ“–'; picText = ''; words = @(); letters = @(); lines = @() }; continue }
    if ($l -match '^words:\s*(.*)$') { $o.words = @($Matches[1] -split '\s+' | Where-Object { $_ }); continue }
    if ($l.StartsWith('?')) { $o.note = $l.TrimStart('?', ' '); continue }
    $o.lines += $l
  }
  if ($o) { $lessons += $o }
  foreach ($o in $lessons) {
    if (-not $o.words.Count) {   # no list printed: spell the lesson's own words
      $w = @(); foreach ($m in [regex]::Matches(($o.lines -join ' '), "[A-Za-z]+(?:'[A-Za-z]+)?")) { $x = if ($m.Value -ceq 'I') { 'I' } else { $m.Value.ToLower() }; if ($w -notcontains $x) { $w += $x } }
      $o.words = @($w | Select-Object -First 12)
    }
    $txt0 = $o.lines -join ' '
    foreach ($key in $pics.Keys) { if ($txt0 -match "(?i)\b$key(?:s|es)?\b") { $o.pic = $pics[$key]; break } }
  }
  $out = [ordered]@{ title = $cfg.title; sub = $cfg.sub; color = $cfg.color; spell = $true; source = $cfg.source; lessons = $lessons }
  [IO.File]::WriteAllText("$root\public\books\$Book.json", ($out | ConvertTo-Json -Depth 6), (New-Object Text.UTF8Encoding $false))
  "$($lessons.Count) lessons"
  $lessons | ForEach-Object { "{0,2} {1} w[{2}] lines={3} {4}" -f $_.n, $_.pic, ($_.words -join ' '), $_.lines.Count, $(if ($_.note) { '? ' + $_.note } else { '' }) }
  return
}
if (-not (Test-Path "$root\source\$($cfg.file)")) {
  New-Item -ItemType Directory -Force "$root\source" | Out-Null
  Invoke-WebRequest "https://www.gutenberg.org/cache/epub/$($cfg.gutenberg)/pg$($cfg.gutenberg).txt" -OutFile "$root\source\$($cfg.file)" -UseBasicParsing
}
$txt = [IO.File]::ReadAllText("$root\source\$($cfg.file)") -replace "`r", ''
$headRx = '(?m)^(?:Lesson 1|LESSON [IVXLC]+\.{0,2}(?:\s*-*\s*REVIEW\.?)?)\s*$'   # Third Reader has one "LESSON XXX.."
if ($cfg.headRx) { $headRx = $cfg.headRx }
$body = if ($cfg.start) { $txt.Substring($txt.LastIndexOf($cfg.start)) } else { $txt.Substring([regex]::Match($txt, $headRx).Index) }
$body = $body.Substring(0, $body.IndexOf($cfg.end))
$body = $body -replace '(?m)^SLATE WORK\.?\s*$', ''
if ($cfg.prose) {
  # printed page headers ("18  ECLECTIC SERIES.") and page numbers, with the blank lines around them, so sentences join across pages
  $body = [regex]::Replace($body, "\n[ \t]*\n?[ \t]*\d*[ \t]*(?:$($cfg.pageRx))\.?[ \t]*\d*[ \t]*\n(?:[ \t]*\n)*", "`n")
  $body = $body -replace '(?m)^[ \t]*\(\d+\)[ \t]*\n', '' -replace '(?m)^[ \t]*\d+[,.]?(?:[ \t]*\d+[,.]?)*[ \t]*\n', ''
  $body = $body -creplace "(?m)^[ \t]*\d*[ \t]*(?:$($cfg.pageRx))[.,]?[ \t]*\d*[ \t]*\n", ''           # leftover headers ("62  ECLECTIC SERIES,")
  $body = $body -creplace "(\w) n't\b", '$1n''t' -creplace "'T is\b", "'Tis"                    # old spelling: "do n't" -> "don't"
}
$heads = [regex]::Matches($body, $headRx)
# the text of each lesson runs from the end of its heading to the next heading (Regex.Split would also return captured groups)
$parts = @($body.Substring(0, $heads[0].Index))
for ($i = 0; $i -lt $heads.Count; $i++) { $s = $heads[$i].Index + $heads[$i].Length; $e = if ($i + 1 -lt $heads.Count) { $heads[$i + 1].Index } else { $body.Length }; $parts += $body.Substring($s, $e - $s) }
$sounds = 'th','sh','ch','ng','ew','oy','ow','wh','ou','oo','sk','qu','oi','gh','ck'
$romanVal = @{ I=1; V=5; X=10; L=50; C=100 }
# scanned "LVll." = LVII, so a lowercase l counts as I
function Roman($r) { if ($r -match '^\d+$') { return [int]$r }; $r = $r -creplace 'l', 'I'; $t = 0; for ($i = 0; $i -lt $r.Length; $i++) { $v = $romanVal["$($r[$i])"]; if ($i + 1 -lt $r.Length -and $romanVal["$($r[$i+1])"] -gt $v) { $t -= $v } else { $t += $v } }; $t }
function Sentences($para) {
  # split a paragraph into kid-sized sentences; keep quotes and "--" asides with their sentence
  $p = (($para -replace '\s+', ' ').Trim()) -creplace '^(?:\d+|I)\.\s+(?=["A-Z])', ''
  $out = [regex]::Split($p, '(?<!\b(?:Mr|Mrs|Dr|St)\.)(?<=[.!?]"?)\s+(?=["A-Z])') | Where-Object { $_ }
  # re-join pieces that split inside a quotation
  $merged = @(); $buf = ''
  foreach ($s in $out) { $buf = if ($buf) { "$buf $s" } else { $s }; if ((($buf -split '"').Count - 1) % 2 -eq 0) { $merged += $buf; $buf = '' } }
  if ($buf) { $merged += $buf }
  $merged | ForEach-Object { $s = $_.Trim(); if ($s -match '[A-Za-z]$') { $s += '.' }; $s }
}
# vocabulary words carry accent marks and syllable breaks in the later lessons: cun'ning, be cause', did n't
function IsPoem($para) {
  $ls = @($para.Trim() -split '\n' | Where-Object { $_.Trim() })
  # poem lines are short and each starts with a capital; wrapped prose goes on in lowercase
  if ($para -match '\n\s+\S') { return $true }
  if ($ls.Count -lt 2 -or ($ls | Measure-Object -Property Length -Maximum).Maximum -gt 55) { return $false }
  $low = @($ls | Where-Object { $_.Trim() -cnotmatch '^["''\u2018\u201c(]{0,2}[A-Z]' }).Count
  ($low -eq 0) -or ($ls.Count -ge 4 -and $low -le 1)
}
function CleanWord($t) {
  $t = $t -replace '\s+', ''
  if ($t -match "(n't|'s|'ll|'ve|'re|'d|'m)$" -or $t -match "^'tis$") { return ($t -replace "'(?=.*')", '') }   # keep a real contraction's apostrophe
  $keep = $t.TrimEnd("'")
  if ($keep -match "^(o'clock|o'er|ne'er|e'er|e'en)$") { return $keep }   # old poetic words keep their apostrophe
  $t -replace "'", ''
}
function VocabTokens($ln) {
  $ln = $ln -replace '\s*\([^)]*\)', ''                                         # pronunciation notes: (wuns), (a gen'), (as f)
  $cols = if ($ln -match '\S\s{2,}\S') { $ln.Trim() -split '\s{2,}' } else { $ln.Trim() -split '\s+' }
  foreach ($c in $cols) {
    if (-not $c) { continue }
    if ($c -match '\s') {
      if ($c -match "'") { CleanWord $c }                                         # syllables of one word: be cause'
      elseif ($c -match '^(a|an|the)\s') { }                                      # phrase like "a black hen": not a new word
      else { $c -split '\s+' | ForEach-Object { CleanWord $_ } }                  # two words in one column: night owl
    } else { CleanWord $c }
  }
}
$nums = @()
if ($cfg.headRx) {
  # A real lesson heading has a page number ("(74)") or is the next number in order. That skips a lesson's own
  # numbered parts ("II. SUMMER.") and survives misprinted numerals ("XVV.", a second "LXX."): lessons are numbered in order.
  $keep = @(); $prev = 0
  # up to 2 lessons may be missing between two headings; a heading with a page number but a misprinted numeral is the next lesson
  foreach ($m in $heads) {
    $v = Roman $m.Groups[1].Value
    if ($v -ge $prev + 1 -and $v -le $prev + 3) { $keep += $m; $prev = $v; $nums += $v }
    # a misprinted numeral is still near its place (XVV for XXV); a lesson's own small parts ("III. A GOOD NAME. (95)" inside lesson 12) are not
    elseif ($m.Value -match '\(\d+\)\s*$' -and $v -ge $prev - 5) { $keep += $m; $prev++; $nums += $prev }
  }
  $heads = $keep
  $parts = @($body.Substring(0, $heads[0].Index))
  for ($i = 0; $i -lt $heads.Count; $i++) { $s = $heads[$i].Index + $heads[$i].Length; $e = if ($i + 1 -lt $heads.Count) { $heads[$i + 1].Index } else { $body.Length }; $parts += $body.Substring($s, $e - $s) }
}
# authors from the table of contents: "87.  The Best Capital      Louisa M. Alcott     245"
$tocAuthors = @{}
# (page column optional: the Fifth Reader's contents have none); the first entry for a number wins, which is the contents page
$tocText = $txt.Substring(0, $txt.LastIndexOf($(if ($cfg.start) { $cfg.start } else { 'x' })) + 1)
if ($cfg.tocEnd) { $ci = $tocText.IndexOf($(if ($cfg.tocStart) { $cfg.tocStart } else { 'CONTENTS' })); $tocText = $tocText.Substring($ci, $tocText.IndexOf($cfg.tocEnd, $ci) - $ci) }   # only the contents page, not the chapters on reading aloud
foreach ($m in [regex]::Matches($tocText, '(?m)^\s*(\d+)\.\s+(\S.*?\S)\s{2,}(\S.*?\S)(?:\s{2,}(\d+))?\s*$')) {
  $a = (($m.Groups[3].Value -split '\s{2,}')[-1] -replace '\.?\s*\d+$', '').TrimEnd('.')   # "Longfellow.290": page number stuck to the name
  if ($a -notmatch '^\d' -and -not $tocAuthors.ContainsKey([int]$m.Groups[1].Value)) { $tocAuthors[[int]$m.Groups[1].Value] = $a }   # skip a line that holds two entries
}
$lessons = @()
for ($k = 0; $k -lt $heads.Count; $k++) {
  $h = $heads[$k].Value.Trim()
  $n = if ($h -eq 'Lesson 1') { 1 } else { Roman(([regex]::Match($h, 'LESSON ([IVXLC]+)')).Groups[1].Value) }
  $headTitle = ''
  if ($cfg.headRx) {
    $hm = [regex]::Match($h, $cfg.headRx); $n = $nums[$k]
    $headTitle = (Get-Culture).TextInfo.ToTitleCase($hm.Groups[2].Value.Trim().TrimEnd('.').Trim('"', [char]0x201c, [char]0x201d).TrimEnd('.').ToLower()) -creplace "(\w) N't", '$1n''t' -replace '\(Concluded\.?\)', '(concluded)' -replace '\(Continued\.?\)', '(continued)'
  }
  $review = $h -match 'REVIEW'
  $block = $parts[$k + 1]
  $block = $block -replace '\[Footnote:[^\]]*\]', '' -replace '(?m)^\s*(\d+|[IVX]+)\.\s*$', ''
  # a title line glued to its poem ("ALICE'S SUPPER." then the verses) gets its own paragraph
  $block = $block -creplace '(?m)^([A-Z][A-Z .,''\u2019!-]{3,})$\n(?=\S)', "`$1`n`n"
  $author = ''; $defs = @(); $questions = @()
  # DEFINITIONS / EXERCISES / NOTES at the end of a lesson (Fourth Reader)
  $tm = [regex]::Match($block, '(?m)^[ \t]*(?:DEFINITIONS|EXERCISES|NOTES?)\b')
  if ($tm.Success) {
    $tail = $block.Substring($tm.Index); $block = $block.Substring(0, $tm.Index)
    foreach ($sec in [regex]::Matches($tail, '(?s)(DEFINITIONS|EXERCISES|NOTES?)\.?\s*-*(.*?)(?=(?:\n[ \t]*(?:DEFINITIONS|EXERCISES|NOTES?)\b)|\z)')) {
      $txt2 = ($sec.Groups[2].Value -replace '\s+', ' ').Trim()
      if ($sec.Groups[1].Value -eq 'DEFINITIONS') {
        $txt2 = $txt2 -replace '^In defining words, that meaning is given which is appropriate to them in the connection in which they are used\.\s*', ''
        foreach ($ln in (($txt2 -replace '(?:^|\s)\d+\.\s+', "`n") -split "`n")) {
          foreach ($entry in [regex]::Split($ln.Trim(), '(?<=\.)\s+(?=[A-Z][\w''/\-]*(?: [\w''/\-]+){0,2},\s)')) {
            $cm = [regex]::Match($entry, '^([A-Z][\w''/\-]*(?: [\w''/\-]+){0,2}),\s+(.+?)\.?\s*$')
            if ($cm.Success) {
              $w = $cm.Groups[1].Value -replace '[''/\-]', ''
              $d = ($cm.Groups[2].Value -replace '(?<=[a-z])-(?=[a-z])', '').Trim()
              $defs += ,@($w, $d)
            }
          }
        }
      } elseif ($sec.Groups[1].Value -eq 'EXERCISES') {
        $questions += @([regex]::Split($txt2, '(?<=\?)\s+') | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '\?$' })
      }
    }
  }
  if ($cfg.prose) {
    # the author's name under a poem: "John G. Whittier.", "Mrs. Follen."
    $am = [regex]::Match($block, '\n[ \t]*((?:Mrs?\.\s+)?(?:[A-Z]\.\s*|[A-Z][a-z]+\s+){0,3}[A-Z][a-z]+\.)\s*$')
    if ($am.Success) { $author = $am.Groups[1].Value.TrimEnd('.'); $block = $block.Substring(0, $am.Index) }
    $block = $block -creplace '(?m)^(?=[ \t]*\d+\.\s+\S)', "`n"                                   # each numbered paragraph is its own paragraph
    foreach ($sp in ([regex]::Matches($block, '(?m)^([A-Z][a-z]+)\.\s+(?=["A-Z])') | Group-Object { $_.Groups[1].Value } | Where-Object { $_.Count -ge 2 -and $_.Name -notmatch '^(Mr|Mrs|Dr|St)$' })) {
      $block = $block -creplace "(?m)^$($sp.Name)\.\s+", "`n$($sp.Name): "                       # a play: "Rose. See how..." -> "Rose: See how..."
    }
  }
  # pull out illustrations (may span lines); script exercises become the cursive copy work
  $script = @(); $picText = ''
  foreach ($m in [regex]::Matches($block, '\[Illustration:([^\]]*)\]')) {
    $c = $m.Groups[1].Value
    if ($c -match '^\s*Script [Ee]xercise:') {
      $c = $c -replace '^\s*Script [Ee]xercise:', ''
      $paras = [regex]::Split($c.Trim(), '\n\s*\n')
      foreach ($pp in $paras) {
        if (IsPoem $pp) { $script += ($pp -split '\n' | ForEach-Object { $_.Trim() } | Where-Object { $_ }) }   # poem: keep lines
        else { $script += Sentences $pp }
      }
    } elseif (-not $picText) { $picText = ($c -replace '\s+', ' ').Trim().TrimEnd('.') }
  }
  $block = [regex]::Replace($block, '\[Illustration:[^\]]*\]', "`n`n@@PIC@@`n`n")
  $paras = [regex]::Split($block.Trim(), '\n\s*\n') | ForEach-Object { $_.TrimEnd() } | Where-Object { $_.Trim() }
  $words = @(); $letters = @(); $lines = @(); $inText = $false; $first = $true; $title = ''; $about = ''
  foreach ($p0 in $paras) {
    if ($p0.Trim() -eq '@@PIC@@') { if ($words.Count -or $letters.Count) { $inText = $true }; continue }
    $p = $p0 -replace '\s*\([^)]*\)', ''
    $isVocab = -not $cfg.prose -and -not $inText -and (($p -replace '\b(Mr|Mrs|Dr|St)\.', '$1') -notmatch '[.!?;,"]') -and ($first -or $p -match '\S\s{2,}\S' -or $p -match '^\S+$')
    # phrase rows like "a rat    a cat" come after the picture, not before it
    if ($isVocab -and $words.Count -and $p -match '^\s*(a|the|an)\s\w+\s{3,}') { $isVocab = $false }
    if ($isVocab) {
      foreach ($ln in ($p0 -split '\n')) {
        foreach ($t in (VocabTokens $ln)) {
          if (-not $t) { continue }
          $isSound = ($sounds -contains $t) -or ($t.Length -eq 1 -and -not ($first -and ($t -ceq 'a' -or $t -cmatch '^[A-Z]$')) -and $t -cne 'I')
          if ($isSound) { if ($letters -notcontains $t) { $letters += $t } } elseif ($words -notcontains $t) { $words += $t }
        }
        $first = $false
      }
      continue
    }
    $inText = $true
    # a note about the author before the selection ("By Celia Thaxter, who was born...", "Hester Lynch Thrale. 1739--1821, ...")
    if ($cfg.headRx -and -not $lines.Count -and -not $about -and $p -match '\bborn\b|\d{4}\s*-{1,2}\s*\d{2,4}') {
      $ta = if ($tocAuthors.ContainsKey([int]$n)) { ($tocAuthors[[int]$n] -split '\s+')[-1] } else { '' }
      if ($p -match '^\s*By\s' -or ($ta -and $p -match "\b$([regex]::Escape($ta))\b")) { $about = ($p -replace '\s+', ' ').Trim(); continue }
    }
    if ($p.Trim() -cmatch '^[A-Z][A-Za-z'' ]{2,40}$' -and -not $lines.Count -and $p.Trim() -cmatch '^(?:(?:[A-Z][a-z'']*|a|an|and|the|of|in|on|at|to|for|with|by)\s?)+$' -and $p.Trim() -match '\s') { $title = $p.Trim(); continue }
    if ($p.Trim() -cmatch '^[A-Z][A-Z .,''\u2019!?-]+$' -and ($cfg.prose -or $p -notmatch '\?')) { $title = (Get-Culture).TextInfo.ToTitleCase($p.Trim().TrimEnd('.').ToLower()); continue }   # story title: THE WHITE KITTEN.
    if (IsPoem $p) { $lines += ($p -split '\n' | ForEach-Object { ($_.Trim()) -replace '^\d+\.\s+', '' } | Where-Object { $_ }) }          # poem
    elseif ($p -notmatch '[.!?;,"]' -and $p -match '\S\s{3,}\S') { $lines += ($p.Trim() -split '\s{3,}') }                 # phrase row
    else { $lines += Sentences $p }
  }
  if (-not $lines.Count) { $lines = $script }
  $pic = ''; foreach ($key in $pics.Keys) { if ($picText -match "(?i)$key") { $pic = $pics[$key]; break } }
  if ($cfg.pics.ContainsKey([int]$n)) { $pic = $cfg.pics[[int]$n] }
  if (-not $pic -and $cfg.prose) { foreach ($key in $pics.Keys) { if ("$title $(($lines | Select-Object -First 3) -join ' ')" -match "(?i)\b$key(?:s|es)?\b") { $pic = $pics[$key]; break } } }   # no picture notes: guess from the title
  if (-not $pic) { $pic = if ($review -or $cfg.prose) { '๐Ÿ“–' } else { '๐Ÿ–ผ๏ธ' } }
  $o = [ordered]@{ n = $n; pic = $pic; picText = $(if ($picText) { $picText } elseif ($review) { 'Review' } else { '' }); words = @($words); letters = @($letters); lines = @($lines) }
  if ($review) { $o.review = $true }
  if ($headTitle) { $title = $headTitle }   # the heading's title wins over part titles inside the lesson ("IV. WINTER.")
  if ($defs.Count) {
    # the book's own new words: shown in lowercase unless the lesson only ever writes them with a capital (names)
    $alltext = $lines -join ' '
    $o.defs = [ordered]@{}
    foreach ($dd in $defs) {
      $w = $dd[0]; if ($alltext -cmatch "\b$([regex]::Escape($w.ToLower()))\b" -or -not ($alltext -cmatch "\b$([regex]::Escape($w))\b")) { $w = $w.ToLower() }
      if (-not $o.defs.Contains($w)) { $o.defs[$w] = $dd[1] }
    }
    $o.words = @($o.defs.Keys | Select-Object -First 12)
  }
  if ($questions.Count) { $o.questions = @($questions) }
  if ($title) { $o.title = $title }
  if ($cfg.headRx -and $tocAuthors.ContainsKey([int]$n)) { $author = $tocAuthors[[int]$n] }   # the contents page knows best
  if ($author -match 'Reader|EXAMPLES') { $author = '' }
  if ($author) { $o.author = $author }
  if ($about) { $o.about = $about }
  if ($script.Count) { $o.script = @($script) }
  if (-not $lines.Count) { Write-Host "Lesson $n has no text in Gutenberg's copy ($title), skipped" -ForegroundColor Yellow; continue }
  $lessons += $o
}
if ($cfg.prose) {
  # New words = words not met in the earlier books or earlier lessons, in reading order, up to 10 per lesson
  $seen = New-Object 'System.Collections.Generic.HashSet[string]' ([StringComparer]::OrdinalIgnoreCase)
  $wordRx = "[A-Za-z]+(?:'[A-Za-z]+)?"
  foreach ($prev in $cfg.after) {
    $pj = Get-Content "$root\public\books\$prev.json" -Raw -Encoding UTF8 | ConvertFrom-Json
    foreach ($PL in $pj.lessons) { foreach ($s in @($PL.lines) + @($PL.words) + @($PL.script)) { foreach ($m in [regex]::Matches("$s", $wordRx)) { [void]$seen.Add($m.Value) } } }
  }
  foreach ($o in $lessons) {
    $text = (@($o.lines) + @($o.script)) -join ' '
    $new = @()
    foreach ($m in [regex]::Matches($text, $wordRx)) {
      $w = $m.Value
      if ($w.Length -lt 2 -or $w -match "^n'" -or -not $seen.Add($w)) { continue }
      # names keep their capital (capitalized in the middle of a line); other words are shown in lowercase
      if (-not ($text -cmatch "(?:[a-z]|\b(?:Mr|Mrs|Miss|Dr)\.)\s+$([regex]::Escape($w))\b") -or ($text -cmatch "\b$([regex]::Escape($w.ToLower()))\b")) { $w = $w.ToLower() }
      $new += $w
    }
    if (-not @($o.words).Count) { $o.words = @($new | Select-Object -First 10) }   # the book's own word list wins when it has one
  }
}
# Last clean-up of every line: printed page headers that ended up inside a sentence ("... ECLECTIC SERIES. ..."),
# footnote/section marks (#, *, [ ]), and scanned digits ("l0" = 10, "I1" = 11)
function CleanLine($s) {
  $s = $s -creplace '\d*\s*\b(?:ECLECTIC (?:SERIES|READER)|(?:FIRST|SECOND|THIRD|FOURTH|FIFTH|SIXTH) READER)\b[.,]?\s*\d*', ' ' -replace '[#*\[\]]', ''
  $s = $s -creplace '\bI1\b', 'I' -creplace '(?<=\d)l|l(?=\d)', '1' -creplace '^\d+\s+(?=[a-z])', '' -creplace '(?<=[a-z]{3})\d\b', ''   # footnote number on a word ("orthography1"); "I1 will" = I; "l0" = 10; a page number before the text
  ($s -replace '\s{2,}', ' ').Trim()
}
foreach ($o in $lessons) {
  $o.lines = @($o.lines | ForEach-Object { CleanLine $_ } | Where-Object { $_ -match '[A-Za-z]' })
  if ($o.script) { $o.script = @($o.script | ForEach-Object { CleanLine $_ } | Where-Object { $_ -match '[A-Za-z]' }) }
}
$out = [ordered]@{ title = $cfg.title; sub = $cfg.sub; color = $cfg.color; source = "Project Gutenberg #$($cfg.gutenberg) (public domain)"; lessons = $lessons }
$json = $out | ConvertTo-Json -Depth 6
New-Item -ItemType Directory -Force "$root\public\books" | Out-Null
[IO.File]::WriteAllText("$root\public\books\$Book.json", $json, (New-Object Text.UTF8Encoding $false))
"$($lessons.Count) lessons"
$lessons | ForEach-Object { "{0,2} {1} w[{2}] l[{3}] lines={4} script={5} | {6}" -f $_.n, $_.pic, ($_.words -join ' '), ($_.letters -join ' '), $_.lines.Count, $(if ($_.script) { $_.script.Count } else { 0 }), $_.lines[0] }
EOF

2. Make the lesson file

PC (PowerShell). It downloads the book from Gutenberg the first time and prints “63 lessons” and one line per lesson:

powershell -ExecutionPolicy Bypass -File C:\ABCBooks\tools\make-book.ps1 -Book first1879

3. Record it with Eloquence

PC (PowerShell). About 5,300 recordings, about 3 minutes here:

powershell -ExecutionPolicy Bypass -File C:\ABCBooks\tools\make-audio.ps1 -Book first1879

Send them to CT 306 (abc-web) and turn them into MP3s (it prints “converted N clips” and the folder sizes):

powershell -ExecutionPolicy Bypass -File C:\ABCBooks\tools\push-audio.ps1

4. Put it on the server

PC (PowerShell):

powershell -ExecutionPolicy Bypass -File C:\ABCBooks\deploy.ps1

Open https://games.503mail.com/abcbooks/, pick a name, and the blue McGuffey’s First Eclectic Reader book opens a map of 63 lessons.

Troubleshooting

The logs and the Tablet check page are the same as in the Primer post. For this book:

The book doesn’t open, or says “Coming soon”

  • Open: PC (PowerShell). Both should print 200:
"/abcbooks/books/first1879.json","/abcbooks/audio/first1879.json" | % { (Invoke-WebRequest "https://games.503mail.com$_" -UseBasicParsing).StatusCode }
  • Look for: a 404 on books/first1879.json means step 2 or 4 was skipped. A 404 on audio/first1879.json means step 3 or 4 was skipped (the book then opens but has no voice on the kids’ tablets).

The recordings on the server

  • Open: Proxmox host shell.
pct exec 306 -- du -sh /var/www/abcbooks/audio/first1879/s60 /var/www/abcbooks/audio/first1879/s75
  • Look for: about 30 MB and 25 MB.

Notes

  • Checking a converted lesson: make-book.ps1 prints one line per lesson with its new words (w[...]), letter sounds (l[...]), the number of reading lines and script lines, and the first line. Odd new words (a phrase, a leftover accent mark) show up right there.
  • Same voice files, two books: each book has its own recordings folder (audio/first1879/), but the app looks in every book’s recordings when a text is missing in the open one, so the home-screen greeting works before any book is open.
  • Kids’ progress is kept per book, so finishing the Primer and starting the First Reader don’t mix up the stars.
  • Next: Spell & Read, from the 1867 Pictorial Primer.