Historical sociolinguistics aims at reconstructing the history of a language in connection to its social and historical context. For Old Catalan, we have to rely on a limited set of written documents and our knowledge of the historical context in order to establish how different social variables interacted with the language in the past.
The Crown of Aragon was a multilingual entity where several linguistic varieties were in contact: there was Catalan, spoken in Catalonia, the east of Aragon and the newly conquered territories (the Kingdom of Valencia and the Balearic Islands), there was Occitan, spoken in the region of Montpellier, which was part of the Crown at that point, there was Aragonese, spoken in Aragon and parts of the newly conquered Kingdom of Valencia (at least for a short period of time) and, of course, there was Latin. At Crown level, each language was used for a different purpose: Catalan was the language of the king and the language used to represent the Crown of Aragon abroad; Aragonese was the language of Aragon and Aragonese nobility, and the language used to communicate with other kingdoms in the Iberian peninsula; Occitan was the language of poetry; and Latin was the language of the Church and the language of the majority of official documents.
Some documents help us understand how these languages interacted with each other in the Crown and what they represented. One such document is the Llibre dels Fets 'Book of the Deeds', which narrates the life of King James I of Aragon, and in it, there is extensive code-switching from Catalan, the language in which the text is written, to other varieties, including Occitan, Aragonese, French, Latin and Arabic. By analysing the code-switching patterns in the text, I was able to establish that not all languages are used to portray characters coming from the region the language is associated with. Aragonese is not used to portray the speech of Aragonese characters; instead, their speech is represented in Catalan. At the same time, Aragonese is not absent from the text: it is used to portray the speech of Castilian characters and for the intervention of the King's son, asking his father for forgiveness after killing his illegitimate brother. These characters have in common that they oppose in one way or another the King. The Crown of Castile competed with the Crown of Aragon for the reconquest of the Peninsula's territory and the King's son had greatly defied his father by killing his illegitimate brother, who was one of the King's favourite children and whom he perceived as a threat. Therefore, Aragonese is used to portray opposition to the King, while Catalan is used to show allegiance to him, and by using it to portray the speech of Aragonese knights, the author(s) erase their political opposition to the King and present them as faithful subjects. You can read more on this in Pujol i Campeny 2020b.