I'm thinking of general rules on how to write mathematics books to people that teach themselves, and are quite alone with only the single aid of the printed book (no YouTube, no software, and so on). Any clue?
Well, start by introducing your topic (what is your topic, as in a description).
Then go on about things your reader needs to know before they can study the topic about to be explained. Be sure to include enough information so that the targeted audience will be able to understand you. If you are writing a book about Ramanujan summations, you don't need to explain how the basic algebra works because your audience is probably experienced with summation methods. But do explain what a Ramanujan summation method is and things the reader should understand before trying to understand the Ramanujan Summation method.
Then, go on explaining why a Ramanujan Summation method works the way it does. Go in depth as to the fundamental properties it has, such and such.
You may want to sprinkle the writing with interesting things where relevant, such as $1+2+3+\dots=-1/12$ (a Ramanujan summation). State this before and/or after introducing a topic. For example, state the cool math thing (above) before explaining to get your reader interested in the summation of divergent series. Then, revisit the question after the reader has a thorough understanding of the methods. Or, use this to guide the reader through the process of summating a divergent series.
Be sure to use common symbols and similars, if you are unclear as to write $a^b$ or $exp_a(b)$, ask here, another stack exchange site.
Remember to explain what $a^b$ means if you feel your reader doesn't understand it.
CHOOSE ONE TARGET AUDIENCE AND STICK WITH IT! It does not please a well educated mathematician to skip the first $50$ pages to get to the content they want to read. On the other hand, it does not please a reader to read the first page and understand nothing. Use the table of contents or simply write multiple books.
It's probably better to explain more and be long-winded than to be short and unexplanatory. The whole purpose of the book is to teach, so remember to teach your reader through every "step."
That's about all I can think of for now.
A tangential half-answer: if the goal is to teach mathematics, rather than to prepare people to cope with school-mathematics... at the very least, avoid all the things that are mandatory in mathematics as a school subject. The meta-requirements are especially invidious to actual mathematics. On the other hand, if the goal is exactly to prepare students to cope with hurdles, filters, obstacles in their lives posed in the form of mathematics, that's a very different thing.
It seems to me a sad irony that the attitudes of mind that optimize understand of mathematics, or of any serious enterprise, are often opposite to the traits rewarded by routine school situations, where compliance, obedience, are "important".
It is importantly true that exceptional preparation in genuine mathematics makes possible "high testing" even in conventional school-bound situations, at least for people who can cope with the cognitive dissonance.
Among other things, one should not teach people to distrust their own (well-earned) physical intuition, which enables them to walk and chew gum at the same time, but only to recommend refinements. It is certainly not the case that mathematics is anti-intuitive, but, at "worst/most-provocative", subtler than anticipated. So we refine our intuition, and now we can walk, chew gum, and integrate discontinuous functions at the same time.
Programmed learning is the answer. I have used it for learning accounting during a transatlantic flight before having to do a hardcore finance class (knowing nothing on business). Also fastest way I know to learn nautical rules of the road. Great English text that is a hidden treasure for naval officers.
Same holds in math. Check out Stroud's books. He really did it right.