Unfortunately for Dodgson, the 21st century does not look kindly on a single man who is beguiled by seven-year-olds. Feminist critics have darkly suggested that Dodgson was a paedophile. They have condemned the beautiful photographs he took and objected to his objectification of the immature female body, and read all sorts of rapacious nonsense into the Alice books. At the other extreme, many of Dodgson's defenders have protested too much. They have attempted to argue that he was utterly without feelings for little girls. One of his early biographers wrote, "There is no evidence that he felt or inspired any pangs of tender passion", when of course there was an abundance of evidence that he did. His defenders tend to portray him as a shy, stuttering bachelor with a fondness for children that may as well have been a fondness for stamps or porcelain puppies.

Is it possible that neither view of him is correct - that he was neither the child molester nor the pure, white-haired reverend? It is possible that our crude categories, our black and white views of romantic feeling, cannot contain someone like Dodgson. It is almost impossible for us to contemplate a man who falls in love with little girls without wanting to put him in prison. The subtleties, for those of us still mired in the paranoias of the 20th century, are hard to grasp. When one thinks of a paedophile, one thinks of a lustful, over-the-top, drooling Nabokovian love, but that is not Lewis Carroll. His love was more delicate and tortured and elusive; his warmth, his strange, terrified passion, more intricate and complicated than anything encompassed by a single word.

Dodgson's affection for what he called his "child friends" was always mingled with a vague yearning. He wrote to one 10-year-old girl, "Extra thanks and kisses for the lock of hair. I have kissed it several times - for want of having you to kiss, you know, even hair is better than nothing." This is typical of his correspondence. He converted whatever his feelings were into the whimsical, quasi-romantic banter that eventually made its way into the Alice books. He wrote to one mother of a potential visit with her daughter, "And would it be de rigueur that there should be a third to dinner? Tête à tête is so much the nicest." There was a romantic intensity to the friendships that Dodgson struck up with children, a hint of hunger, of never quite getting enough. This was especially true of his relationship with Alice. There was always a sense that he wanted more of her. And yet, can we really blame him for that - as long as he didn't act on his feelings? If he turned himself inside out, turned the world inside out with his powerful imagination, in order to avoid them?

He was not alone in his obsession. The era seemed to breed a certain type of neurasthenic man who had a well-developed and intellectually complicated disdain for overt physicality and who found himself drawn to pre-teens. Take John Ruskin. He also fell under the spell of Alice, among other young girls he encountered. One particular street urchin whom he glimpsed in Italy made a big impression on him. It is one of the paradoxes of Victorian culture that the sentimentality, the frilly, sugar-sweet view of the child often coexisted with darker sexual urges; that they fed each other, and the squeamishness about sex led to a perverse attraction to anything innocent and pure. Children were safe, and in their safety, certain thoughts - dirty, sensual thoughts - were allowed to flourish.

It is almost impossible to claim that Dodgson was drawn to little girls on a purely spiritual plane. His deep aesthetic appreciation of their physical presence was too conspicuous. He wrote to Gertrude Thomson, an artist who was sketching girlish fairies and nymphs, "I confess I do not admire naked boys in pictures. They always seem... to need clothes, whereas one hardly sees why the lovely forms of girls should ever be covered up."

It's clear, then, that Dodgson had a submerged erotic fascination with the nubile female form. But what to make of it? What if he did love children, and in that love was a sexual element? What if he admired the bodies of little girls and never touched one? There is no doubt that he was tormented by what he called "the inclinations of my sinful heart". Even his mathematical writings were marked by his struggle. In the introduction to Curiosa Mathematica, Part II, he wrote that fixing one's mind on mathematics as one lay in bed could ward off "unholy thoughts, which torture with their hateful presence, the fancy that would fain be pure". Strong language for a book about trigonometry. The picture we get of is of a man afraid of his own dreams, struggling for command over himself. In one of his most charming analyses, the biographer Morton Cohen actually charted Dodgson's moments of greatest torment and insomnia in his diaries and found that they correlated to the days on which he saw Alice.

But Dodgson's response to any heightened agitation he felt with children was this: he sat with Alice in a boat gliding along the glittering river and made up stories, the more outlandish the better. His feelings rhymed and punned themselves into expression. He chatted her up with the manic energy of Wonderland. His frustration, his alienation, blossomed into the caterpillar at the hookah and Humpty Dumpty and the Mad Hatter. He channelled his devotion into a wild and lovely literary universe; his imagination so dangerous and inflamed, it fled the real world. He called the Alice books a "love-gift". And because this love is unrequited, because it is impossible, ethereal, because he cannot allow himself to fully feel it, there is a hint of sadness. As he puts it, "a shadow of a sigh" trembles through the story.

To me, there is a nobility in a self-restraint so forceful that it spews out stuttering tortoises and talking chess pieces rather than focus on the matter at hand. There is something touching about a man who fights the hardest fight in the world: his own desire. You can feel the loneliness on the page. You can the feel the longing in the photographs. You can witness the self-contempt in his diaries. How can one not feel sympathy for a man who writes in his diary, "I pray to God to give me a new heart", but is stuck, in spite of his astonishing powers of invention, his brilliance, his immortal wit, with the one he has.

He had impure thoughts, yes. What matters, in the end, is what he did with them.

· Katie Roiphe's novel about Lewis Carroll and Alice Liddell, Still She Haunts Me, is published by Review, RRP £10. To buy a copy for £8 plus UK p&p, call the Guardian books service on 0870 066 7979.