## LaTeX forum ⇒ Text Formatting ⇒ Eating preceding spaces

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
georgevreilly
Posts: 1
Joined: Mon Feb 16, 2009 5:02 am

### Eating preceding spaces

I used to be very knowledgeable about TeX and LaTeX in the late eighties and early nineties, but I've been away from the fold for a long time. I'm pleasantly surprised at how much TeX-fu I still retain, but much has gone.

I'm using \marginpar to add some marginal annotations to a document:
     \newcommand{\side}[1]{\marginpar{#1}}

For legibility, I'd prefer to be able to use it thus:
     world will little note, nor long remember     \side{some stuff}     what we say here, but it can never forget

The \side command is on a line by itself, but it applies to the last word on the preceding line. There's a newline at the end of the preceding line and because of that, the marginal note may appear beside the following line in the output.

I know of two ways to fix this, with a trailing %:
     world will little note, nor long remember%     \side{some stuff}     what we say here, but it can never forget

or by moving \side immediately after "remember":
     world will little note, nor long remember\side{some stuff}     what we say here, but it can never forget

but neither of those are aesthetically satisying. I would prefer not to mutilate the preceding line, but to have the annotation occupy its own line in the TeX input.

Is it possible to have \side discard any whitespace immediately preceding its invocation? I haven't been able to find anything that works. I don't want to put all the regular text inside some environment either.

/George V. Reilly, Seattle

kaiserkarl13
Posts: 603
Joined: Tue Mar 25, 2008 5:02 pm
I figured out something that might work for you based on code from this web site:
http://www.f.kth.se/~ante/latex.php

Essentially, it puts an optional hyphen (which will never get expanded, since it's at the end of a word) in front of the margin paragraph:
\newcommand{\side}[1]{\-\marginpar{#1}}

It isn't fool-proof, but here's a working example of a situation where it helps:
\documentclass{article}\newcommand{\side}[1]{\-\marginpar{#1}}\begin{document}\noindentblah blah blah blah blah blah blah{%world will little note, nor long remember\side{some stuff}}%what we say here, but it can never forget\end{document}

(compare to the result with the optional hyphen command omitted).