Inside the onion cells is a chemical compound that contains sulfur. When we slice and dice an onion, the cells break, and react with an enzyme outside of the cells. A series of chemical reactions takes place and new molecules are formed, which also contain sulfur and are released into the air. When the molecules react with the moisture in your eyes, sulfuric acid is formed and you feel a burning sensation.
Tear gas is also a lachrymator.
There are a couple of things you can do to make onion-dicing a more pleasant chore. First, you can freeze the onion for 10 to 20 minutes before cutting it. The cold temperature of the onion will slow down the chemical reaction. Another thing to try is to chop the onion under cold water . The sulfuric acid will still form, but the chemical reaction will get its necessary moisture from the water rather than from the moisture in your eyes.