You will need a heavy skillet with a diameter or 9 to 10 inches (Dorie uses a cast-iron skillet; smaller is better than larger).
Choose a skillet with a handle that can go under the broiler (if you are not sure, wrap the handle in foil).
Pour about 2 tablespoons oil into the skillet and warm it over medium heat.
Add the potatoes and onion, garlic and rosemary if using; turn the ingredients around until they glisten with oil.
Season with salt and pepper; decrease the heat and cook slowly until the potatoes are golden and cooked through, about 20 minutes; you should be able to pierce the potatoes easily with the tip of a knife.
Discard the garlic and rosemary and transfer the potatoes and onion to a bowl.
Carefully wipe the skillet with a paper towel (if anything has stuck to the bottom of the pan, you should wash it--you need a clean surface so the tortilla will unmold easily).
Position broiler rack so that when you slide the skillet onto it, the pan will be about 6 inches from the heat source; preheat broiler.
In a big bowl, beat the eggs with salt and pepper to taste and the cayenne, then stir in the potatoes and onion.
Put the skillet over med-high heat and pour in about 1 1/2 tablespoons oil.
When the oil is hot, add the eggs and potatoes to the pan.
Immediately lower the heat, and let the eggs cook, undisturbed, for about 2 minutes.
Run a silicone spatula or a table knife around the edges of the pan to release the tortilla, then cover the pan and cook slowly for another 8-10 minutes, or until the top is almost set--there will be a circle of liquid or jiggly egg at the center.
Every couple of minutes, run your spatula around the sides of the pan and just under the tortilla to keep it from sticking.
Slide the pan under the broiler and cook until the top of the tortilla is set; check it after 1 minute, and then keep checking--it can go fast.
Transfer the tortilla to a serving platter and allow it to cool to room temperature before cutting and serving it.