I have recently falled into an error because I didn't use % when I was supposed to. My question is now: When do I have to use % at the end of the line and when should I leave it out?


An end of line is a space so your question is asking when to add a space.


is the same as

foo bar



is the same as


so it just depends on the context. Sometimes a space is needed to separate words, or for TeX syntactic reasons, sometimes a space is not needed but ignored anyway, and sometimes a space is definitely wrong at that point.

| improve this answer | |
  • ...except for things like verbatim, where an EOL is not a space. – Steven B. Segletes Oct 13 '15 at 23:29
  • I also think it worth to explicitly mention that spaces (and thus %) are ignored after \if family of conditionals, as well as after \else and \fi...since they are used pervasively in macros. – Steven B. Segletes Oct 13 '15 at 23:32
  • @StevenB.Segletes ??? \if has no special treatment of spaces. – David Carlisle Oct 14 '15 at 6:53
  • Did I say that? Must have been my alter-ego. Need to adjust the meds. – Steven B. Segletes Oct 14 '15 at 10:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.