From: leichter@zodiac.rutgers.edu
Newsgroups: comp.text.tex
Subject: Re: when is whitespace ignored by LaTeX?
Date: 26 Jan 93 17:15:00 GMT
Organization: Rutgers University Department of Computer Science

In article <1993Jan25.213654.29814@eng.ufl.edu>, ruck@alpha.ee.ufl.edu (John R
Ruckstuhl Jr) writes:
| Would someone give me a few rules of thumb w.r.t. ignorable whitespace?
| 
| In LaTeX, I wrote something like:
| 
|     \begin{picture}(850,1100)
| 
|     \multiput(12,0)(200,0){2}{                  % 2 columns
|         \multiput(0,883)(0,-133){7}{            % 7 rows
|             \framebox(200,133){\parbox[b]{1.75in}{yakyak}}
|         }
|     }
| 
|     \end{picture}
| 
| but the frameboxes were about a character space right of where I wanted
| them (relative to edge of the picture box).  Inserting a \noindent,
| like:
| 
|     \multiput(12,0)(200,0){2}{                  % 2 columns
|         \multiput(0,883)(0,-133){7}{\noindent   % 7 rows
|             \framebox(200,133){\parbox[b]{1.75in}{yakyak}}
|         }
|     }
| 
| solved the problem, but is \noindent really sensible in a picture
| environment?  Also, the following will work:
| 
|     \multiput(12,0)(200,0){2}{                  % 2 columns
| \multiput(0,883)(0,-133){7}{\framebox(200,133){\parbox[b]{1.75in}{yakyak}}}
|     }
| 
| but really, what's the right way to be able to use indentation for
| readability?
| And what about the trailing whitespace in my indentation style, between 
| the end of the framebox command and the "}" on the next line.  Is it
| ignored as I expected, or is it likely to bite me.
| 
| The local guru says this is magic, and after awhile I'll get a feeling
| for when whitespace counts and when it doesn't, but I'm hoping someone
| here can make the rules simple and clear for me.

A COMPLETE set of rules is surprisingly complex; in fact, there's an article
about this subject in the latest TugBoat.  Here are some basic rules for
situations in which TeX itself always ignores all spaces (and TAB's):

	- At the beginning of a line, so you can always safely indent.
	- After a control WORD (\ followed by one or more letters),
		but NOT after a control SYMBOL (\ followed by a single
		non-letter - \_, for example).  This, BTW, is why your
		\noindent worked - it had nothing to do with indentation.
	- In vertical mode; that is, between paragraphs.  Unlike the previous
		two cases, you usually cannot tell what mode TeX will be in
		from a quick look at the syntax, so this is not a generally
		useful rule.  (There are special cases that apply mainly when
		you are writing macros when you DO know.)

TeX ignores a SINGLE space after a number THAT IT READS AS A NUMBER or a
measure.  For example, the space in "\kern1pt " is ignored.  Note that this
almost never comes up in LaTeX, because in most places where you'd use a
number or measure in TeX, you pass an argument to a macro in LaTeX, and the
argument is delimited by "}" anyway.

In addition to TeX's rules, LaTeX deliberately discards spaces in a number
of places where this makes sense.  For example, it discards the spaces at
the beginning of environments - such as after the \begin{picture}.  In
general, you never need worry about spaces after a \begin{whatever} - either
they will make no difference, or LaTeX will discard them.  The same goes for
the ends of environments.

If we look at your example:

|     \multiput(12,0)(200,0){2}{                  % 2 columns
|         \multiput(0,883)(0,-133){7}{            % 7 rows
|             \framebox(200,133){\parbox[b]{1.75in}{yakyak}}

Spaces are NOT ignored after the "{", so they show up in your output.  Note
that end-of-line is treated as a space, so you'd have the same problem even if
you didn't have the comments on the line.

The best way to deal with this is to add extra %'s, as follows:
|     \multiput(12,0)(200,0){2}{%                  % 2 columns
|         \multiput(0,883)(0,-133){7}{%            % 7 rows
|             \framebox(200,133){\parbox[b]{1.75in}{yakyak}}

A good general rule of thumb is:  Add "%" at the end of every line, unless it
otherwise ends in:

	- A control word;
	- \begin{whatever};
	- \end{whatever};
	- simple text to be typeset.

While this may lead you to insert a few extra %'s, it's safe and simple.

							-- Jerry