Caramelise the onions (40 min): Melt the butter with the olive oil in a large frying pan over medium-low heat. Add the sliced onions and 1 teaspoon salt, 1/4 cup water plus extra for seasoning. Cook, stirring often, until deep golden and jammy.
Deglaze (3 min): Add the garlic and thyme and cook for 1 minute. Pour in the white wine (or sherry) and scrape up the browned bits from the bottom of the pan. Simmer until almost evaporated, then remove from the heat.
Make the cream mix (5 min): Warm the cream, beef stock, and black pepper in a small saucepan until steaming but not boiling. Preheat the oven to 180°C fan-forced and grease a 2 L baking dish.
Slice the potatoes: Slice the potatoes about 3 mm thick using a mandoline or a sharp knife. Don't rinse them, as the starch helps thicken the sauce. Toss the slices with the warm cream mix.
Layer: Place one third of the sauce at the bottom of the baking pan. Dip the potato slices into the pot and then layer the potatoes on top of the sauce in the baking pan (ideally, you want sauce in between the slices). Add a layer of the Gruyère then the remaining sauce on top. Sprinkle with the parmesan.
Bake covered (40 min): Cover tightly with foil and bake until the potatoes are nearly tender.
Bake uncovered (25 min): Remove the foil and bake until bubbling and deeply golden on top.
Rest (10 min): Rest for 10 minutes before serving so the gratin sets and slices cleanly.