Arithmetization of metamathematics in a general setting