IN RECENT months, despite coup threats, economic crisis, a heart scare and incessant vilification in the press, Asif Ali Zardari, Pakistan's president, has never appeared in public without one constant companion: a stubborn, face-splitting grin. He seems not to have much to smile about. The coalition led by his Pakistan People's Party (PPP) is just over a year away from the end of its five-year term. But you could get long odds in Islamabad for a bet on its getting there. Like any civilian government in Pakistan, it survives only so long as the army allows it to, and the army would like to see the back of it. That does not necessarily mean, however, that a coup is looming. There is more than one way to skin a civilian government.

Times have changed since Zulfikar Ali Bhutto, the country's first elected leader (and the last to serve a full term in office) was overthrown by a coup in 1977 and later hanged. The pattern set in a more recent phase of democracy, in the 1990s, was to topple governments through legal or constitutional intrigue. Three, including two led by Mr Zardari's late wife, Benazir Bhutto, fell in that way before a fourth tried to get rid of the army chief, Pervez Musharraf, in 1999, leaving the affronted general no option but to retaliate with an old-fashioned coup.

Even though the PPP's victory in an election in 2008 has led to an unusually long stint under Mr Zardari and his prime minister, Yousaf Raza Gilani, their sway has hardly been smooth or unchallenged. From the outset their coalition has been engaged in a chaotic tussle for power with the combined forces of the army and the judiciary. This tussle is reaching its climax for two reasons: one letter and one memo.

The letter is one the Supreme Court insists the government write to the Swiss authorities asking them to reopen a money-laundering case against Mr Zardari, despite his presidential immunity. Ever since it was first asked, in 2009, to send the letter, the government has refused. This week the Supreme Court began contempt proceedings against Mr Gilani, who would be disqualified from office if convicted of a crime. Hauled before the court on January 19th, he brazened it out, insisting there was no case to answer, since the president “has complete immunity inside and outside the country.” The hearing resumes on February 1st.

The memo is one sent anonymously in May to the American top brass, soon after Osama bin Laden had been located and killed a stone's-throw from an elite military academy in the Pakistani town of Abbottabad. Purporting to reflect the views of the highest levels of the Pakistani government, it asked for American help in reining in the army, humiliated by the bin Laden episode and possibly contemplating a coup. The government denies any role in “memogate”. But rather than use the opportunity to profess its loyalty to its civilian masters, the army has used the scandal to unsettle yet more a government it now sees as intolerably treacherous as well as irredeemably corrupt.

However, the army is busy fighting an Islamist insurgency in the north-west, does not want responsibility for Pakistan's sickly economy, and recalls how unpopular it was towards the end of Mr Musharraf's eight-year rule. Moreover, after the Arab spring, renewed military dictatorship in Pakistan would look decidedly bad. Nor is it obvious how, constitutionally, to install an unelected “technocratic” caretaker government that might give military rule a civilian glow. So the army has reverted to the usual Plan B, the “soft coup”: the hope that the courts or parliament will somehow oust the PPP, and that a more malleable civilian government will emerge. Concentrating minds is the (indirect) election to the Senate scheduled for the beginning of March. The PPP will gain a majority in the upper house, enabling it to block legislation for years to come.

The court's action against Mr Gilani brings these tensions to a head. If it orders his arrest, the police, who answer to the government, might not obey. If the court then asks the army to detain him, its action might look indistinguishable from a hard coup. Earlier this week Mr Gilani had called a parliamentary vote that he won easily, in support of “democracy”—in effect a vote of confidence. He seems almost to be daring the army to take him on.

For its part, the army seems to be challenging the PPP to take the initiative and even perhaps fire the army chief, General Ashfaq Kayani. But the PPP has decided that if it must lose power, it must be thrown out and be the victim. “Politics is a game of nerves,” says Nayyar Bokhari, a senator and senior PPP member. So far that nerve has held remarkably well, as Mr Zardari has at every turn outsmarted his enemies in the opposition, the army and the courts.

The tracks of whose tears?

That is in part because they seem muddled. The army wants Mr Zardari out, but not to be replaced by the opposition leader, Nawaz Sharif, who is these days a fierce critic of the generals. For his part, Mr Sharif does not want to see democracy itself derailed. But this week he voted against the “pro-democracy” resolution. Waiting for the election due next year might create further momentum behind the campaign of Imran Khan, a cricketer-turned-politician who is suddenly wildly popular in quarters viewed by Mr Sharif as his power base. So he would like the election brought forward.

When the election is held, it will probably result in another fractured coalition, with the army's influence as strong or stronger than now. The PPP is right to warn that democracy is at stake in the recent shenanigans. But it has done democracy a huge disservice during four years when its members lined their pockets, while displaying utter indifference to the misery faced by many Pakistanis. This winter households are suffering shortages of electricity, gas and even water, and food inflation is running at an annual rate of some 20%. Mr Zardari's grin looks out of place.

Economist.com/blogs/banyan