The track is also stressed, ie stretched, so that as it expands with the temperature it still remains under tension. The level of stressing is changed as the ambient and expected temperature changes.
On the London Underground the PPPs, ie Metronet and Tubelines, are supposed to keep an eye on the weather and set the correct tension while the system is closed overnight. Some of the problems the Tube system has when it gets hot or cold have been when the PPPs haven't done this pre-tensioning properly and the track can't react correctly to the weather.