Born in Baltimore and raised on Orleans Street, he was the son of Thomas R. Foster Sr., a Glenn L. Martin aircraft employee, and Mary Ruth Myers, a Sinai Hospital manager. He was a 1950 Polytechnic Institute graduate and earned a bachelor's degree from what is now Towson University, where he was a member of the honor society.

He joined the Baltimore City school system and taught for a semester at Clifton Park Junior High School. He was then drafted and assigned to an Army infantry unit in Germany, where he worked in intelligence.

After leaving the service, he resumed teaching and was assigned to Hamilton Junior High School while Herring Run Junior High was being constructed.

"I was an awkward student and was getting Cs in an accelerated program. He gave me advice on how to study and taught me to ask questions. I went on to get a degree in electrical engineering," said Bohdan Bulawka of Sarasota, Fla. "He also tried to make us see the big picture. He formed a Civil War club and had us study the maps of the great battles."

He was on the Herring Run faculty when the school opened. There he met students who remained in touch with him for more than 50 years.

"Dr. Foster had a truly generous and kind spirit," said Iris Bauernfeind Lepley of Parkville. "In 2009, when our homeroom class from the first accelerated academic program to graduate from Herring Run Junior High decided to have a reunion, he welcomed his former students back into his life. He cared not only about the children we were but also about the adults we had become."

Another former student, Sherrilynn Wilmer, recalled, "He was always patient with us and worked hard to explain the mysteries of mathematics to a bunch of 12- and 13-year-olds. He also ran the savings stamp program and I remember helping him collect the money in the morning."

"He was a dynamic math teacher and made the classes fun," said Kenneth Smith of Salisbury, a former Herring Run student who later taught at City College and Western High School. "He used common everyday objects and situations to demonstrate math principles. He picked up a circular trash can to show the value of pi."

Dr. Foster was widely quoted in news articles. In a 1983 Baltimore Sun article about overcrowded classes, he said that when Patterson Senior High School added a ninth grade, the predictions called for 95 students.

"All of a sudden, 200 converged on us," he said in the article. "We had a lot of layoffs, such as at Bethlehem Steel, and a lot of parents who had been sending their kids to Catholic schools decided they couldn't afford it. They didn't make that decision until school opened."

Dr. Foster was a co-author of three mathematics texts. His 1971 book, "Key Ideas," published by Harcourt Brace, was written with Polytechnic Principal William Gerardi and Wilmer Jones, the city's coordinator of mathematics.

The textbook was widely used throughout Texas, Charleston, S.C., Detroit, Pittsburgh and other school systems, according to a 1976 Sun article.

"Publishers will identify a need for a book and put together a team of authors to work on it," Dr. Foster said in the 1976 article. "In this case, they came to Baltimore City and asked us what they were doing wrong. They were losing money in junior high math. We told them what we needed, and they said, 'Go to work.' "

The Sun's article called the textbook an "immediate success. A volume that could be used easily by the most amateur of teachers and required little reading."

Dr. Foster, whose family was originally from Virginia, was a Confederate Civil War re-enactor. Family members said he made his own uniforms and participated at events in Sharpsburg and Gettysburg. He was also a founder of the Victorian Dance Ensemble and called its dances.

After moving to Oak Crest Village, he wrote for the retirement community's newspaper. He enjoyed sailboat racing, classical music and digital photography. He was also an opera buff.

A memorial service will be held at 1:30 p.m. March 15 at Oak Crest Village Chapel, 8801 Walther Blvd.

He is survived by his wife of 54 years, the former Jean Toms, a retired nurse and nursing teacher; a son, Thomas R. Foster III of Darlington; two daughters, Laura Foster Daniels of Essex and Susan Foster F. Lanman of Bel Air; and four grandchildren.