A compilation of aggadic (narrative) and halakhic (legal) midrash
While we speak often of "the Midrash," there is no single book with this title, but only a series of compilations composed and edited over the course of more than a millennium. These works are generally categorized as either halakhic (legal) or aggadic (narrative), though this dichotomy obscures the extent to which so-called halakhic midrashim also include narrative material and to which aggadic midrashim also contain legal material.
One of the works that best exemplifies this intermingling of legal and narrative material is Midrash Tanhuma, a collection of stories, discussions of specific laws, and rabbinic homilies, all connected with the five books of the Torah and named for Rabbi Tanhuma, the first character to appear in the collection. The compilation moves effortlessly between genres, reminding us of the interdependency within the Jewish tradition of halakha and aggadah.
Two types of midrashim, though not exclusive to Midrash Tanhuma, appear more frequently here than in other collections. These two genres are the petihta, a homiletic introduction to a section of the text; and midrash yelamdenu, a legal discourse based on the biblical text. The latter is so prevalent within Tanhuma that an alternate name for the book is Midrash Yelamdenu. Though some scholars believe that Tanhuma, comprising the narrative portions of the midrash, and Midrash Yelamdenu, consisting only of legal discussions, may once have been two separate books, the two names have been interchangeable since at least the middle ages.
The petihta, or opening (generally translated into English as "proem"), marks the beginning of a section of the Torah as divided for public synagogue reading. The divisions preserved by these petihtaot (plural of petihta) reflect the triennial cycle of synagogue readings prevalent in ancient Palestine, in which the Torah would be read in sequence over the course of three years. (In contrast, the triennial divisions used by many contemporary synagogues divide each parashah into thirds.)
The petihta begins with a verse from elsewhere in the Bible, most often from the books of Proverbs or Psalms. This verse prompts a discourse that eventually finds its way back to the first verse of the weekly Torah reading. For instance, a petihta introducing the first verse of the book of Exodus begins by quoting Psalms 48:11, "The praise of you, God, like your name, reaches to the ends of the earth."
The petihta continues with a discussion of names, identifying four types of people: those who, like God, have beautiful names and beautiful deeds; those with beautiful names and ugly deeds; those with ugly names and beautiful deeds; and those with ugly names and ugly deeds. After laying out these four categories, the text asserts that Jacob's children were beautiful both in name and deed, and then returns us to the first verse of Exodus, "These are the names of the children of Israel who went down to Egypt." A particular verse may have more than one petihta attached to it.