Heat the butter and oil in a large frying pan over medium-low heat.
Add the sliced onions and cook gently, stirring regularly.
Sprinkle in the sugar to help the onions caramelise.
Continue cooking until the onions become deeply browned and jammy but not burnt, about 30 minutes.
Add the garlic and cook for another minute until fragrant.
Stir in the anchovies. They will gradually melt into the onions.
Add the tomato ketchup, if using, and cook for another 2-3 minutes.
Season with black pepper. Taste before adding any salt.
Cool completely before storing in a sterilised jar.