Generate textbook-quality synthetic data for training LLMs and SLMs