OMAR GARCÍA CERVANTES, an aspiring novelist, was brought up in the state of Veracruz but moved to Mexico City 16 years ago. As a gay man, he is happier there than anywhere else. Mexico City has grown only more welcoming since he moved there. In November last year the mayor, Miguel Ángel Mancera, signed a declaration proclaiming its gay-friendliness. Gay marriage has been legal in the city since 2010; under a law passed in 2014, people can change their legal sex simply by applying to alter their birth records. Hate crimes against gays are almost unheard of, says Alejandro Brito of Letra S, a gay-rights activist group.

Outside the city, the climate is more forbidding. Fans of the national football team are wont to shout “puto” (“faggot”) at opposing goalkeepers. The Catholic church, the spiritual home of 80% of Mexicans, continues to denounce gay marriage as a threat to families. Its influence is especially strong in states north-west of the capital. A demonstration last year against gay marriage in Guadalajara, the second-largest city, attracted more than 50,000 people, says the organiser, an alliance of church groups and educational institutions.

Attitudes harden even a few miles outside Mexico City. Lorena Wolffer, an artist, noticed disapproving stares when she visited a hospital with her female partner recently. “We just turned to each other and said, ‘Of course, we’re in the state of Mexico,’” not the city, she recalls.

But there is progress. Last year the supreme court ruled that state laws preventing homosexuals from marrying violate constitutional protections against discrimination. Three of Mexico’s 32 states (Michoacán, Colima and Morelos) have recently passed laws permitting gay marriage, joining Mexico City, Campeche, Coahuila and Nayarit in a liberal group of seven. Four more allow gay marriage but have not passed laws sanctioning it.

In the 21 states that still forbid it, couples can now defy local laws by going to court; under the supreme court’s ruling, judges are obliged to give them permission to marry. In May this year Mexico’s president, Enrique Peña Nieto, proposed changing the constitution to make gay marriage legal throughout the country, though there is little prospect of that happening before the next presidential election in 2018.

The spread of gay rights has been accompanied by more reports of violence against homosexuals. The number of homophobic murders has jumped to 71 a year on average over the past decade from 50 a year during the previous ten years, according to Letra S. In June, in the northern town of Monclova, a lorry driver shot Jessica González Tovar and ran her over in the presence of her female partner.

But reports of more homophobic violence may be misleading. Letra S draws its data from newspaper reports, since the police do not report such crimes separately. The higher numbers may show that the press is reporting them more accurately, Letra S acknowledges. “There seems to be more homophobia,” says Nicolás Loza Otero of FLACSO, a university in Mexico City, “but I think there’s less.”

That hopeful assessment is probably right. Even the conservative areas north-west of Mexico City are changing. Fresnillo, a town in Zacatecas, elected Mexico’s first openly gay mayor, Benjamín Medrano, in 2013. Rubí Suárez Araujo became Mexico’s first transgender municipal councillor in Guanajuato in March this year. Sexual diversity is increasingly visible in Guadalajara, says María Martha Collignon of ITESO, a university there. A gay marriage takes place nearly every week.

Just under half of Mexicans support gay marriage, according to a poll conducted in 2013 and 2014 by the Pew Research Centre, a think-tank. But among those aged 18 to 34, 63% are in favour. Older Mexicans are becoming less censorious. “Parents aren’t saying they’re pleased at the news that their children are lesbian,” says Paulina Martínez of Metal Muses, a lesbian pressure group. “But they accept it more.” It will take years before Mexico becomes as tolerant as its capital, but gay people in the heartlands have grounds for hope.