Generalcommenting the ends of lines of command arguments

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
johnjamessmith0
Posts: 37
Joined: Sun Mar 29, 2009 1:41 am

commenting the ends of lines of command arguments

Post by johnjamessmith0 »

I know I've read an explanation about this somewhere, but I couldn't think of a good way to search this question up, sorry.

Will someone explain what is going on when people put '%'s at the ends of lines in multi-line command definitions, and the like, as in

Code: Select all

\def\markboth#1#2{%
  \begingroup
    \let\label\relax \let\index\relax \let\glossary\relax
    \expandafter\@markboth\@themark{#1}{#2}%
    \@temptokena \expandafter{\@themark}%
    \mark{\the\@temptokena}%
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}
(from fancyhdr's extramarks.sty). I know the practice avoids some problems that tend to occur, but I'd just like to understand why it's necessary so I know when I need it and when I don't.

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

commenting the ends of lines of command arguments

Post by meho_r »

When you press "Return/Enter" key and go to another line, a space is automatically added at the end of the previous line in the output. Adding a "%" sign at the end of a line prevents this space from coming into existence (and a space can do much damage when it finds its way into command definitions).

Here's an example, observe the result:

Code: Select all

\documentclass{article}

\begin{document}

Test
Test
Test

Test%
Test%
Test

\end{document}
Post Reply