Step 1. Don’t.
You’re being selfish and other people suffer for your brief moment of sinister relaxation. There is no plausible or excusable reason to fart in an elevator, other than sick sadist satisfaction. Try not to be a sociopath, and break the wind before and/or after being inside a cramped public place.
Avoidance of legumes and Mexican foods help prevent the need to pass gas in the first place. However, we are all only human, and Mexican food is subjectively the best food. When you inevitably give into human error, take steps to minimize embarrassment.
Step 2. Pass blame
So you accidentally passed gas, now is the time to frame someone else to save face. The key to blaming someone else is to not say what you mean, try to resort to body language to avoid embarrassment.
Find the second “most likely-looking to fart in an elevator” person and look at them disapprovingly, hiding your malcontent. It helps to grab at your nose. If you are one of two people in the elevator, this strategy works with less success.
Step 3. Pray to Sterquilinus
The relatively esoteric Roman god may or may not exist, but what you need to focus on is if he/she is a malevolent deity.
Step 4. Press all the buttons
Which is more distracting? The olfactory sensation of a gross smell, or the rude visible act of pressing every single button? Give into the childhood urges, and light that panel like a christmas tree. It is only a mild inconvenience, and what does the opinion of others matter? They are already judging you for being mortal, and farting.
Step 5. Admittance of guilt
Speak as a politician, “Mistakes were made”. Like academic writing, avoid using first person. If you utilize the word “I” it is too late, you’ve failed. Practice an apology before apologizing; much like music, repetition and practice will make your apology sound better. However, only apologize once. Because groveling is as unattractive as natural body functions.