[Tex/LaTex] Minted red box around greek characters

minted

When using Minted i get a red box around greek characters
Annoying 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}
def add(α, β):
    return α + β
\end{minted}
\end{document}

Output of minimal working example

edit: I am using xelatex

Best Answer

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}
def add(α, β):
    return α + β
\end{minted}
\end{document}

\end{document}

enter image description here

Here's the patch also for \inputminted:

\begin{filecontents*}{\jobname.py}
def add(α, β):
    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}
def add(α, β):
    return α + β
\end{minted}

\inputminted{python}{\jobname.py}

\end{document}

enter image description here

Related Question