TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a key combination to move the insertion point backward and forward through arguments using AUCTeX? For example, where "|" is my insertion point:


Then I would want a command to move it:


And perhaps another command to move it back:


And another to move it out:

share|improve this question
yasnippet does this sort of thing very well. Somebody has already written quite a few snippets for LaTeX, such as this one for \frac{}. yasnippet can be used in other modes and languages as well as in TeX. – SlowLearner Oct 5 '13 at 22:48
up vote 5 down vote accepted

To move between empty groups I use these functions (can be improved of course):

(defun mg-TeX-forward-group ()
  "Move to the next empty group."
  (let ((group (save-excursion (search-forward-regexp "{[^}]*}" nil t))))
    (when group
      (set-mark (point))
      (goto-char group)
      (backward-char 1))))
(eval-after-load "tex"
  '(define-key TeX-mode-map [M-right] 'mg-TeX-forward-group))
(defun mg-TeX-backward-group ()
  "Move to the previous empty group."
  (let ((group (save-excursion (search-backward-regexp "{[^}]*}" nil t))))
    (when group
      (set-mark (point))
      (goto-char group)
      (forward-char 1))))
(eval-after-load "tex"
  '(define-key TeX-mode-map [M-left] 'mg-TeX-backward-group))
share|improve this answer
Changing search-forward "{}" to search-forward-regexp "{[^}]*}" and search-backward "{}" to search-backward-regexp "{[^}]*}" is more what I was looking for. – Geremia Oct 6 '13 at 4:43
@Geremia Your change has been approved, but you need to then change what the OP wrote about moving between empty groups. The change you made will pick up non-empty groups too. – A.Ellett Oct 7 '13 at 17:35
@A.Ellett That's fine. – Geremia Nov 7 '13 at 23:31
Upon starting Emacs, I get this strange error when putting your code in my ~/.emacs file: Symbol's value as variable is void: TeX-mode-map. – Geremia Nov 7 '13 at 23:40
@Geremia I keep forgetting to wrap an eval-after-load around define-keys. I'll update my answer. – giordano Nov 8 '13 at 0:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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