Singer, songwriter and satirist who eschewed the limelight to return to teaching mathematics

No one ever fought off the trappings of fame and success so fiercely as the singer, songwriter, and mathematician Tom Lehrer, who has died aged 97. He was an enigma. The songs that made him famous were mostly written and recorded before 1960, after which he returned to teaching mathematics and tried to behave as though no one had heard of him.

His songs were by turns gloriously vulgar, ludicrously macabre or ferociously political: I Got It from Agnes – “it” being a sexually transmitted disease; I Hold Your Hand in Mine, in which the held hand is no longer attached to a body; and We Will All Go Together When We Go, perhaps the best anti-nuclear weapons song ever written, praising “Universal bereavement / An inspiring achievement”.

Others were wonderfully clever games with words and music, including The Elements (1959), which names all the chemical elements, set to the tune of Gilbert and Sullivan’s I Am the Very Model of a Modern Major General.

He began writing songs as a graduate student at Harvard, where he had enrolled at 15 and had taken a first-class maths degree at 18. He sang them to his friends and soon people started asking him to perform at parties. “My songs spread slowly,” he said. “Like herpes, rather than Ebola.”