LaTeX forum ⇒ Text FormattingEating 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

Postby georgevreilly » Mon Feb 16, 2009 5:12 am

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:
  1. \newcommand{\side}[1]{\marginpar{#1}}


For legibility, I'd prefer to be able to use it thus:
  1. world will little note, nor long remember
  2. \side{some stuff}
  3. 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 %:
  1. world will little note, nor long remember%
  2. \side{some stuff}
  3. what we say here, but it can never forget

or by moving \side immediately after "remember":
  1. world will little note, nor long remember\side{some stuff}
  2. 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: 593
Joined: Tue Mar 25, 2008 5:02 pm

Postby kaiserkarl13 » Thu Feb 19, 2009 5:35 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:
  1. \newcommand{\side}[1]{\-\marginpar{#1}}


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

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


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests