Is there an easy way to perform an ordinary forward-paragraph in latex mode?

When the point is at a after running the command forward-paragraph the point goes before the first \. I just want to go after the last $.


1 Answer 1


It depends on whether you want, in addition to the LaTeX version, a new function to do the "ordinary" forward paragraph stuff (by which I mean the Text mode version where a new paragraph begins after an empty line (or a form-feed character, i.e. ^L) or whether you want to replace the LaTeX version with your version. IMO, you should leave the LaTeX version alone and add a new one for your purposes: you can bind your new function to the C-down key where forward-paragraph is usually bound, but you can still call the LaTeX version with M-x forward-paragraph - or you can bind your function to a different key.

Here's a modified function that behaves "ordinarily":

(defun my/forward-paragraph (&optional arg)
  (interactive "^p")
  (let ((paragraph-start "\f\\|[ \t]*$")
         (paragraph-separate "[ \t\f]*$"))
     (forward-paragraph arg)))

This takes advantage of the fact that forward-paragraph uses the variables paragraph-start and paragraph-separate to specify regular expressions that matchs any string that should be considered the start of a paragraph and any string that separates paragraphs. By default, those are

"\f\\|[ \t]*$"
"[ \t\f]*$"

respectively, i.e. either a form-feed character or an "empty line" (a line with only spaces or tabs - or nothing) for paragraph-start and an "empty" line (a line with only spaces, tabs or form-feeds - or nothing). Major modes redefine these variables to accommodate their definition of how paragraphs start and are separated from each other. The function above does local redefinitions back to the default values before calling forward-paragraph and that overrides for the duration of the function any override that the major mode has done.

  • Thank you, but it still stops before $$ (double $).
    – Name
    Commented Apr 30 at 5:36
  • The problem was that that there is another variable that needs to be reset to its default value: paragraph-separate. Thanks for trying it out and reporting. I think it's fixed now.
    – NickD
    Commented Apr 30 at 8:05
  • Thanks, apart from an extra parenthesis ) at the end of the third line (that should be removed) the code works as expected.
    – Name
    Commented Apr 30 at 15:03
  • @NickD - Why not just using LaTeX-forward-paragraph in your definition? Commented Apr 30 at 15:03
  • Fixed the paren - thanks! @ArashEsbati: why should it? After all, this function has nothing to do with LaTeX: it just resets defaults, so it could be used for a similar purpose in another mode that mucks around with paragraph-start and paragraph-separate.
    – NickD
    Commented Apr 30 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.