Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Spurious spaces: when do you have to use %?

0 views
Skip to first unread message

KingTomato

unread,
Oct 4, 2005, 4:24:07 AM10/4/05
to
I didn't know this thing of spurious spaces. When & where do you have
to use % in order to avoid them?

Is there a qick guide about the issue?


Ciao

José Carlos Santos

unread,
Oct 4, 2005, 4:56:28 AM10/4/05
to

Read the FAQ:

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=spinmacro

Best regards,

Jose Carlos Santos

Adam Funk

unread,
Oct 4, 2005, 5:05:09 AM10/4/05
to
KingTomato wrote:

> I didn't know this thing of spurious spaces. When & where do you have
> to use % in order to avoid them?

LaTeX (actually TeX, I think) ignores whitespace at the beginning of a line
of source code, but it turns the newline at the end of a line into a space
in the output. If a line contains the comment character "%", then
everything from "%" to the end of the line, including the newline, is
ignored. Here's an example I found:

\item number of separate phrases%
\footnote{For example, it take five canned phrases (with variable
substitution) to read an e-mail with the usual fields (\texttt{From},
\texttt{Subject}, \texttt{Date} and \texttt{Body}).}

With the "%", there would be an incorrect space between "phrases" and the
footnote superscript in the main text.

HTH,
Adam

Brooks Moses

unread,
Oct 4, 2005, 3:46:02 PM10/4/05
to

The FAQ answer that Jose linked to is probably the best answer, but
here's the quick guide:

Assuming nothing strange (such as a verbatim environment) is going on,
the following aspects of TeX are relevant:

The end of a line is treated as a space, unless it is preceeded
by a (normal) space.

Any spaces at the beginning of a line are ignored.

Any spaces after a macro with a multi-letter name (such
as \this, but not \$) are ignored.

The end-of-the-line space is treated as part of the comment,
if the line contains a comment character.

Thus, whenever there is a line break where (a) you do not wish to have a
space inserted, and (b) the line does not end with a macro with a multi-
letter name, you should end the line with a comment character, which
will comment out the space caused by the line break.

Note that this is a relatively rare occurrence in normal text; Adam's
\footnote example is one of the few cases where it arises. Normally you
_want_ the line break to insert a break, because it's separating two
words. The problem is common in macro programming, however, where often
the line break is separating things that shouldn't be separated by a
space in the output.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.

Christophe Jorssen

unread,
Oct 4, 2005, 4:29:17 PM10/4/05
to
> I didn't know this thing of spurious spaces. When & where do you have
> to use % in order to avoid them?
>
> Is there a qick guide about the issue?
>

You can have a look at /The Advanced TeXBook/ by Salomon (I think). It
is the best reference I found regarding this issue. Unfortunatly, I
don't have it anymore in my library...

--
Christophe


Donald Arseneau

unread,
Oct 4, 2005, 4:48:57 PM10/4/05
to
Brooks Moses <bmoses...@cits1.stanford.edu> writes:

> Any spaces after a macro with a multi-letter name (such
> as \this, but not \$) are ignored.

...for values of "multi" greater than or equal to one.


--
Donald Arseneau as...@triumf.ca

Brooks Moses

unread,
Oct 4, 2005, 5:18:27 PM10/4/05
to
Donald Arseneau wrote:
> Brooks Moses <bmoses...@cits1.stanford.edu> writes:
>> Any spaces after a macro with a multi-letter name (such
>> as \this, but not \$) are ignored.
>
> ...for values of "multi" greater than or equal to one.

Huh; I'd thought macros like \c were in the same category as \"; I guess
I should have checked. Anyhow, thanks for the correction!

Dan

unread,
Oct 5, 2005, 3:07:49 PM10/5/05
to

Brooks Moses wrote:

>
> Any spaces after a macro with a multi-letter name (such
> as \this, but not \$) are ignored.

Spaces after "\ " are also ignored.


Dan

0 new messages