Edinburgh has been a literary city since the Enlightenment and remains so — it was the first UNESCO City of Literature in 2004. The two writers most associated with the modern city are Ian Rankin and Irvine Welsh, who between them cover the respectable and the ragged ends of town.
Ian Rankin's "Rebus" series follows the police detective John Rebus through a couple of dozen novels' worth of crimes in modern Edinburgh. Rankin lives in the city and his Edinburgh is the real one — the pubs, the housing schemes, the stretches of the Old Town that the tour guides hurry past. Knots and Crosses is the first; Black and Blue and The Falls are particular high points. Rebus drinks at the Oxford Bar on Young Street, which is a real pub and worth a visit.
Irvine Welsh's "Trainspotting" is the other essential Edinburgh book — Leith in the late 1980s, told in fierce, funny demotic Scots. The film is famous; the book is sharper.
For the older city, Robert Louis Stevenson's "The Strange Case of Dr Jekyll and Mr Hyde" is set in London but powered by Stevenson's Edinburgh childhood — the split between the respectable New Town and the dark closes of the Old. Muriel Spark's "The Prime of Miss Jean Brodie" captures the Edinburgh of the 1930s through the Marcia Blaine School in Bruntsfield, and is as sly and clever a portrait of the city's manners as you will find.