17

I'm trying to include some Erlang code samples in a document using the minted package which include the ? operator to denote a message being received from a process. The code

\documentclass{minimal}
\usepackage{minted}
\begin{document}
\begin{minted}{erlang}
A ! Msg1,
receive
    A ? Msg2 ->
        ok
\end{minted}
\end{document}

produces the following output:

LaTeX output

with the ? operator being treated differently to the ! operator, and having a red box drawn around it. How can I remove this box and have it treated in the same way as the ! operator? I presumed pygmentize would treat them similarly in this context. Is there any way I can check that this assertion is true, and if it's not, modify how pygmentize treats it accordingly?

8

Normally the red box indicates syntax errors in your source code (here Erlang). However, the language specific parsers used by Pygments (which in turn is used by minted) are incomplete. Apparently the Erlang parser cannot cope with the question mark as an identifier.

The best course of action is to file a bug with the maintainer of the Erlang lexer, Jeremy Thurgood or the Pocoo team who maintain Pygments.

Or you can fix the error yourself in your local Pygments installation by modifying pygments/lexers/functional.py – the error is probably just a missing question mark on line 659.

  • Thanks; that worked a treat - it was that line and simply adding an escaped ? term did the trick nicely. I'll email Jeremy. – Edd Mar 29 '11 at 8:10
  • where is that file in a mac? – ncmathsadist Oct 18 '16 at 21:33
18

In my case, the solutions above does not work. I was trying to print the following Python 3 line, using minted 2.1:

>>> print("Instalação!")
Instalação!

I ended by disable the color boxes around "çã" e "!", by inserting in the preamble:

\AtBeginEnvironment{minted}{%
  \renewcommand{\fcolorbox}[4][]{#4}}

This solution I found here.

  • 1
    The only one solution that worked for me despite the poor vote number. Thanks a lot ! – Metal3d May 27 '16 at 11:50
  • 2
    This one didnćt work for me because I was importing source code from an external file. Simply dropping the first line seems to work: \renewcommand{\fcolorbox}[4][]{#4}. Not sure if there are any side-effects for this, though. – Lazar Ljubenović Jan 30 '17 at 10:52
  • @LazarLjubenović The side-effect would be that the box is dropped for everything, not just minted environments. If you don't have any others that you do want, it's probably fine; scoping it's just a bit neater. – OJFord Jun 19 '17 at 11:15
  • Problem solved. Great, +1. – ncmathsadist Feb 5 '18 at 17:32
12

You may also override the pygments error command like this:

\expandafter\def\csname PY@tok@err\endcsname{}

That's not exactly the better solution, because it will hide all syntax errors of your code, but works perfectly for me. I still don't know what that line above means exactly, it just works.

I discover that by running pygments on command line and reading the output generated, like this (in my case I was working with html instead of Erlang):

pygmentize -f latex -O full -l html test.html
  • 5
    I found that the \expandafter invocation needs to not be in the preamble. – Paul Stansifer Mar 29 '13 at 17:14
9

I'm using minted v2.0. Adding

% no red boxes on parser error:
\makeatletter
\expandafter\def\csname PYGdefault@tok@err\endcsname{\def\PYGdefault@bc##1{{\strut ##1}}}
\makeatother

to preambule works.

Expecting errors in cached files leads that \PYGdefault{err} is issued on error. It's definition is found in default.pygstyle on cache dir. Redefining that in preambule solves the problem.

3

Choose a minted style that do not draw red boxes, like xcode

With this command :

\usemintedstyle{xcode}

Actually you will style have the \PYG{err} so I am not sure that you will get ? treated as ! but at least you do not have the red boxes, and this without any hack.

-1
  1. Open the file default.pygstyle;

  2. Erase the line with the string PYGdefault@tok@erre

It's enough!

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.