Quantum theory of magnetoelectricity in rare-earth multiferroics: Nd, Sm, and Eu ferroborates