President Obama took a rare break Tuesday from campaigning in swing states to visit deep-red Texas, mindful that raising green can be as important as turning a state blue in the most expensive election in history.

Trailing Republican challenger Mitt Romney in raising money over the past two months, Obama appeared at four fundraisers in San Antonio and Austin, where his campaign expected to collect as much as $4 million and surpass his previous single-day Texas record.

The haul comes at a critical time: Obama’s campaign has been alarmed by Romney’s recent fundraising surge. In June, for example, Romney raised $106 million, compared with Obama’s $71 million.

It was the seventh time Obama has raised money in the Lone Star State since he took office and the second time this year. The home of Obama’s Republican predecessor, George W. Bush, as well as a would-be GOP challenger, Gov. Rick Perry, Texas has been surprisingly fruitful territory for the president.

Obama has raised $15.7 million in Texas, the fifth-highest total from any state, trailing California ($64 million), New York ($41 million), Illinois ($18 million) and Florida ($17 million). Texas is the only one of those states that Obama did not win in 2008, and the only reliably Republican one.

Romney has raised $24 million from Texas for his campaign and the Republican National Committee, racking up $3.5 million at a recent luncheon appearance in San Antonio.

The president sandwiched the Texas stops between visits to crucial battleground states: Ohio on Monday and Florida on Thursday and Friday. At his first stop in San Antonio, a convention center luncheon of 1,200 supporters, many of them Latino, he began to warn the crowd about a spate of negative television ads before realizing that his audience might not see many of them on the local airwaves.

“You’re not considered one of those battleground states,” Obama said. Then he declared: “But that’s going to change,” drawing cheers.

That might not happen for a while, though.

Upon touching down in Texas, Obama was reminded that the state could be hostile territory. He was greeted by news reports that Perry was demanding an apology for comments by Attorney General Eric H. Holder Jr. about the state’s voter identification law. Holder called the law a “poll tax” and equated it to Jim Crow-era requirements.

But Obama got a rousing reception from his Democratic audiences. He also spoke to a group of gay activists in Austin and held more intimate, high-dollar events at the homes of Mikal Watts, a San Antonio trial lawyer, and former Dell finance chief Tom Meredith, who lives in Austin.

Appealing to the mostly Latino crowd in San Antonio, Obama hit Romney on immigration, charging that the GOP candidate believes that the tough immigration law Arizona approved, which was in part overturned by the Supreme Court, is a “model for the nation.”

The crowd booed, and Obama continued: “I believe we are a nation of laws and a nation of immigrants. I believe we can secure our borders and give opportunities to people who are striving and working hard — especially young people who have been raised in this country and see themselves as Americans. That was the right thing to do.”

Among those turning out to see the president were former Housing and Urban Development secretary Henry Cisneros; U.S. Trade Representative Ron Kirk, who traveled with Obama on Air Force One; actress Eva Longoria, a major Obama bundler; and former San Antonio Spurs basketball player Bruce Bowen.

Asked what difference Obama supporters could make in a red state, Bowen responded: “At the end of the day, it’s still part of the great U.S.A., and we can’t necessarily divide things like that because we’re all in it together. I’m thrilled to be a part of this.”

Obama was, too, so much so that on Wednesday he’ll bring a little piece of Texas back to Washington when the national champion Baylor University women’s basketball team visits the White House.