Preheat oven to 350 degrees. Butter a 9-inch-square metal baking pan, then line with parchment paper, leaving an overhang on all 4 sides. Pulse the flour, almonds, cocoa powder, cinnamon, salt and cayenne pepper, if using, in a food processor until the almonds are finely ground.
Beat butter and granulated sugar in a large bowl with a mixer until light and fluffy. Add the flour mixture and beat until just combined (the dough will be crumbly). Press the dough into the bottom of the prepared pan (you can cover the dough with plastic wrap and use the bottom of a measuring cup to even out).
Prick the dough all over with a fork, then use a sharp knife to cut it into 18 strips. Top with almonds, lightly pressing them in. Sprinkle with the raw sugar. Refrigerate until the dough is firm, about 10 minutes.
Bake until the shortbread is slightly puffed and firm, 30 to 35 minutes. Remove the pan from the oven and immediately retrace the strips with a knife; cool completely in the pan on a rack. Lift up the parchment paper to remove the shortbread from the pan, then separate into bars. Store in a airtight container up to 1 week.