Paris, 1979. Doctor Who, in his goggle-eyed, scarf-wrapped fourth incarnation, is passing the time of day with the Countess Scarlioni. The countess is a glamorous art thief married to a charming man who, beneath his thin latex carapace, is actually a shivering mass of swamp-green alien linguine. The countess doesn't know this, but she is aware of what lurks in her husband's secret bookcase – the first draft of Hamlet.
The Doctor knows the manuscript is genuine because he recognises the handwriting – not Shakespeare's, but his own. "He sprained his wrist writing sonnets," he explains, launching into the play's most famous speech. But when he reaches the bit about taking arms against a sea of troubles, the Doctor looses a great splutter of disgust. "I told him that was a mixed metaphor," he exclaims. "And he would insist!"
Tom Baker will never play the Dane. On Thursday, however, one of his successors will be on the stage of the Courtyard Theatre in Stratford-upon-Avon, urging his too too solid flesh to melt. Two weekends ago, 10m people watched David Tennant bust a billion Daleks and tow the stolen planet Earth back to its rightful place in the universe. Now the actor is studying for no less hazardous a mission: to scrape the mould from the rotten state of Denmark. Some don't approve. When Tennant's casting was announced, Jonathan Miller issued a public snort about the "celebrity casting" of "that man from Doctor Who".
Unlike any actor who has preceded him in the role of the Doctor or the Prince of Denmark, David Tennant is both an accomplished Shakespearean (he has often turned out for the RSC) and a complete and utter Doctor Who fanboy fruitcake. Some of his forebears had a passing interest in Gallifreyan matters before they entered the Tardis. Some had dabbled with the Dane: Patrick Troughton was Player King to Olivier's Hamlet, Colin Baker was Laertes to Martin Jarvis's Hamlet, Christopher Eccleston was a creditable Hamlet for the West Yorkshire Playhouse in 2002. None, however, had what Tennant has – a long-term commitment to Shakespeare coupled with a spooky command of the arcana of Doctor Who. Should you ever meet him, do put this to the test and ask Tennant whether he recognises a genealogical relationship between the Cybermen, the Voord and the Fishmen of Kandalinga. You'll get a view. You'd only get a polite smile from Peter Davison.
So what might Tennant take from his experience of playing the Doctor that might help him in Elsinore? Gareth Roberts wrote last year's episode "The Shakespeare Code", in which the Swan of Avon helped the Doctor repel a cabal of evil Carrionite witches from the Globe Theatre, simultaneously saving the Earth and furnishing an idea for the opening scene of Macbeth. "The Doctor," Roberts reasons, "when presented with a dilemma, will often begin an exercise in philosophical self-examination. He's always thinking about the bigger picture. He believes there's a general standard of ethics across the universe. That sort of idea is very much in Hamlet's mind. He has the chance to kill Claudius at prayer but he can't do anything because he's worried about the afterlife."
Exhibit A in Roberts' argument is "Genesis of the Daleks" (1975). This story opens with the Doctor meeting the mist-shrouded figure of an elderly Time Lord, who charges him with the task of destroying the Dalek race at the moment of its birth. It ends with the Doctor wiring the baby mutants' incubation room with explosives, but refusing, at the last minute, tocomplete the circuit that will blow the chamber apart. "The Doctor can't make the decision because of a philosophical idea," notes Roberts. "He subscribes to the Ker-Plunk theory of time – that if you start pulling out straws eventually all the balls will fall down. He suspects that the universe might be a better place with the Daleks there for people to unite against."
Fiddlesticks, counters Dr Martin Wiggins, senior lecturer and fellow at the Shakespeare Institute at Stratford. The elderly Time Lord in "Genesis of the Daleks" is not the ghost of Old Hamlet, because he's clearly wearing the same outfit worn by Death in Ingmar Bergman's The Seventh Seal. And the Doctor's moment of indecision is not the prayer scene from Hamlet, it's a direct steal from The Brothers Karamazov.
Dr Wiggins is equally crushing when I pitch him my theory that "The Invasion of Time" (1978) – in which the Doctor feigns madness to prevent his home planet falling to a race of aliens with thick Ulster accents – is another version of Shakespeare's story. If you must go truffling for Hamlet in pre-2005 Doctor Who, he suggests, better to try "The Masque of Mandragora" (1976), in which a fizzing alien entity arrives in Italy to stop the Renaissance from happening. It has an inexperienced, intellectual prince, a usurping duke, and a debate about the conflict between science and religion that recalls Hamlet's musings on the nature of the supernatural world.
It's much more fruitful, he argues, to look for parallels in the Russell T Davies revival. This, Wiggins contends, might be read as "Hamlet backwards". "Hamlet is a character who thinks ethically, who considers the moral consequences of what he does," he says. "He moves away from a stymying sense of his own ethical responsibility and towards a more impulsive way of responding to the situation he's placed in. The way that Davies has conceived the character of Doctor Who is that he starts off as someone who, because he was involved in a war, is aggressive and wants to kill Daleks – but he changes over the series."
In a 2005 episode, Christopher Eccleston's Doctor discovers the last survivor of the Dalek species and is gripped by the desire to blast it into atoms. In the most recent episode, David Tennant offers sanctuary on board the Tardis to Davros, the desiccated being who created the Daleks. Something, clearly, has changed.
We should hardly be surprised to find the imprint of our national dramatist's most revered play upon one of the most voluminous discourses in post-war British culture. Forty-five years of Doctor Who television episodes, audio dramas, stage shows, books, webcasts, comic strips, short stories, feature films and sweet-cigarette cards have so far yielded six encounters with Shakespeare. The first was in 1966, when, sitting at the controls of a machine which allowed the operator to be a Peeping Tom upon any event in the history of the universe, one of his companions chose to spy upon the moment when Elizabeth I badgered the playwright into giving Falstaff his own show. Although the universe is a big place, it's hard to imagine that their paths will fail to cross again – simply because they are both such substantial figures in the culture.
That point was demonstrated to me last week at the press night of a new production of Six Characters in Search of an Author at the Chichester Festival Theatre. In this version, Pirandello's dizzying reflection on the occult power of the created literary being is given an extra twist with a scene in which the show's backers talk about the possibility of booking Patrick Stewart. It's impossible, they conclude: Stewart is spending the summer playing opposite David Tennant. "The Tennant Hamlet!" the producer exclaims. "I promised to take my daughter. She's a Doctor Who nut."
The Stratford production's swift sell-out suggests that the audience is anticipating a rare kind of cultural twofer: Shakespeare's most celebrated hero, performed by the actor who now gives life to television's most celebrated hero. And in the case of both parts, it's hard to be unaware that you are watching only the latest of a long line of interpreters. New Doctors must overwhelm or accommodate the shades of William Hartnell and Tom Baker just as new Hamlets must compete with the ghosts of Olivier, Gielgud and David Warner. Tennant has already performed one successful act of exorcism. He seems destined to complete a second. Unless, of course, he is suddenly floored by that mixed metaphor waiting for him in his most famous speech.
Hamlet is at the Courtyard Theatre, Stratford-upon-Avon, from Thursday (0844 800 1110, www.rsc.org.uk)