Last time we saw Ibn Battuta through the Kingdom of Tlemcen, which at the time was at war with the Hafsids over control of the city of Béjaïa, or Bougie. Béjaïa is today a mid-sized city in north-central Algeria, but at the time it was the western capital of the Hafsid dynasty. Its site had been occupied at least since Carthaginian times, but gained in importance as a port city after the Arab conquests. It became the capital of the 11th-12th century Hammadid dynasty and retained much of that prominence under the Almohads and then the Hafsids. In the late 12th century, a young Pisan boy spent a good chunk of his youth in Béjaïa with his merchant father and became interested in mathematics. His name was Leonardo Fibonacci, and later on he would introduce Hindu-Arabic numerals as well as the concepts of zero and the decimal point to Europe. No big deal.
The Hafsid dynasty was the first of the three successor dynasties to emerge from the collapse of the Almohad Caliphate in the mid 13th century. Unlike the Zayyanids, who had merely been regional governors in Tlemcen under the Almohads, and the Marinids, who had never been anything more than an enemy to the Almohads, the Hafsids had been part of the Almohad project from its earliest days as a religious revivalist movement. Unlike the Marinids and Zayyanids, the Hafsids emerged from the same Masmuda Amazigh background as Ibn Tumart and the Almohads. In fact, the dynasty could trace its ancestry to one of Ibn Tumart’s closest companions, Omar Abu Hafs al-Hentati, so it held a prominent position in the caliphate throughout its history.