6

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.

enter image description here

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 $?

Simon Fromme
  • 332
  • 1
  • 9

3 Answers3

5

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.

Tyler
  • 21,719
  • 1
  • 52
  • 92
4

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:

enter image description here

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.

Arash Esbati
  • 1,795
  • 1
  • 8
  • 13
0

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.

perror
  • 115
  • 9