Generally farts are caused by the incomplete digestion of resistant carbohydrates (like cellulose etc.) Baked beans are complex and hard for you to break down so they make you fart. If you are lactose intolerant, you are not completely breaking down that particular carbohydrate. And if you eat stuff with sulphur in it it adds to the smell. Dried apricots etc are preserved with sulfur products.
There is a product called Bean-O that helps you digest the carbs in beans so you don't fart. And a product called
asafoetida may help too.
I have seen evidence that swallowing air and not burping it can also create a fart stream.