Spanish Prime Minister Mariano Rajoy | Pablo Blazquez Dominguez/Getty Images Spain to Scotland: You’re not special Madrid won’t let an independent Scotland stay in the EU, but won’t necessarily block any application to join either.

MADRID — Spain will not agree to an independent Scotland staying in the European Union after Brexit — at least, not until it applies to join on its own merits.

As the governments in London and Edinburgh prepare their battle plans ahead of a potential second Scottish independence referendum, both are paying careful attention to what happens in Madrid. Spain has long been the most vocal opponent within the EU to any kind of separate deal for an independent Scotland because of fears that allowing such an arrangement would encourage Catalonia's bid for independence from Spain.

To judge by the views of senior MPs and government officials in Madrid interviewed for this article, neither U.K. Prime Minister Theresa May nor Scottish First Minister Nicola Sturgeon is likely to be entirely happy — or disappointed — with the noises coming from the Spanish capital.

For the SNP, there is no getting away from it: Any hope in Holyrood that Spain might acquiesce to an independent Scotland remaining in the EU in the U.K.'s place despite Brexit is a non-starter.

But Spain’s stance is not as hard-line as the U.K. prime minister’s closest advisers insist. One senior government official familiar with May’s thinking said there was “no way on earth” Spain would ever accept an independent Scotland into the EU.

According to senior figures in the Madrid government, Spain is not saying it will indefinitely block an independent Scotland rejoining the EU but neither has it agreed this might be possible.

“Spain supports the territorial integrity of the U.K. and doesn’t encourage secessions or divisions in any of the member states" — Foreign Minister Alfonso Dastis

The conservative government of Prime Minister Mariano Rajoy simply insists that, were it to become independent, Scotland must apply to join like everybody else. Any decision on whether to veto a Scottish application to join the EU as an independent country will be taken at a later date.

Pandora's Box

In the upcoming Brexit negotiations, Spain is advocating a hard EU line against Sturgeon's Scottish National Party to stop their separatist cause becoming a blueprint for Catalan pro-independence forces.

Rajoy considers the issue a priority in the Brexit negotiations, and his goal, which is backed by the main opposition Socialists, is to avoid any formula by which Scotland can remain in the European Union — either as part of the U.K. or as an independent country.

“Spain supports the territorial integrity of the U.K. and doesn’t encourage secessions or divisions in any of the member states," Foreign Minister Alfonso Dastis said last week after Sturgeon announced her intention to hold a new referendum on independence from the U.K. "We prefer that things continue the way they are.”

Scotland, Dastis said, “would have to join the queue, meet the requirements, go through the well-known negotiations and the outcome will be whatever those negotiations produce.”

The government in the northeastern region of Catalonia is controlled by pro-independence forces, who have committed to organizing a referendum on secession from Spain before October — a vote that Madrid and the country's courts consider illegal.

For Scotland to leave the U.K. but remain within the EU is exactly the kind of precedent Madrid wants to avoid as it could encourage Catalan separatists, who are paying equally close attention to the Scottish case and who have claimed that Catalonia may be able to leave Spain without leaving the EU.

When asked on Tuesday whether Catalonia could remain in the EU if the region seceded from Spain, former Catalan president Artur Mas, who has just been banned from public office for two years for organizing an illegal independence vote in 2014, said the Scottish case might be instructive. “Let’s see what happens,” he said.

Government officials and sources in Rajoy’s Popular Party (PP) confirmed that Spain has no sympathy for the independent-minded Scots and will reject any agreement by which Scotland could enjoy EU benefits. “Out is out,” said one official in Moncloa, the Spanish government complex in Madrid.

A senior source in the PP leadership said the Scottish question is high on the agenda, trumping even economic issues that may arise during the Brexit negotiations.

“If Scotland could celebrate a referendum before Brexit, could it inherit the British chair in the EU? The Spanish answer is No. Scotland must first become an independent country — if it wants to — and then start an application to join the EU with the same conditions as Serbia, for example,” said Esteban González Pons, an MEP for the PP.

Ignacio Sánchez Amor, a speaker on foreign affairs from the opposition Socialists, backed Dastis’ position, arguing that granting Scotland special access would be opening a Pandora's Box of demands across Europe. “Everyone has some sort of trouble,” he said, adding that the EU should build “a firewall” against any secessionist demands.

Toying with a veto

Could Spain veto an independent Scotland from joining the EU? González Pons said Madrid won’t do that but other sources said the decision hasn’t been taken yet, suggesting that the Spanish position will depend on the Catalan situation when, and if, an independent Scotland applies to join the EU.

“The Spanish government is projecting its own internal phantoms in third countries and different situations” — Jordi Xuclà, MP for the Catalan European Democratic Party

Beyond a veto, the country can find other, more discreet ways, to try to block Scottish access to the Union.

A member of parliament from the PP said a possible Scottish application to rejoin the EU could take years to process, and suggested that Scotland may not meet EU requirements in terms of, for example, currency or borders. “The only ones who don’t seem to be getting it are the Scottish National Party,” he said.

Ignacio Molina, a senior analyst at the Instituto Elcano think tank, said he wouldn't have advised such a rigid line against the Scottish separatists, as some in Brussels view Europhile Scotland with sympathetic eyes.

According to Molina, Spain should've simply let the U.K. deal with the issue and wait to see if London proposes any kind of special solution for Scotland.

Some pro-independence politicians dismiss the connection between the Scottish case and Catalonia.

“The Spanish government is projecting its own internal phantoms in third countries and different situations,” said Jordi Xuclà, an MP for the Catalan European Democratic Party, which supports Catalan independence.

A spokesperson for the Scottish National Party (SNP) said: "There is a well of goodwill in the EU for the position Scotland currently finds itself in.

"The SNP’s longstanding policy and commitment has been to membership of the European Union. That remains our position.

"We want the people of Scotland to have an informed choice — so we will set out well before any referendum — how Scotland’s relationship with Europe will be secured."