Older Mexicans can still remember when scores of priests were hunted down and killed, and just seven years ago priests were still forbidden to vote, walk the streets in clerical garb or hold open-air Masses.
For decades, Mexican schoolchildren were taught that the Catholic Church had plagued their country for centuries by burning Indians and fanning the flames of civil war. But at least 90 percent of Mexicans are Catholic, and that fact moved the government in 1992 to establish diplomatic ties with the Vatican and improve church-state relations.
Pope John Paul II's visit to Mexico comes at a time when those relations have rarely been better, although analysts say tensions persist over strife-torn Chiapas state, from which priests have been expelled, and over government policies on education, health and an increasingly market-oriented economy.
The harrowing scenes of Mexico's 1920s "cristero" war over strict anti-clerical laws prompted British author Graham Greene to write his classic novel "The Power and the Glory" after visiting Tabasco state on the Gulf of Mexico.
The victors of Mexico's 1910-17 revolution were in no mood to tolerate dissent after years of infighting that cost 1 million lives. Then-President Plutarco Elias Calles, founder of Mexico's long-ruling Institutional Revolutionary Party, upped the ante by insisting that the church come under the firm control of the all-powerful state.
Church leaders replied by refusing to hold services, and religious peasants rose up in arms around the country to the war cry "Viva Cristo Rey" ("Long Live Christ the King").
Repression was swift and brutal. The governor of Tabasco changed the state capital's name from San Juan Bautista (St. John the Baptist) to Villahermosa, turned the cathedral into a sports arena and forced priests to marry concubines.
Widespread devastation in western Jalisco state later provided the setting for one of Mexico's most famous novels, "Pedro Paramo," about a village where every inhabitant is dead -- a scene author Juan Rulfo had witnessed as a child.
"The conflicts were ended on terms highly favorable to the federal government and very unfavorable to the church. In that sense, the Salinas reforms of 1992 were very important in terms of putting on a more normal diplomatic footing," Kevin Middlebrook of the Center for U.S.-Mexican Studies at the University of California at San Diego said, referring to then-President Carlos Salinas de Gortari.
The Catholic Church has been linked with Mexico as indelibly as the Spanish language since priests accompanied the conquistadors 500 years ago, and the church's role has been controversial ever since.
"There can be no doubt that the Catholic Church in Mexico has been a relevant institution, fundamental in explaining to us the development of the Mexican nation," former President Miguel de la Madrid said at a recent news conference.
Church and state clashed repeatedly after Mexico won its independence in 1821 as free-market liberals in the government fought pro-church conservatives, especially over the 1857 constitution that scrapped the prominent role in national affairs the church had enjoyed since the Spanish conquest.
The 1857 constitution triggered a three-year civil war that liberals won, but conservatives retaliated by inviting Austrian Archduke Maximilian to become Mexico's emperor in 1862, backed by invading French forces. That sparked another civil war that ended with expulsion of the French and Maximilian's execution in 1867, and authorities have sidelined the church ever since.
"Since the middle of the last century, Mexico has supported a lay state, which to some extent the church has seen as anti-Catholicism," political analyst Roberto Blum of the CIDAC think-tank told Reuters.
On a formal level, relations between Mexico and the Vatican are friendly, and current President Ernesto Zedillo is the first Mexican head of state to have visited a pope in Rome.
"There is a respectful, serious and formal relationship between the state and the Vatican, and diplomatic relations with the Holy See are also cordial and respectful," said Ricardo Ampudia, who was head of protocol at the Foreign Ministry when Mexico established diplomatic links with the Vatican in 1992.
But Blum said Mexico had done little more than nod to reality by recognizing the Vatican, and friction remained.
"The local church feels it doesn't have the rights its very nature and function demand, like the right to educate, the right to communicate," he said.
The church is also at odds with government policies on free-market economics and birth control and official anti-AIDS campaigns that promote using condoms, he said.
Another sore point is the 1993 killing of Cardinal Juan Jesus Posadas, who investigators said was gunned down by hired killers who mistook him for a rival drug lord.
"The church is not satisfied with the explanation that the attorney general's office gave," Blum said.