A chemistry student has been arrested for allegedly planning a gas attack against protesters opposed to a visit by Pope Benedict XVI, a Spanish police official said Wednesday.

The pontiff is due to arrive Thursday for a nearly four-day visit to celebrate World Youth Day, and a protest march is scheduled for Wednesday evening in Madrid.

A police official said the suspect arrested in Madrid on Tuesday is a 24-year-old Mexican student specializing in organic chemistry. She would not say whether investigators believe the man was actually capable of carrying out a gas attack, and did not know if the man actually had chemicals for an attack.

The Mexican Embassy identified the detainee as José Pérez Bautista and said he was from Puebla state, near Mexico City.

Police have 72 hours from the time of the arrest to take the detainee before a judge at the National Court for questioning or release him. A court official said he would appear before the judge Thursday at the earliest.

The court official — speaking on condition of anonymity in line with court policy — said the detainee had been making threats over the Internet against people in Spain opposed to the Pope's visit, and police who'd been monitoring his online activity ultimately decided to arrest him as the visit approached.

Police said in a statement released Tuesday night that officers who searched the detainee's apartment in a wealthy district of Madrid seized an external hard-drive and two notebooks with chemical equations that had nothing to do with his studies.

It said he tried to recruit people via the Internet to help him, and that a computer allegedly used for this purpose was among objects seized by police.

The statement said the man had planned to attack anti-Pope protesters with "suffocating gases" and other chemicals. But, it did not mention police having confiscated chemicals that could be used in an attack.

The police official spoke on condition of anonymity in line with police rules.

The statement said the suspect was in Madrid studying with Spain's top government research body, the Spanish National Research Council and his office there was searched. The council confirmed the arrest but gave no immediate details on the Mexican.

Church organizers say the papal visit is costing about $72 million to stage. Protesters complain the government is essentially spending taxpayer's money on the visit by granting tax breaks to corporate sponsors and perks such as discount subway and bus tickets for pilgrims.

The story is based on the Associated Press.