text: He was born in Edinburgh the only child of David Swan, engineer, and his wife, Janet Smith. Janet was the daughter of Thomas Smith, lighthouse engineer. Her sister was married to the famous lighthouse engineer, Robert Stevenson. He was privately educated at home, 7 Union Street, and appears to have been both lonely and unhappy. His father died in 1821 when he was only three. His mother took in lodgers to make ends meet, including at one point Thomas Carlyle. William's only childhood friend is said to have been his cousin, Thomas Stevenson (father of Robert Louis Stevenson).
  At 17 he was sent to Edinburgh University to study divinity. He "came out" during the Disruption of 1843 and became an active member of the Free Church, teaching mathematics and physics at the Free Church Normal School. From there he move to teach the same subjects at the Scottish Naval and Military Academy in Edinburgh.
  In 1848 he was elected a fellow of the Royal Society of Edinburgh his proposer being Philip Kelland. He served as Secretary to the society 1858-59. In the 1850s "William Swan, teacher of mathematics" was living at 4 Duke Street in the New Town, renamed Dublin Street in the 1920s.
  In 1856, Swan applied to join the faculty at Marischal College, but was passed over in favor of James Clerk Maxwell. Swan subsequently joined the Scottish Naval and Military Academy, where in 1857 he demonstrated that Fraunhofers D-line in the spectrum of the Sun was caused by the presence of sodium; in this respect, he is sometimes credited as having inspired Gustav Kirchhoffs research into the same issue.
  In 1859, he joined the faculty of Saint Andrews University, where he was a professor of natural philosophy until 1880.
  He was awarded two honorary doctorates (LLD): firstly from Edinburgh University in 1869, secondly from St Andrews University in 1886.
  He died of heart disease at his wife's country house of Ardchapel in Shandon in western Scotland.
  He is buried with his wife Georgina (who pre-deceased him) in Warriston Cemetery in northern Edinburgh. The grave lies in the narrow walled area between the main cemetery and the Water of Leith Walkway (in the south-east corner of the main cemetery.