I am using Emacs 25.1.1 on Windows 10 OS with auctex, and cdlatex minor mode.

Cdlatex has a very useful feature of command input, which is typing a shortcut followed by TAB. for instance:

When I type eqt TAB, it will input a whole latex equation environment and move the cursor into this environment.

my question:

Regarding the indentation of this environment input. It just doesn't respect the current indentation (like child, subchild, etc). I search around and there seems no information about this.

Is there any hot fix for this general environment input indentation thing?

Thanks a lot.


Looking at cdlatex mode, it doesn't appear to be designed with modifying the inserted templates in mind (I could be wrong).

The yasnippet package does offer completely customizable templates, with the option to have them respect indentation. It takes a bit of reading to figure it out, but once you do you can write your own templates to do fairly complex insertions. For your example, the following:

# name: eqt
# key: eqt
# --
$> $0

Will create a snippet, bound to the text eqt, that expands to an equation environment, and the environment will be indented as appropriate based on the surrounding environments (if any).

If that looks interesting, check the documentation for yasnippet. You need to install the package (via package-list-packages), enable the mode for latex files, and write or install the snippets you want to use.

| improve this answer | |

You can define new environments in cdlatex using cdlatex-env-alist and assign a hotkey to those with cdlatex-command-alist.

For your case,

(setq cdlatex-env-alist '(("equation" "\\begin{equation}\n\t ?  AUTOLABEL \n\\end{equation}" nil)))

This will override the default equation environment. Note that \t inserts the tab just before the cursor. Checkout the documentation for more details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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