I use AUCTex for all my Latex needs, and it works great. However, I wanted to insert a tikzpicture environment in my document, and I pushed the key C-c C-e for environments, but tikzpicture is not listed amongst the choices. Is there a way to include the \begin{tikzpicture} ... \end{tikzpicture} environment in the list of AUCTex environments? I am not sure what variable I would need to change or how in my dotfile. I use Spacemacs, so I would probably need to append something to the list of environments,right?

  • 1
    If there is a \usepackage{tikz} line in the preamble, I would expect to find tikzpicture in the environment list. It does for me without any intervention on my part. Commented Mar 10, 2021 at 17:22
  • @FranBurstall I will have to give that a try. I ran into this issue before adding the \usepackage{tikz} in the preamble. I did not think that the list of environments was sensitive to the list of packages used, since the other environments like equation or such, never seemed to depend on the packages. But it is a good idea to do a little experiment. Thanks for the suggestion.
    – krishnab
    Commented Mar 10, 2021 at 17:47

2 Answers 2


Okay, I figured it out. A user might need to check the final 3 parenthesis, but this code worked to add the environment. I added the following lines to my .spacemacs file.

;; Add latex environments to list of environments.
(add-hook 'LaTeX-mode-hook 'add-my-latex-environments)
(defun add-my-latex-environments ()
   '("tikzpicture" LaTeX-env-label)))

AucTeX automatically provides a list of environments for you to insert. This includes a set of 'default' environments, based on a hard-coded set of environments commonly associated with the documentclass of your file.

Additionally, AucTeX parses the header of your file, and if it detects any packages that provide additional environments, these are added to the list. This functionality depends on you telling AUCTeX to parse your file automatically:

(setq TeX-parse-self t) ; Enable parse on load.
(setq TeX-auto-save t) ; Enable parse on save.

You can also manually tell AUCTeX to reparse your file, if you don't want it done automatically. The command TeX-normal-mode, bound to C-c C-n by default, serves this purpose.

There may be exceptions where you need to manually add an environment. However, I have just tested this with Emacs 28.0.50 and AUCTeX 13.0.5, and the tikzpicture environment is properly detected when your file contains the \usepackage{tikz} macro.

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.