  The integrating factor technique is widely used to solve numerically (in
particular) the Schr\"odinger equation in the context of spectral methods.
Here, we present an improvement of this method exploiting the freedom provided
by the gauge condition of the potential. Optimal gauge conditions are derived
considering the equation and the temporal numerical resolution with an adaptive
embedded scheme of arbitrary order. We illustrate this approach with the
nonlinear Schr\"odinger (NLS) and with the Schr\"odinger-Newton (SN) equations.
We show that this optimization increases significantly the overall
computational speed, sometimes by a factor five or more. This gain is crucial
for long time simulations.
