Crime novelist Ian Rankin has gifted his literary archive to the nation.

The writer has donated around 50 boxes of material – taking up more than 21ft of shelving – to the National Library of Scotland in Edinburgh.

The archive, which spans more than 45 years, includes typescripts of manuscripts with handwritten annotations and notes by the Scot.

Also included is correspondence with literary figures such as JK Rowling, Iain Banks, Ruth Rendell, Val McDermid and Jilly Cooper, as well as figures from the worlds of culture and politics.

The material dates from 1972 to 2018 and has been described by Rankin as “a pretty complete author’s life, late-20th century-style”.

Ian Rankin archive
Around 50 boxes of material make up the archive (National Library of Scotland/PA)

He said: “I remember that in my first week as a postgraduate student, we were given a tour of the National Library of Scotland, including access to the basement levels.

“Those vaulted underground corridors would reappear in the climactic scenes of my first Rebus novel.

“The library has seemed like a friend ever since, so it seems fitting – as well as a thrill and an honour – that my archive should find a permanent home there.”

The library said it will recruit a curator to catalogue and promote the Ian Rankin archive.

National librarian Dr John Scally has described the archive as “comprehensive, fascinating (and) in-depth”.

Ian Rankin archive
The NLS has welcomed the archive (National Library of Scotland/PA)

He said: “Ian Rankin is a well-known face to us here at the National Library. We knew him when he was researching Muriel Spark as part of his PhD, and we knew him when he penned his first novels here in our very reading rooms.

“Little did we know then just how successful he was to become, and that in time, his archive would be as gratefully received as Spark’s.

“It will be preserved into perpetuity alongside other Scottish literary giants.

“Rankin’s main protagonist, John Rebus, has walked George IV Bridge many times, and frequently visited this very library while researching cases.

“We are honoured to be a character in the Rebus novels alongside the city of Edinburgh, and we feel this is the rightful home for Ian’s archive.

“Because of his generosity, readers will be able to gain insight into the creative process of this wonderful writer.”