0

Let's say I write a subscript inside a math environment like \(a_p\). Auctex conveniently, and by default creates a pair {} and puts the cursor inside of it so I don't have to bother putting them myself to deal with multiple subscripts. However, I wonder if there is there a keymap to escape these {} without using the arrow keys. For example, C-e puts the cursor outside the math environment, when sometimes I would like to keep writing the formula after done with the subscript.

2 Answers 2

1

There are, of course, alternatives to the arrow keys such as C-f and friends.

An alternative is to use the cdlatex package (which plays very nicely with auctex). With this loaded, TAB calls cdlatex-tab which exits {} groups and more:

This function first calls all functions in ‘cdlatex-tab-hook’, which see.

If none of those functions returns t, the command first tries to expand any command keyword before point.

If there is none, it cleans up short subscripts and superscripts at point. I.e. it changes a^{2} into a^2, since this is more readable. This feature can be disabled by setting ‘cdlatex-simplify-sub-super-scripts’ to nil.

Then it jumps to the next point in a LaTeX text where one would reasonably expect that more input can be put in. To do that, the cursor is moved according to the following rules:

The cursor stops...

  • before closing brackets if ‘preceding-char’ is any of -({[]})
  • after closing brackets, but not if ‘following-char’ is any of ({[_^
  • just after $, if the cursor was before that $.
  • at end of non-empty lines
  • at the beginning of empty lines
  • before a SPACE at beginning of line
  • after first of several SPACE
1
  • C-f is really what I needed. I might take a look at this function later, but I'm using Tab to trigger snippets right now, and that could cause some issues. Commented Aug 15, 2022 at 20:03
1

AUCTeX's behavior after ^ and _ in math mode is controlled by the variable TeX-electric-sub-and-superscript:

TeX-electric-sub-and-superscript is a variable defined in ‘tex.el’.

Its value is nil

If non-nil, insert braces after typing ^ and _ in math mode.

Default value is nil which means no braces after ^ and _. As usual, you can press C-q ^ and C-q _ in order to get the literal ^ or _ without braces where you actually don't need them, e.g., \(a_p\).

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.