Q: how do I define sentence endings to be LaTeX macro-aware?

I'd like backward-sentence and forward-sentence to be smarter about LaTeX macros -- particularly \footnote -- when working in LaTeX buffers. Consider the following snippet:

Here's some text in a LaTeX buffer.\footnote{And here's a footnote example. It's got a couple of sentences.} I wonder how I can get Emacs to recognize where the sentence endings occur?

If point is anywhere in what we would consider the first sentence (ie, before the footnote), calling forward-sentence takes point not to the period immediately before the \footnote macro, but rather to the period after "example" within the footnote. Likewise, if point is at the beginning of the second sentence in the footnote, backward-sentence takes point not to the "A" in "And" at the beginning of the first sentence in the footnote, but rather to the "H" in "Here's" in the sentence that precedes the footnote.

How can I fix the definition of a sentence to make Emacs aware of these macro-boundaries? It looks like I would want to write a specific regexp for sentence-end, but before I start messing around with regexps, I was wondering if someone has already solved this problem.

This S.O. thread asks a related question, but the accepted answer appears to involve writing custom backward-sentence and forward-sentence commands rather than redefining sentence boundaries per se.

  • 1
    I'm afraid regexps may not be suitable here... I just had the idea that one might write a custom forward-sentence function, mimicking the TeX's algorithm of determining the sentence ending. (In TeX, you get larger spaces after sentences, which is btw frowned upon by some typographers. TeX is smart enough to account for common cases like dots after capital letters (=not sentence ending) and parens between the dot and the space (=sentence ending).) – mbork Feb 23 '15 at 21:14
  • Why don't you want to use custom functions? It might be possible to do this with regexps, but it will be much easier to tweak the functions from the post you link to. Is there something other than forward/backward sentence you want to do? – Tyler Feb 23 '15 at 21:43
  • 1
    @Tyler: actually, yes: I use evil and want to be able to use its sentence text objects. Basically, I'm trying to avoid rewriting an open-ended number of functions, with forward-sentence and backward-sentence being the two best-known ones. The other reason is that it seems like this is what sentence-end is intended for, and I'd hate to hack together some functions if a more elegant solution exists. – Dan Feb 23 '15 at 21:56
  • Sounds reasonable. It does seem like sentence-end ought to do this, but when I answered the other post I couldn't figure it out. – Tyler Feb 23 '15 at 21:58
  • @Tyler: that was you on the other thread? Kudos for the idea! – Dan Feb 23 '15 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.