Replica variables, loop expansion, and spectral rigidity of random-matrix ensembles