21

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

  • Can you please add a minimal example of code? – egreg Dec 11 '16 at 16:12
  • 1
    You get this behaviour, too, if you use German umlauts (ä, ö, ü). Is there a "real" solution yet? – elementzero23 May 7 '18 at 15:13
  • 1
    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
24

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

|improve this answer|||||
  • 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
  • !input minted causing problems – Kim Petersen Dec 11 '16 at 17:31
  • 3
    @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
  • 1
    @IvoLooser The code simply disables \fcolorbox inside minted snippets. – egreg Jan 29 '17 at 18:53
6

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}

|improve this answer|||||
3

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

|improve this answer|||||
  • Why re-adding the code when egreg already provided the same solution for the inline variant? – epR8GaYuh Feb 11 at 8:44
0

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}
def add(α, β):
    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.

|improve this answer|||||
0

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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.