Understanding Darboux Sum Comparison Lemma I can't understand how the green-underlined inequality holds? 
If $f(x) \ge 0$ for all $x\in [a,b]$ , then the mentioned inequality is true, otherwise I doubt that; and thus may the proof is not correct at all? Thanks.   


 A: The proof is flawed for the reason you state. 
I suspect this lemma is intended for proving that Riemann sums converge to the integral in the limit as the partition norm tends to zero, given that the  Riemann integral is defined as a limit approached as partitions are refined. I am assuming here that the author's term "gap" means the norm or maximum interval length for the partition, $gap \, P = \|P\|$.
What is correct about this lemma (and potentially useful) is the combined result
$$U(f,P^*) - L(f,P^*) \leqslant U(f,P) - L(f,P) + 2 k M \,gap P^*.$$
This can be proved as follows.  Note that
$$M_i = \sup_{x \in [x_{i-1},x_i]}f(x) \leqslant M, \\ m_i = \inf_{x \in [x_{i-1},x_i]}f(x) \geqslant -M.$$
Since there are at most $k$ crossing indexes we have $$\sum_{i \in \mathcal{C}}M_i(x_{i}- x_{i-1}) \leqslant k M gap \, P^*,\\ \sum_{i \in \mathcal{C}}m_i(x_i- x_{i-1}) \geqslant -k M gap \, P^*,$$
which implies
$$\tag{1} \sum_{i \in \mathcal{C}}(M_i-m_i)(x_i- x_{i-1}) \leqslant 2k M gap \, P^*.$$
For non-crossing indexes we see that subintervals $[x_{i-1},x_i]$ coincide with subintervals of the refinement $P' = P \cup P^*$, and, hence,
$$\tag{2} \sum_{i \notin \mathcal{C}}(M_i-m_i)(x_i- x_{i-1}) \leqslant U(f,P') - L(f,P').$$
Adding (1) and (2) we obtain
$$U(f,P^*) - L(f,P^*) = \sum_{i \in \mathcal{C}}(M_i-m_i)(x_i- x_{i-1})  + \sum_{i \notin \mathcal{C}}(M_i-m_i)(x_i- x_{i-1}) \\ \leqslant  U(f,P') - L(f,P') + 2k M gap \, P^* \\ \leqslant  U(f,P) - L(f,P) + 2k M gap \, P^* ,$$
where the final inequality follows because $P'$ is a refinement of $P$.
