# Minted red box around greek characters

When using Minted i get a red box around greek characters

Can this behaviour be disabled or is there a specific line that needs to be changed in the python lexer?

A minimal working example

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{XITS}
\setmonofont{Consolas}

\usepackage{minted}
\setminted[python]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\footnotesize,
frame=lines
}
\begin{document}
\section{Some code in this section}
\begin{minted}{python}
return α + β
\end{minted}
\end{document}


edit: I am using xelatex

• Can you please add a minimal example of code? – egreg Dec 11 '16 at 16:12
• You get this behaviour, too, if you use German umlauts (ä, ö, ü). Is there a "real" solution yet? – elementzero23 May 7 '18 at 15:13
• This seems to be a feature of the underlying Pygments library (cf pygments.org/demo/6790720), so you would probably need to open an issue at bitbucket.org/birkenfeld/pygments-main/issues (if there isn't one already, I haven't checked) to get this changed. From the LaTeX side of things there are probably only work-around that treat the symptom, not the disease. – moewe May 7 '19 at 7:57

This seems to be an error in the Python lexer. If you don't need \fcolorbox inside the minted environment, here's a hack:

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{XITS}
\setmonofont{Source Code Pro} % I don't have Consolas

\usepackage{minted}
\setminted[python]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\footnotesize,
frame=lines
}
\usepackage{etoolbox}

\makeatletter
\AtBeginEnvironment{minted}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\makeatother

\begin{document}

\section{Some code in this section}
\begin{minted}{python}
return α + β
\end{minted}
\end{document}

\end{document}


Here's the patch also for \inputminted:

\begin{filecontents*}{\jobname.py}
return α + β
\end{filecontents*}

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{XITS}
\setmonofont{Source Code Pro} % I don't have Consolas

\usepackage{minted}
\setminted[python]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\footnotesize,
frame=lines
}
\usepackage{etoolbox,xpatch}

\makeatletter
\AtBeginEnvironment{minted}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\xpatchcmd{\inputminted}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{}
\xpatchcmd{\mintinline}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{} % see https://tex.stackexchange.com/a/401250/
\makeatother

\begin{document}

\section{Some code in this section}
\begin{minted}{python}
return α + β
\end{minted}

\inputminted{python}{\jobname.py}

\end{document}


• This hack seems to work fine for my minimal example but when i use it in conjunction with \inputminted I still run in to problems. – Kim Petersen Dec 11 '16 at 17:21
• – Kim Petersen Dec 11 '16 at 17:31
• @KimPetersen Patch for \inputminted added. I used filecontents just to make the example self-contained. – egreg Dec 11 '16 at 19:06
• I tried to understand that code, but i wasn't able to :-( . Could provide me someone please a sample to stop hightlight errors in Minted Inline? I will be very thankful. – Ivo Looser Jan 29 '17 at 18:15
• @IvoLooser The code simply disables \fcolorbox inside minted snippets. – egreg Jan 29 '17 at 18:53

I suggest you try to use a minted style that does not higlight \PYG{err}

\usemintedstyle{xcode}


Of course if your red boxes was generated because of some \PYG{err}

Just for completeness and since I can't comment yet:

The hack in the Answer by egreg can also be applied to the command \mintinline by

\xpatchcmd{\mintinline}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{}


Greetings

• Why re-adding the code when egreg already provided the same solution for the inline variant? – epR8GaYuh Feb 11 '20 at 8:44

I had a similar problem but couldn't disable error highlighting for all minted environments. And I came up with the following modified version of @egreg that worked for me.

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{XITS}
\setmonofont{Source Code Pro} % I don't have Consolas

\usepackage{minted}
\setminted[python]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\footnotesize,
frame=lines
}
\usepackage{etoolbox}

\makeatletter
\AtBeginEnvironment{noerr}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\makeatother

\newenvironment{noerr}{}

\begin{document}

\section{Some code in this section}
\begin{noerr}
\begin{minted}{python}
return α + β
\end{minted}
\end{noerr}

\end{document}


So instead of replacing fcolorbox in the minted environment, I create a new environment noerr, in which fcolorbox is replaced. This way I can use the minted environment in the noerr environment to suppress the highlight but also use it outside to get the highlighting.

I currently don't have a corresponding version for \mintinline or \inputminted.

This usually works for julia code, where the @ would have a red box around it

\begin{minted}[escapeinside=||]{julia}
|@|. a .+ b
\end{minted}


If you use | in your code, you can change the escape character, e.g.

\begin{minted}[escapeinside=??]{julia}
?@?. a .+ b
\end{minted}