thank you, michael and lowell.
AUCTeX: interesting. I used to run it. I thought I did, but I did not. Now, in emacs 24, installing is easy: I can install-package AUCTeX. Unfortunately, auctex does not give a modeline indication whether it is running (someone, PLEASE add it). I think I now have it running, because now my fill-region command no longer has this problem. So, this solves my specific problem. thanks guys.
I actually now use visual-line-mode and whitespace-newline-mode. the big advantage is that I can deal better with coauthors who do not use emacs. this is how MS-Word and other editors expect things to be. However, at least once, I have to do a reformatting from ancient latex text to newer one. it looses some nice auctex features, like footnote and quote indentation on the following lines, but net-in-net, this is the better tradeoff for me.
tex is a black art. yes, some packages deal better with spacing, but this is a command I have written.
Post by Lowell GilbertPost by iaw4in emacs 24.1.1, running with --no-init-file on ubuntu linux 12.10, I
am trying out how fill-paragraph works. For example, in the snippet
below, if I put my cursor onto world and type M-Q, it wraps the 'In
the real world..." to follow the comment on the previous line.
Obviously, this makes text a comment and is highly undesirable, esp
because in latex, one often needs a trailing % to suppress spaces.
how can I instruct emacs not to wrap into a trailing %? or at least
trailing %% , so that I can mark it?
You're going to get advice to use AUC TeX, which may be the best move
for you. It has a *lot* of indentation and editing features that are not
available in the tex- and latex-modes that ship with Emacs. For longer
documents, AUC TeX is highly recommended because it has nice features
manage documents that are split over multiple files. You can also get
away with fewer tricks like using the space-absorbing hack you
mentioned, by adapting some LaTeX packages to lay out the whitespace
differently in specific situation: take a look at "titlesize" and
"atbeginend" for a start.
That said, your particular request is not unreasonable, and can probably
be accommodated in a number of ways.
First of all, you might consider changing your typing style for LaTeX
files. I tend not to fill sentences at all, because that reduces the
utility of using "diff" (a line-by-line compare tool) to compare my
changes to previous versions. Some people recommend starting every text
line in LaTeX on a new line, for a varety of minor reasons; this can
easily be supported by wrapping by sentence instead of paragraph.
Before I go on to discuss ways to change the Emacs behaviour to
something more convenient for you, let me talk about why the more
simple-minded fill functions don't get this right. The '%' character
does not always mean the start of the comment, and the text-mode fill
code can't necessarily tell just by looking at the current line. So it
guesses, and only occasionally gets it right.
So we get back to wrapping by sentence, which can be recognized more
reliably than paragraph (this is because the confusing uses of '%' are
mostly inside commands, where begin-end matching of brackets will keep
the scope of the parse, and not have any "real" text to mess up). Such a
wrapping function can easily be constructed from the sentence movement
commands, if something of the sort doesn't exist already. Also,
fill-nobreak-predicate could recognize comments better -- but again, you
risk getting funny behaviour if it matches a '%' that *doesn't*
indicated the start of a comment. Yet another variation is to add '%' to
the start and end of a paragraph. I can't really think of any negative
consequences to this possibility, but there might be some.
I apologize for going on at such length.
Good luck.
--
Lowell Gilbert, embedded/networking software engineer
http://be-well.ilk.org/~lowell/