Spitting — Eruvin 99a
תלמוד בבלי מסכת עירובין דף צט/א
אמר ריש לקיש כיח בפני רבו חייב מיתה שנאמר כל משנאי אהבו מות אל תקרי למשנאי אלא למשניאי והא מינס אניס כיח ורק קאמרינן:
From Beis Yechezkel p. 183:
The Shulchan Aruch (Orach Chaim 151:7) permits spitting in a Shul (if he feels compelled to do so involuntarily). It is a widespread custom among Chasidim to spit during Aleynu LiShabei'ach when they recite the words SheHeim Mishtachavim LiHevel VaRik (the source of the custom is the Taz [Yoreh De'ah 179:5]). However, the Arizal was very careful not to spit in a Shul, because of the dictum of Kavod Beis HaKenesses (Sha'ar HaKavanos fol. 4), and the Mishnah Berurah (151:24) warns that one should never spit in front of another person who may be disgusted. This, writes the Mishnah Berurah, is not a Middas Chassidus but a true prohibition (see Chagigah 5), so the gains of "public spitters" are outweighed by their losses.
Moreover, the applicability of the Shulchan Aruch's leniency to today's times is not at all clear. The Sha'ar HaTziyun (151:15) writes that wealthy people that do not allow spitting in their homes are not allowed to spit in their Shuls. Clearly, most people today can be classified as "wealthy" in this regard — viz. that they do not spit on their own floors — and would therefore be forbidden to do so in Shul as well. Furthermore, it should go without saying that smokers may not toss their discarded cigarette stubs on a Shul floor.