TSX today: Broad-based gains narrowly offset losses in energy and materials