# How can I prevent auctex to indent a new environment inside another environment?

Suppose I enter the following code using LaTeX-environment

\begin{tikzpicture}
\begin{pycode}
a = 2
\end{pycode}
\end{tikzpicture}


Then auctex automatically indents as shown above. This is not desired since it will bring error messages if I compile it via pythontex because of wrong indentation.

So I have two question:

1. How to prevent that the pycode environment becomes indented if it is insied any other environment (for example tikzpicture)
2. How to prevent that code inside a pycode environment is indented by auctex.

Note that this is a follow up question to Pythontex and auctex, so the solution should work together with mmm-mode.

Edit

After giordanos suggestion I made a minimal .emacs file:

(require 'package)
;;              '("melpa" . "http://melpa.milkbox.net/packages/") t)

;; (setq package-archive-enable-alist '(("melpa" deft magit)))

(package-initialize)

'("pycode" current-indentation))
))

(require 'python)
(defun python-indent-guess-indent-offset ()
"Guess and set python-indent-offset' for the current buffer."
(interactive))

(require 'mmm-auto)
'((latex-python-envs
:submode python-mode
:face mmm-default-submode-face
:front "\\\\begin{\$$pycode\\|pyverbatim\$$}\n"
:back "\\\\end{~1}\n"
:save-matches 1)

(latex-python-cmds
:submode python-mode
:face mmm-default-submode-face
:front "\\\\pyc?{"
:back "}")))

;; (setq mmm-global-mode 'maybe)
;; (setq mmm-submode-decoration-level 0)
;; (global-set-key [(f11)] 'mmm-parse-buffer)



It works but messes up the syntax highlighting:

If I do C-c C-n, it becomes ok, but the mmm-mode get's disabled:

If I enable the mmm-mode again, I get the first picture again.

(add-to-list 'LaTeX-verbatim-environments "pycode")

• Thanks, that solves problem 2. For the first problem, the \begin{pycode} remains indented. Any idea? – student Feb 10 '16 at 14:29
• See the updated answer, you should add pycode also to LaTeX-verbatim-environments. – giordano Feb 10 '16 at 14:35
• Uh, doesn't happen for me. Try to revert the buffer with C-c C-n`. – giordano Feb 10 '16 at 14:58