Measurement of jet fragmentation in 5.02 TeV proton–lead and proton–proton collisions with the ATLAS detector