A photographer finds the beauty in a troubled neighborhood with a story not unlike his own.

SAN FRANCISCO — The line for a free breakfast snaked around Glide United Memorial Methodist Church. Police busted two men in a restaurant doorway. Panhandlers provided a neighborhood soundtrack.

It was Sunday morning in the Tenderloin, and Mark Ellinger had pictures to take. Clutching a camera in his meaty right hand, cigarette poking out between his fingers, the photographer marveled at the carved stone lintel of the Marathon Hotel.

He gestured toward the building that once housed famed madam Tessie Wall's last "parlor house." Then he pointed out the muraled back of a single-room-occupancy hotel called the Fairfax.

"I used to live on the third floor," he said. "People would climb up the fire escape, break in, do drug deals, sleep in the hallways."

It would be hard to find a better photographer for the work in progress that is the Tenderloin than the work in progress that is Mark Ellinger. Where others see blight, the recording engineer turned homeless heroin addict turned self-taught historian and artist sees beauty.

When advocates pushed to have the neighborhood designated a national historic district (an honor awarded in 2009), they enlisted Ellinger to document parking garages that once had been stables, offices that used to be brothels and the largest concentration of SROs (single room occupancy buildings) still standing in America.

Now the photographer, a lanky 62-year-old with a shock of white hair, and his favorite subject have been captured by playwright/director Annie Elias. "Tenderloin," which opens Friday night at the Cutting Ball Theater, details life in the beleaguered heart of one of America's most beautiful cities.

--

The Cutting Ball is in the southeast corner of the Tenderloin, 30 or so of the poorest, most densely populated blocks in San Francisco, an area roughly bordered by Union Square, Nob Hill, the Civic Center and Market Street.

Before the 1906 earthquake and fire destroyed it, the Tenderloin was a respectable residential area -- as well as home to gambling joints and brothels, restaurants and theaters. It was rebuilt as an experiment in multiunit urban living, with what is believed to be the first studio apartment building in the country.

The other enterprises also rebounded after the disaster. A 1940 Works Progress Administration guide described the Tenderloin as "a region of apartment houses and hotels, corner grocers and restaurants, small night clubs and bars, gambling lofts, bookmakers' hide-outs and other fleshpots of the unparticular."

The balance between legal and illegal began to tip in the 1960s -- and was largely upended a generation later with the advent of crack cocaine. Today, pain and promise skirmish here.

There are efforts to build a Tenderloin museum and attract tourists. Two days before Elias' play had its first preview last week, the Uptown Tenderloin Historic District unveiled a series of sidewalk plaques commemorating its "lost landmarks."

In front of Wally Heider Recording, sound engineer Stephen Barncard reminisced about the Grateful Dead and the Doobie Brothers, Creedence Clearwater Revival and Jefferson Airplane. The concrete Moderne building on Hyde Street "was the best place to be in 1969," he said as a disabled, homeless woman scuffed her way across the bronze plaque lauding "the city's first modern recording studio."

At the same time, the North of Market-Tenderloin Community Benefit District is also working on more basic services, like trying to design public toilets that won't double as shooting galleries. The organization has partnered with another nonprofit group to sweep and scrub the sidewalks, water trees and dispose of what its website delicately describes as "hazardous waste."

Because, as one character in "Tenderloin" notes halfway through the play, "Who said that poor people have to live in squalor?"

--

Ellinger's rise and fall and rise is seen in the pages of the San Francisco Chronicle.

There he is in 1987, a successful composer and sound engineer, commenting on the death of avant garde filmmaker Curt McDowell, a close friend. They met at a San Francisco Art Institute painting class that, Ellinger said, "ended up with everybody fiddling around in the fountain with their clothes off late into the night."

All that is left of that time can be found on a website Ellinger calls "Music From Another Lifetime" -- a handful of scores and songs he composed when he still owned a piano.

Sixteen years later there's a newspaper photograph of a homeless Ellinger -- 53 but looking much older -- in the Tenderloin's St. Anthony Dining Room being served the charity's 30 millionth meal.

Between the obituary and the free beef bourguignon, Ellinger lost everything.

His closest friends died, and so did his adoptive father. His adoptive mother disowned him. He suffered a series of manic-depressive breakdowns, walked away from his recording studio, Truth and Beauty, and never went back.