NEW YORK — President Trump had just begun to speak on an outdoor stage here at Madison Square Park in front of a couple hundred military veterans when the whistles and catcalls could be heard from beyond the security perimeter where crowds had gathered, along with a chant: “Lock him up!”

High above, in the windows of the tall buildings overlooking the park, a handful of makeshift signs were also visible to the naked eye: “Impeach” and “Dump Trump.”

If Trump had hoped to kick off his hometown’s annual Veterans Day parade with an apolitical tribute to the armed forces, he instead was treated to another reminder that virtually every one of his public appearances has turned into a referendum on his presidency amid the mounting impeachment inquiry by House Democrats.

From loud boos at Nationals Park in Washington last month to a huge ovation at a college-football game in Tuscaloosa, Ala., this past weekend, Trump has faced a real-time voice vote from the American electorate, with nearly a year to go before ballots are cast on Election Day.

President Trump was met with loud boos on Oct. 27 when he was introduced at Game 5 of the World Series at Nationals Park. (The Washington Post)

For Trump — who has sought to provoke and exploit the nation’s cultural divisions to maintain allegiance from his conservative base — the demonstrations have prompted a dilemma as he seeks to chart a course to a second term. As he attempts to make a case for reelection, the president has been eager to demonstrate broad support, but the public displays of antipathy threaten to undermine that narrative in blunt and potentially embarrassing ways.

After the president’s appearance at Game 5 of the World Series, video clips went viral showing of much of the hometown Washington crowd jeering as Trump was introduced.

“It’s an indication of just how deeply polarizing President Trump is that he has to kind of carefully cherry-pick stadiums or universities or venues because chances are he’s going to get booed, or the boos will be louder than the cheers,” said Douglas Brinkley, a presidential historian at Rice University.

“He’s having to curate America, finding places that can allow him to have a public forum,” Brinkley added. “Trump knows that if he’s going to get reelected, he can’t just do it with the base, he’s got to expand the base, and he’s going to have to get out there. The key is finding a university or facility where the crowd can be controlled and Trump can project any heckler into a kind of wacko.”

The president has been hyper-aware of how the public receptions of him have played in the media. After he was greeted with a mix of cheers and boos while attending an Ultimate Fighting Championship bout at Madison Square Garden on Nov. 2, Trump on Saturday basked in the extended applause from a crowd of more than 101,000 at Bryant-Denny Stadium after he and first lady Melania Trump, viewing from a private box, were shown on the scoreboard during the game between the University of Alabama and Louisiana State University.

Ahead of the game, the Alabama student government had reportedly warned students in a letter that they risked losing their group-seating tickets for the rest of the season if they were disruptive in protesting the president and first lady.

Trump’s supporters were elated by the warm reception for the president. Trump retweeted video clips of the moment posted by White House social media director Dan Scavino, Breitbart News reporter Kyle Morris and Andrew Pollack, a conservative gun rights advocate. Each of their videos has garnered between 5 million and 8 million views.

In his tweet of the video, Pollack faulted the mainstream media for focusing attention on the boos Trump received at the World Series while, in his view, mostly ignoring the cheers at the college game. In an interview, Pollack, whose daughter Meadow was killed in the mass shooting at a high school in Parkland, Fla., last year, said he agrees with Trump’s contention that the mainstream press is “fake news,” based on his own experiences with the media in the debate over school safety and gun control.

Of the public opposition to Trump, Pollack said: “Our personalities are similar because we don’t care what other people think. We do what’s righteous and a lot of people don’t want to hear it. If they can’t handle it, his view is, ‘Hit the highway.’ That’s why we all love him.”

The emotional stakes were highlighted by images of a defaced and deflated 20-foot-tall “Baby Trump” balloon, a popular symbol of Trump’s critics, which was slashed about a mile away from the Alabama football stadium where protesters had gathered. Police arrested a man who they said used a knife to leave an eight-foot-long gash in the balloon.

All presidents have faced public opposition, including protesters. President Barack Obama was routinely met at public appearances with conservatives protesting his administration’s handling of the attack on U.S. diplomats in Benghazi, Libya, and liberals decrying his immigration policies or opposing the Keystone pipeline. During the George W. Bush administration, Iraq War protesters often tried to disrupt his events — an Iraqi journalist threw a shoe at Bush during a news conference, and Vice President Richard B. Cheney was booed while throwing out a first pitch for a Nationals game at RFK Stadium.

In a presidency defined by a special counsel investigation into Russia’s election interference and a House impeachment probe, Trump has been less willing to venture into public than his predecessors. He has mostly eschewed cultural activities and spends most of his time outside the White House dining, playing golf or vacationing at one of his properties.

On trips abroad, White House aides have taken careful steps to shield him from mass protests, including holding a bilateral visit in 2018 with British leaders outside of London, where thousands demonstrated against him.

Sensitive to the public perceptions, presidents have spent increasing amounts of time in states hospitable to their political leanings. Though he visited all 50 states over his eight years in office, Obama spent far more time in blue states, raising money and holding political rallies, as well as swing states, which were crucial to his electoral fortunes.

Trump has accentuated that trend in a mirror image, visiting twice as many red states as blue states over his first 2½ years in office. On Thursday, the president will travel to Bossier City, La., to hold his second campaign rally in eight days in that deep-red haven.

As the first sitting president to participate in the Veterans Day parade here in New York, Trump mostly stayed away from politics in his remarks — though he highlighted the U.S. Special Operations forces mission last month that ended in the death of Islamic State leader Abu Bakr al-Baghdadi, which has become part of his campaign stump speech.

After presiding over a wreath-laying and a moment of silence, Trump returned to his motorcade, which sped down the parade route along Fifth Avenue and pulled up to Trump Tower.

The president entered his private residence before the parade began. He had no public events the rest of the day.