This is, in a way, a follow-up to this question.
I see the following band diagram for a forward biased diode everywhere:
In the above picture, I marked a point with potential zero (where battery is connected to the N-type material) and chose two arbitrary points \$A\$ and \$B\$ inside the P-type material.
From now on, \$\varphi (P)\$ denotes the potentia at point \$P\$.
Since we apply the potential \$\;\lvert V_a \rvert = \varphi(A)\$ to the L region, the potential along the diode must somehow (although I don't know how to precisely mathematically describe it and nobody has answered this question yet) strictly (because the very reason why the charge flows from one point to another is the potential gradient) and continuously decrease to \$0\$, but it also has to be defined at every point.
This way, for example, \$\varphi(A) \gt \varphi(B)\$.
Then the Fermi level, being defined as the potential energy energy per particle, must also vary throughout the P and N regions. In particular, \$E_F(A) > E_F(B)\$, so these levels on the diagram cannot be a horizontal line. I drew in red over the band diagram how they should vary.
Am I wrong somewhere? How can I mathematically describe the Fermi level dependence on a space coordinate inside a diode? I think the only way to answer the last question is to find the dependence of the potential first, which I don't know how to accomplish.