1

I want to add some python code using the minted package to my latex file. I used

\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
A @ B
\end{minted}

which worked until now that I have some @ in my code (I am new here and don't know how to add the compiled version). The @ will display with a red box around them. Does someone know how to get rid of this red box?

1
  • 1
    Hi, welcome. Take a screenshot of the PDF and paste into your answer (or click the button to add images) to show output. – Torbjørn T. Aug 25 '20 at 22:17
1

The python lexer thinks the syntax A @ B is an error. Instead you can use the python3 lexer, which does accept it:

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
%%% python3 instead of python
{python3}
A @ B
\end{minted}
\end{document}

enter image description here

4
  • The comment %%% python3 instead of python generates an error: ! FancyVerb Error: Extraneous input "%%% python3 instead of python" between \begin{minted}[<key=value>] and line end I had to delete it ito successfully complete the compilation. – AndréC Aug 26 '20 at 7:25
  • Ah yes, I added that after I compiled myself :) it was intended as extra clarification. If the comment is above the line then it works fine, I edited my answer. – Marijn Aug 26 '20 at 7:56
  • Indeed, there it compiles. – AndréC Aug 26 '20 at 8:04
  • Thank you very much, worked perfectly – JD. Aug 26 '20 at 10:31
1

One more solution I found is to change the style of minted to something that does not show errors. Go to https://pygments.org/demo/#try and try the different styles for the code. The style "xcode" for example would work in this case. Then just type

\usemintedstyle{xcode}

or input any other style.

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.