> Unfortunately the number of people that can write a good teaching book is very small.
I disagree. I claim that almost anyone can write a good teaching book, as long as they follow the instructions. How long it will take is up to the skill, but with enough repetition, I think anyone can do it.
1) Write the material
2) Test how well it works
3) Fix found problems
4) Go to step 2
I think the major issue with bad books is that they were never tested by anyone. I claim this, because I have found errors from math books that would have been obvious to anyone who had tried to do the exercise. This requires more work, but it is work that literally even a kid could do. It just costs either money or volunteer time.
> Suggesting that an author goes through all that work for free is unrealistic
You can have free text books and pay huge amount of money to the authors at the same time. You can get the money from government or private donators. You pay for the work once and after that the work is published for free use.