If you know someone is infected then special precautions like wearing a high efficiency well fitting mask is the way to go.
Unfortunately, in practical terms, there is little you can do to avoid getting it. It is transmitted by airborne droplets. Avoid people who are coughing. In areas where TB rates are high, BCG vaccination is an option.