3

I am using Emacs 25.1.1 on Windows 10 OS with AUCTeX and the CDLaTeX minor mode.

CDLaTeX has a very useful feature of command input, which is typing a shortcut followed by TAB to expand that shortcut. 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.

2 Answers 2

0

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
# --
\begin{equation}
$> $0
\end{equation}

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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