Take the 2-minute tour ×

I do a lot of editing using Emacs and auctex, some of this involve wrapping certain parts of the manus with a certain environment. This is quite easy using transient-mark-mode and C-c C-e.

But I'd like Emacs to do some cleanup on the text as well as wrapping the environment.

As far as I can see LaTeX-add-environments is mostly for empty environments, where the interface will ask for information.

Anyone know if it it possible to add a processing hook as well, or do I need to take a different route?

share|improve this question
Reading through gnu.org/software/auctex/manual/auctex/Adding-Environments.html might give a hint of what is possible? –  N.N. Jan 17 '13 at 9:37
@N.N. actually, by looking though latex.el I think it have found the answer LaTeX-after-insert-env-hooks, doc.el use this to add a hook to makesure macrocode env is formatted correctly. Sounds like exactly what I'm looking for. –  daleif Jan 17 '13 at 10:42
add comment

1 Answer

To answer my own question

(add-hook 'LaTeX-after-insert-env-hooks 'LaTeX-after-insert-hint  nil t)

where I have defined LaTeX-after-insert-hint, just remember that the hook is given env (name of environment, should test to see if it is the one the hook should be acting on), start (pos just before the inserted \begin) and end (pos just before inserted \end)

EDIT: In the the present case, I'm editing a book, where the author sometimes write hints within the exercises. I'd like those to have a consistent look, so I wrap a hint environment around it. The hints often start with Hint:, I'd like the environment to provide that, so I want a hook that can clean the contents of the hint environment after I have wrapped hint around it using C-c C-e. This does the trick

;; remember start is just before inserted \begin
(defun LaTeX-after-insert-hint (env start end)
  "Do some cleanup of the hint env"
  (when (string-equal env "hint")
      (goto-char start)
      (forward-line 1)
      ;; only clean if there is a match
      (when (looking-at "[ \t\n]*Hint\: *")
      (LaTeX-fill-environment 'left)

The (LaTeX-fill-environment 'left) is not necessary, it is just a nice extra feature.

share|improve this answer
I don't understand, what you have done. But as you seem to be a decent user of TeX, Emacs & friends, your answer might be valuable for others. Would you mind to go into some details and publish your code? –  Keks Dose Jan 17 '13 at 14:31
add comment

Your Answer


