On Tuesday, the National Theatre's celebrated production of A Streetcar Named Desire, Tennessee Williams's great play about madness and sexual appetite, will be broadcast live to cinemas.

On 1000 big screens, Stanley Kowalski will stalk and stomp and swelter, and his girlfriend Stella will try to control and love him, and fail, and the fragile Blanche Dubois will start to crumble and break until the only option left is the asylum. And it will all end with Blanche's famous, plaintive words to the men who have come to take her away: "Whoever you are, I have always depended on the kindness of strangers."

In the National's production, Blanche is played by the American actress Gillian Anderson, who said recently that she has always wanted to take on the part. And who can blame her? It is one of the greatest roles in one of the greatest plays of the 20th century (and since it was made famous by Vivien Leigh in the 1951 film version, has become a challenge for actresses, a kind of hurdle).

What is particularly interesting about the character is who she really represents. In the play, she is a genteel lady of the deep South, a teacher who once had money and still has her delusions. But she is something else as well, something more profound: she is a fictionalised version of Tennessee Williams; Blanche's frailties, faults and desires are Williams's frailties, faults and desires. In the words of Elia Kazan, the movie director and Williams's great collaborator and friend: "Tennessee Williams equals Blanche."

It is this idea that forms the core of John Lahr's new biography, Mad Pilgrimage Of The Flesh. Williams was, says Lahr, the most autobiographical of playwrights (in Williams's own words, the plays were "a picture of my own heart") and Blanche was the most autobiographical of all, the closest to his own reality. She was also a way for Williams to explore who he was (and who he wanted). In the play, Blanche, a penniless teacher draped in lace, is immediately attracted to Stanley, a brutish man in a blue collar, and Williams was the same: he was attracted to the Stanleys of this world - sailors, rough trade, the dangerous and the violent.

Lahr recounts one incident which best illustrates the similarities. It happened in 1943 when Williams was beaten up by sailors he had taken back to his hotel room. Later, in his diary, he asked why they had struck him ("what is our offence?") but at the same time he was excited and inspired by the violent encounter - he could see its potential. "Not that I like being struck," he wrote. He hated it, he said, but he could also appreciate the keenness of the emotional situation. It was material for art.

In his biography, Lahr explores the consequences of this process and how Williams used his experiences -sometimes violent, sometimes erotic, sometimes mad - to create his characters and situations. He turned his own delirium, says Lahr, into one of the 20th century's great chronicles of the brilliance and the barbarity of individualism. He was also a gay man writing at a time when he could not publicly be so, or write about being so, thus he used Blanche and his other great female characters - such as Maggie in Cat On A Hot Tin Roof - to write about the gay experience instead.

In fact, Lahr believes that Williams only wrote about women so often because he was obsessed with men and it was through female characters, in the 1940s and 1950s at least, that he could view the male. In the process, of course, he created something new for the 1950s: the first sighting on the American stage of a sexual man when Marlon Brando walked out as Stanley in the first stage production, and later the film. "When Marlon Brando appeared on stage in a torn, sweaty T-shirt," wrote Gore Vidal, "there was an earthquake."

Lahr, who is but one of many writers to devote a book to Williams, has always been at his best when he writes about these sexual experiences and desires; his great skill is to use sex as a way of uncovering the layers of a human. He did the same thing in Prick Up Your Ears, his fine biography of Joe Orton, and in Mad Pilgrimage Of The Flesh he does it again with Williams: he unpeels and picks and gouges, and the experience for the reader is intense, sometimes gory, sometimes titillating.

What makes Williams's sexual life particularly interesting is that there was a transformation at the heart of it. He grew up in a conventional household, under the influence of a grandfather who was a preacher but may also have been gay himself, and it meant that, in his early twenties, Williams was, in his own words, a little puritan. Then he discovered sex, and success discovered him, and the Puritanism was abandoned for what he called the trapeze of the flesh. He swung on it and unlearned his own repression.

In the 1940s, 1950s and 1960s, this unlearning process meant that Williams had a lot of fun: he was sustained by the act of loving but also the act of imagination - the creation of his plays. It was only when the act of imagination was no longer appreciated that Williams's life began to go wrong. In the 1970s and 1980s, there was a pincer movement, with the critics on the one side who had deserted him for new playwrights such as Pinter and Beckett and, on the other side, his gay audience who no longer seemed to have any patience for the allusions and hints of Williams's work when there was something much more direct on offer.

Williams's self-destructive reaction was to push harder for the success, and in recounting this period, Lahr draws his final and most disturbing parallel with Blanche. As his career went wrong, Williams characterised the pie chart of his life as 89% work or worry over work, 10% struggle against lunacy and 1% love for lover and friends, and when he took refuge in drink and drugs the final destination was the same as Blanche's: a mental institution.

Lahr does not spare any of the mess or the detail in describing what the last years were like for Williams (at the time, Life Magazine called the playwright a White Dwarf at the end of its life cycle). Williams himself also appeared to realise what was happening: the colourful lights that had sustained him since childhood, he said, had started to flicker. Describing this process means that the final section of Lahr's book is melancholic, but then aren't all life stories sad at the end? Lahr's theory, the blood of the book, is that Williams devoured himself to describe our pain and, in that sense, Lahr's book is the story of a great writer but also a warning to great writers: use your life to write and the writing may use up your life.