Even more than its language, Catalonia is defined by its history. Its seed was the Spanish March established by Frankish king Charlemagne as a southern buffer against the Muslim invaders in the eighth and ninth centuries, a strip of territory running west-to-east along and south of the Pyrenees and including what is now Andorra. This land was ruled by counts, each with his own county, naturally, pledging allegiance to the Carolingian monarchs, as Charlemagne's dynasty was called, these counts originally being nominated directly by the Carlongians. The most important of these counts was the Count of Barcelona, who extended his sway over other counties, until towards the end of the ninth century the title became hereditary (the last nominated count being the memorably named Wilfred I the Hairy). In 985, Borrell II ceased paying allegiance to the Carolingians, and in 1150 Count Ramón Berenguer IV of Barcelona married Petronila of Aragon, so unifying the two titles. Their son Alfonso II of Aragón (I of Barcelona) was the first ruler of the two lands, jointly called the "Crown of Aragón," though modern historians sometimes use the term "Catalan-Aragonese Confederation," presumably on grounds of explicitness. Whatever, although its name was Aragón, Barcelona was its centre, and Catalonia expanded quickly to take in the Balearic Islands and Valencia in the 13th century, Sicily and Sardinia in the 14th and Naples in the 15th century. This has been called a kind of Mediterranean Empire, and Catalonia was certainly ruler of the Mediterranean waves. The unification of the Castilian and Catalan crowns by the marriage of Fernando II of Aragón and Isabella I of Castile (1469), the end of the reconquista (1492) and the ensuing conquest of the Americas shifted the political and economic centre of gravity in Spain towards Seville.
A historical curiosity is that the Catalan police force, the Mossos d'Esquadra ("Boys of the Squad"), was established in 1721, making it the oldest police force in Europe. Command of it has oscillated between the Spanish state and Catalonia ever since.
In coming centuries, Catalonia's laws and independence were steadily undermined as Spain became progressively more centalized. Regionalist reaction tends to be the same in these cases, to pick the other side whenever the chance presents itself. But the Crown of Aragón was abolished as a result of the horrendously complicated War of Spanish Succession (the Catalans sided with the British, to no advantage at all), as was the constitution of the Principality of Catalonia. In the Napoleonic Wars, the Catalans again took sides against the French well ahead of the rest of Spain, at first reduced to a Napoleonic puppet state until popular unrest tipped the balance the other way.
In the second half of the nineteenth century, like the Basque Country, Catalonia became a leading player in Spain's tardy industrial revolution, both bringing prosperity and reviving nationalist or regionalist feelings.
In the early twentieth century, as Catalonia was successively given and relieved of different degrees of autonomy, Catalan history became a violent mixture of ruthless industrialists (complete with pistoleros, hired gunmen), reckless trades unionists, no-holds-barred anarchists, and stubborn, hardheaded nationalists. In 1932, under the Second Spanish Republic, the Generalitat was restored, but this too, was short-lived: the Generalitat rebelled against the right-wing government which won the elections in 1934 and was suspended.
During the Spanish Civil War, when the fascists were about to take Barcelona in 1939, the Generalitat went into exile, and the succession of its presidents was maintained throughout Franco's dictatorship. In 1977, four years after Franco's death, at the invitation of Adolfo Suárez, Josep Tarradellas came out of exile to reestablish the Generalitat, with Catalan autonomy defined within the Spanish Constitution and a Catalan Statute of Autonomy. The new Generalitat's first elections were held in 1980 and won by Jordi Pujol, a very short right-of-centre nationalist, who continued to be reelected president until his retirement in 2003.