President Reagan and Prime Minister Pierre Trudeau talked optimistically of bettering U.S.-Canadian relations today, but a joint public appearance of the two leaders was marked by noisy protests against Reagan's environmental and foreign policies.

Despite the most raucous beginning to a trip abroad for an American president since the Vietnam era, Reagan and Trudeau appeared to make headway in their talks. They agreed to meet with Mexican President Jose Lopez Portillo to further what Reagan called a "North American pact."

Reagan also expressed support for a favorite Canadian project, a natural gas pipeline from Alaska to the United States across Canada.

Anti-American feeling in this usually friendly neighbor nation was spurred by Reagan's action last week in pronouncing all but dead a long-pending treaty that would give Canadian fishermen three-fourths of the scallops in a rich maritime area off the coast of Maine and Nova Scotia.

But the loudest of at least three separate demonstrations against Reagan policies focused on the president's well-publicized belief that air pollution standards should be relaxed in favor of increased industrial production.

"Acid rain, go home," chanted protestors who were allowed within 50 yards of the president as he and Trudeau took turns exchanging courtesies on a platform set up outside Canada's ornate Gothic Parliament building. The demonstrators bore signs saying "Stop Acid Rain." Others carried banners aimed at U.S. foreign policy: "U.S. Guns Kill Nuns" and "Bonzo Supports Terrorism." In counterpoint, a friendly sign declared: "We Like Jellybeans, Too."

Trudeau was visibly disturbed by the demonstrators. He returned to the microphone after Reagan spoke to lecture the hecklers.

"Hey, guys, when I go to the United States, I'm not met with these kinds of signs," Trudeau said. "You know, the Americans have some beefs against us, too, but they receive them politely. Now, how about a great cheer for President Reagan."

He was greeted with boos and cat-calls from the many hundred demonstrators, who outnumbered the rest of the audience.

The House of Commons responded hours later by passing two resolutions, one of which praised Trudeau, rebuked the demonstrators and urged Reagan not to consider their response typical of Canadian hospitality. The other resolution said that the relationship between Canada and the United States is one of "interdependence," which must continue.

Reagan made light of the hecklers, joking in a meeting in the prime minister's office that, "I thought they were imported to make me feel at home."

In recent days Trudeau has been backing away from earlier criticisms of U.S. policy. His original opposition to Reagan's policy in El Salvador was broadened last week to include criticism of all foreign involvement, a statement designed to mollify those opposed to Cuban shipments of arms to Salvadoran rebels. Yesterday Trudeau answered opposition criticism in Parliament on the fishing treaty cancellation by saying that the U.S. Congress, not Reagan, was to blame.

"This government is putting importance on maintaining good relations with the United States," Trudeau said. "We are going into these meetings with the presumption these problems can be settled as they should between neighbors and not with threats."

Outwardly, at least, this attitude marked the approach of both Reagan and Trudeau, who were said by both sides to have hit it off in their private meetings.

Reagan, the first U.S. president to visit Canada since Richard Nixon came here in 1972, was greeted with full military honors and a grace note from Governor General Edward Schreyer: "Mr. President, if this is the era of the global village, then welcome to the house next door."

But no meeting as brief as Reagan's 27-hour visit here could hope to do more than make a beginning on the toughest unresolved bilateral issues -- environmental and energy policies and the fishing treaty.

Reagan is scheduled to address the Commons on Wednesday.