John Mcdougall/Agence France-Presse

“Some men like Jack/ and some like Jill; / I’m glad I like them both; but still…/ In the strict ranks/ of Gay and Straight/ What is my status?/ Stray? or Great?”

When Vikram Seth wrote “Dubious” many years ago, he may not have realized how long his poem would live. “Dubious” has become an anthem for Indians unwilling to be straitjacketed into heterosexuality, unwilling to accept the argument often put forward that being homosexual, lesbian, transgendered or transsexual is against Indian culture.

Seth had a long line of predecessors, as the scholar Devdutt Patnaik and the academics Saleem Kidwai and Ruth Vanita have noted. The “Markandeya Purana” carries the story of Avikshita, the son of a king who refused to marry because he believed he was a woman.

Gender was fluid, for yakshas and humans alike, in ancient and medieval Indian culture. The Mahabharata famously tells the story of Amba, the princess who was abducted by Bhishma but rejected by the warrior, who had taken a vow of celibacy. Praying to avenge the insult, Amba is reborn as Shikhandini, daughter to King Dhrupada, and then prays for a further transformation into Shikhandi — as a man, she can fight Bhishma, and becomes the cause of his death on the battlefield.

And the story of Teeja and Beeja still resonates in Rajasthan folklore. In a beautifully crafted version by Vijaidan Detha, Teeja and Beeja, two women, are inadvertently promised to one another in marriage by their fathers. (Beeja is brought up as a boy, married as a “man” to Teeja; they are happy together until Teeja suggests that she return to dressing as a woman. Driven out by the villagers, they pray to benevolent ghosts, and Beeja is turned into a man. But while this transformation is more socially acceptable, Teeja hates her new husband’s bullying and runs away. The story ends with the two living together as women, in the forest with the ghosts, safely away from the villagers.)

Ismat Chughtai’s “Lihaf” (The Quilt), was the subject of an obscenity trial in the 1940s, for her delicate evocation of the relationship between two women. It was much later, in the 1980s and 1990s, that contemporary Indian writers picked up from where Chughtai had left off. Vijay Tendulkar’s Marathi play, “Mitrachi Ghoshta,” was considered revolutionary for the 1980s because it had a lesbian protagonist — though it had a tragically conservative ending by today’s standards, where the protagonist commits suicide out of despair. Mr. Seth’s “The Golden Gate,” written in verse, contrasted two Californian couples — John and Liz, and Phil and Ed — both trying to find their way to love in elegantly turned rhymes.

Mahesh Dattani’s explorations of gender roles led to the sensitive “Bravely Fought The Queen,” where a married man, not out of the closet, grapples with his need for relationships with men. Seven years later, Mr. Dattani’s “On A Muggy Night in Mumbai” explored denial more deeply. Kamlesh tries to hide from his sister the fact that he had a relationship with the man she’s dating; his former boyfriend struggles with his own denial.

Mr. Dattani’s plays are especially poignant when you contrast their protagonist’s battles with being silenced to the frank lust and love expressed by Babur in his memoirs, for a youth called (aptly) Baburi. “One day, during that time of desire and passion when I was going with companions along a lane and suddenly met him face to face, I got into such a state of confusion that I almost went right off. To look straight at him or to put words together was impossible…” writes the man who would become emperor of India. Babur was married at the time, and had expressed an almost equal passion for his young wife — both loves were natural, in his eyes and the eyes of his companions.

An early — and funny — contemporary memoir was Firdaus Kanga’s “Trying to Grow,” written in 1990. Based on his own life, Mr. Kanga’s book told the story of a Parsi boy called Darius, nicknamed Brit because his bones are so fragile. (Kanga has osteogenesis imperfecta.) Darius finds love much later in his life. As Mr. Kanga wrote: “In all the time I was growing up I had never heard anybody talk about homosexuality. I certainly knew no gay men, except in the sublime stories I found and read — those by James Baldwin, E M Forster and Iris Murdoch.”

By 2003, R Raj Rao’s novel, “The Boyfriend” had an increasingly self-aware, assertive audience, even though the police could still use creaking, colonial laws to prosecute and homosexual men in India. Over the next few years, writers like Neel Mukherjee (“A Life Apart”) and Rahul Mehta (“Quarantine”) would explore the complexities and nuances of gay relationships in their writing with the same confidence that they explored being outsiders in either India or England, or dissected the workings of the Indian family. And there were first-person narratives too, such as Bindumadhav Khire’s “Partner” in 2005, an account in Marathi of growing up gay in middle-class Pune.

In her 2010 book, “Leaving India: My Family’s Journey From Five Villages to Five Continents,” Minal Hajratwala writes: “I have come to understand that queerness is a migration as momentous as any other, a journey from one world to the next … I am the only lesbian, and the only writer, in the recorded history of our clan.” But she is also part of a larger clan, one that has been recording its history, stray, great and in-between, for centuries in India.