About legumes. As far as I know, flatulence is caused by polysaccharides, which can be "soaked" if the beans are soaked for at least 10 hours. If you buy beans in a can, then it is advisable to drain the liquid and rinse the beans themselves.
More thorough chewing of food helps many more. It also takes some getting used to, but in the end it is in any case more beneficial for the body and helps to better absorb food in general.
Many vegan foods do cause flatulence, although they are healthy.
When it comes to legumes, there are several methods. First, the body gets used to them over time. If you have eaten few of them before, it is best to get used to it gradually, starting with small amounts and increasing the portions. Then, beans and cochlea are easier to digest if they are part of the soup. There are also many spices that aid the digestion of legumes - cinnamon, coriander, saffron, cardamom, zira, and many others. If there is access to Indian spice blends, such as garam masala, that is best. In these mixtures, almost every spice not only adds flavor, but also aids digestion.
Nuts and some vegetables can also cause gas. It is important not to overdo it with portions. Drinking fluids should also help.
I was worried about this problem before, now my body is partly used to it, and partly I have built my diet so as to feel good and look good with a flat, not bloated stomach :)