The author of the bestseller Rebus novels says the death of his mother when he was just 19 may have led him to his most famous character.
In a wide-ranging interview with BBC Scotland News, Sir Ian Rankin revealed that his mother, Isobel, became ill just two weeks after he left the family home in Fife to study at the University of Edinburgh.
She died just 10 months later, having never received a formal diagnosis.
“It was a tough time and the stuff I was writing got very dark as a result of that and maybe that was the start of the journey that would lead to me writing quite dark police novels about Edinburgh,” he said.
While his mother was ill, Sir Ian had to split his time between his hometown and his new life in Edinburgh where, by his own admission, he was “pretending to be Bohemian”.
“I was smoking Gauloises cigarettes and reciting bad poetry that I wrote and then I would jump on the train and go back to Cardenden and watch my mum deteriorating,” he said.
His writing helped him deal with her death.
“Humanity seems a wee bit bleak to you when that sort of stuff happens and you think where is God in all this, nowhere to be seen,” he said.
“[With crime fiction] you are looking at the human condition, you’re trying to answer some very big questions about how the way the world is and the way human beings are so it is possible that my mum dying got me thinking in those terms.”
The father-of-two remembers his mother, who grew up in Bradford, as a “lovely wee mum” who worked in a school canteen and then a chicken factory.
“She was a great cook, a proper Yorkshire cook. She made the best rice pudding with skin on the top in the oven. She did the best Yorkshire puddings,” he said.
His dad, Jim, died 10 years later. He saw his son become a published author but didn’t live long enough to see him become the bestseller he is today.
Now aged 64, the Edinburgh author has sold more than 35 million copies of his John Rebus series and is about to release his 25th book, Midnight and Blue.
But he has no plans to retire.
He uses his writing to make sense of the world, and when it’s going well “it’s really good fun”.
Warning: The next section contains spoilers for Ian Rankin’s new novel
He gets a buzz when he gets a great idea and then he wants people to read it.
But the self-proclaimed perfectionist says it then “starts to slip away” from him and he has to write another book.
However, he does view his latest book, Midnight and Blue, which sees Rebus convicted and sent to Saughton Prison, as one of his best yet.
He had thought his previous Rebus novel, A Heart Full of Headstones, would be the last as it ended on a “lovely clifftop ending”, with the former detective about to be sentenced.
But his fans disagreed and said they needed to know what happened next.
“So I’ve suddenly got an ex-detective in Edinburgh Prison (also known as Saughton Prison) surrounded by people who hate him because he is an ex-cop,” he said.
As part of his research, he spent a day in the real-life prison.
His Rebus series has been translated into 36 languages and he has been knighted for services to literature and charity.
“I am living the dream but it doesn’t make the books any easier to write,” he said.
“I was under the impression the more you wrote the easier it would be but it seems to get harder as you get older.”
However, Sir Ian has never had a problem with being motivated and he attributes this drive to his working-class background.
“I wanted to prove to the world that although I had come from a background where there wasn’t much that I was good at something,” he said.
Now he has proved himself, makes him “feel terrific”, he added.
But he is unhappy with the prospect of people being able to use artificial intelligence to write books for them.
“The computer can’t write it, it’s just stealing from other people. It scans all available texts in existence and uses them to crib the story together,” he said.
“It’s a mash-up of other people’s ideas.”
Sir Ian has seen an AI book “in the style of Ian Rankin” but said it was “rubbish”.
“I think the human being is the most extraordinary creation and letting AI do everything for us is going to make us less extraordinary,” he said.
So what is left for Sir Ian, who still loves a weekly drink in Edinburgh’s Oxford Bar?
“I’m not going to give up drinking, I think it’s delicious,” he said.
Instead he harbours hopes of one day making it on to one of former President Obama’s reading lists, which can boost an author’s profile and sales.
“I would love Barack Obama to read my books,” he said. “That is how you crack America and so far I haven’t had much luck with that.”