I'm using minted
to highlight code in Python. In some cases I want to mix code with output that the user will see. This gives me the red syntax error boxes, for example like so:
And sometimes it gives me no error but I would like to turn off the highlighting (second line):
So what I would like to know if it's possible to turn off the highlighting for a few lines but at the same time keeping the options such as the line numbering and background.
MWE:
\documentclass{article}
\usepackage{minted}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\newminted{python3}{bgcolor=bg, linenos=true, tabsize=4}
\begin{document}
I want lines 2 and 4 not to be highlighted but still keep the background and line numbering.
\begin{python3code}
>>> type(3.14)
<class 'float'>
>>> print(name)
NameError: name 'name' is not defined
\end{python3code}
\end{document}
Edit: To clarify: There are lines that I want highlighted that start with >>>
and there are lines I want highlighted which don't start with >>>
. There are also lines that I don't want highlighting for. So the default should be that it highlights the line but that I can add an exception to some lines.
Best Answer
The short and the long of this is: write a special lexer. But you’re in luck, it already exists, just use
pycon
as the language.