The autonomous institutions of Catalonia had been abolished by the Nueva Planta decrees at the end of the War of the Spanish Succession, in which Catalonia had sided against Philip V, and so Catalonia was now largely ruled by the intendente sent by Madrid.
Born in Seville, he was the son of Brigadier José de Gayangos, intendente of Zacatecas, in New Spain.