I was recently scolded by a teacher for yawning in class. If there is any other time when I feel the urge to yawn, how can I avoid it?
When you are about to yawn just touch the tongue with one of your fingers.
The saltiness does the magic; it's highly unlikely that someone will carry salt in pocket, but a finger does the trick.
That's my hack for preventing a yawn. I hope you find it useful.
You can also take a deep breath right before the yawn hits. It takes some alertness to anticipate the yawn, but this is the least conspicuous solution I've found.