Standard recommendations and steps for writing introductory books Suppose I plan to write an introduction to, say, statistics that's intended both for self-learning and as a companion to a university course.
Is there any standard advice about the following?

Defining the scope of the book
The planning of the writing process
Organising the table of contents
Models for organising the content of each section
Maintaining coherence in the writing style across the book (especially when writing in co-authorship)
How to write exercises/problems
Models of interaction between content and exercises (and lessons)
Any other topic related to the writing of a book like this

The answer should to be useful for introductory books for which these questions apply. However, the answer could use statistics or any other field as an example.
My recommendation (having done something like this) is to first teach one or more courses in this area for at least five years before writing your text.
Start off in year 1 by making slides or notes for your lectures using LaTeX. If you post those, you will have an incentive to get them right (and students will also find some errors). Fix the mistakes as you find them before year 2. After year 2, consider changing the organization or splitting up some material if students have more trouble with it.
After five or more years, you will have come up with a sensible organization of topics. You will know how to foreshadow and set the exposition up for later developments; will be familiar with common questions and misunderstandings; and, will have exercises already written (with answers).
Then write the book using your slides or lecture notes as a skeleton and incorporating the exercises you found helped students the most. (Don't forget to thank the students who found errors.) You can also add in topics you wanted to cover but previously did not.
As I mentioned, LaTeX is your friend for this. With the right organization, it can make your table of contents for you (as well as a table of figures and tables), create an index, and show a list of references with clickable URLs (if you create a PDF file).
After that, teach a couple of classes using the text and you will find areas to improve. You will also likely see tweaks to make your old slides/lecture notes fit the text better.
As for publishing, you can choose an academic press or self-publishing. Both stink.
An academic press will not do much editing, will probably re-type all of your hard work and introduce errors, will charge a high price that students may not want to pay, and will likely give you no revenue; however, they will distribute the book widely (often to libraries).
Self-publishing using a print-on-demand place will get you about the same amount of editing help, will earn you zero credibility, and will receive far less distribution. However, you may actually make a little bit of money, you will have much more control over pricing, and nobody will retype all your work and introduce errors.
I know people who have done both and most thought both options were not great but more seemed to be considering self-publishing because academic presses seem to offer so little for services now.