For people who want to know why this should be done differently than, for example, a normal text. This is due to the difference between reliable teams and fragile teams. Headers do not allow fragile commands, so you need to specifically say that latex is reliable, for example.
This link explains this further, and this shows another alternative.
bastijn
source share