# How to indent back one level when writing a newline?

I'm using Emacs to write LaTeX. For example, in the following code, I have write to the level 3. When I press C-j, the cursor will indent to the third level. I what the newline to be indent at level 2.

How would I be able to do this?

\level 1
\level 1
\level 2
\level 2
\level 3
\level 3
\level 2 % <- I want to end up here


Update: Thanks, I'm using sdaps package to write a survey. Here is a question example. BTW, I don't know list environment yet. Is it related to this?

• Can you give a real use case? The only scenario where I think this is useful is within list environments, and AUCTeX has good list support. This is more-or-less the default behavior when using proper lists. – Sean Allred Oct 27 '14 at 2:59
• Thanks :) Re 'list environments': a 'list' environment is any environment in LaTeX that acts like a list, e.g. itemize, enumerate, and description. That said, I'm having a hard time translating your 'levels' idea to your tabular environments. Can you explain a bit more? :( – Sean Allred Oct 27 '14 at 3:46
• Just added a few explanation. This "back-indent" (or how to call this?) could be done by press a few buttons manuallly. But is there a hot key for this? – user2280 Oct 27 '14 at 4:07

I think I understand now.

There are at least two ways you can get at the behavior you need, assuming you are using AUCTeX (which you should be if you are writing LaTeX):

C-c ] runs the command LaTeX-close-environment, which is an
interactive compiled Lisp function in latex.el'.

It is bound to C-c ], <menu-bar> <LaTeX> <Close Environment>.

(LaTeX-close-environment &optional REOPEN)

Create an \end{...} to match the current environment.
With prefix-argument, reopen environment afterwards.


which will close the environment on a new line and advance point to the next line after that, or the even more convenient

C-c C-e runs the command LaTeX-environment, which is an interactive
compiled Lisp function in latex.el'.

It is bound to C-c C-e.

(LaTeX-environment ARG)

Make LaTeX environment (\begin{...}-\end{...} pair).
With optional ARG, modify current environment.

It may be customized with the following variables:

LaTeX-default-environment'       Your favorite environment.
LaTeX-default-options'           Your favorite document class options.
LaTeX-table-label'               Your prefix to labels in tables.
LaTeX-default-format'            Format for array and tabular.
LaTeX-default-position'          Position for array and tabular.

• It is :) I encourage you to read more about AUCTeX with (info "AUCTeX"); there is so much you can do with it. If you work with citations, RefTeX is equally indispensable. If your documents have a lot of mathematics, preview-latex` (bundled with AUCTeX) comes in very handy. – Sean Allred Oct 27 '14 at 4:19