# Don't switch to math-mode when entering $ in a minted environment I am using AUCTeX to edit Latex files and use the minted package to highlight source-code within documents. Unfortunately the character $ is still recognized as a delimiter for a math-mode even though it is located within a minted-block and should have no special meaning whatsoever.

This totally breaks syntax-highlighting and makes emacs think I am editing in math-mode although I am not.

Is it possible to configure AUCTex in such a way as to give characters within a minted environment no special meaning? Or do I have to apply some sort of quoting to $? ## 3 Answers You can add minted environments to the latex-verbatim-environment variable: M-x customize-variable latex-verbatim-environments, insert a new string "minted", and save your changes. You may need to reload your .tex file for the changes to take effect. After doing this, minted environments will not be fontified at all, so it won't matter if you include $ symbols.

• I'm pretty sure this happens automatically if file parsing is enabled. It may be worth mentioning it Feb 3 '17 at 19:23
• @giordano I have enabled both TeX-parse-self and TeX-auto-save, and still needed to manually add minted to latex-verbatim-environments. Feb 3 '17 at 19:48
• Which version of AUCTeX are you using? Feb 3 '17 at 19:54
• @giordano 11.90.0 Feb 3 '17 at 20:27
• Ok, I'll have a look in the next days. Feb 3 '17 at 20:36

I'd like to give an answer which is complementary to the one given by @Tyler.

I'd recommend that you set this in your init file:

(setq TeX-parse-self t)


restart your Emacs and open your .tex file again. The difference is that AUCTeX provides a support file minted.el for minted package which does a lot more besides fixing the fontification in environments and macros provided by minted package. You can hit C-c C-e minted RET and will be asked for optional argument and the language for your code; both with auto-completion. Your .tex file could look like this:

\documentclass{article}

\usepackage[newfloat]{minted}

\begin{document}

\begin{minted}{bash}
$echo "Hello"$ echo World
\end{minted}

\begin{Minted}
$echo "Hello"$ echo World
\end{Minted}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-command-extra-options: "-shell-escape"
%%% End:


Note that Minted is just an arbitrary environment to show the difference that code will be indented with 2 spaces where spaces are significant. Here a screenshot for the fontification:

The line

%%% TeX-command-extra-options: "-shell-escape"


allows you to use C-c C-a in Emacs and your file gets compiled correctly with minted.

I still had this problem with a recent distribution of AUCTex, so I looked for an answer. The one given here did not solved my problem. Yet, I added the following command to my .emacs file and everything went fine:

(setq LaTeX-verbatim-environments-local '("minted"))


I hope this might help some people.