1

When attempting to use the minted package to highlight a piece of source code in the Mako templating language:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{minted}
\usemintedstyle{borland}

\begin{document}

\begin{minted}{mako}
<%inherit file='base'/>

% for i in range(5):
  ${i}
% endfor
\end{minted}
\end{document}

I find that the file='base' fragment is coloured red -- indicating an error. I suspect this is due to the underlying Pygments library having incomplete support for Mako (the code itself is 100% valid). What I am wondering is how I can redefine the error fragment to hide this.

2
  • 1
    If the fault is in the Pygments support for Mako, this is not a question about TeX and friends.
    – egreg
    Aug 9, 2015 at 21:09
  • @egreg: "What I am wondering is how I can redefine the error fragment to hide this." So accepting that we get bad output redefining the command that indicates a piece of text is an error. Aug 9, 2015 at 22:11

1 Answer 1

1

This is the .pygtex file that's produced:

\begin{Verbatim}[commandchars=\\\{\}]
\PYGborland{c+cp}{\PYGborlandZlt{}\PYGborlandZpc{}}\PYGborland{n+nb}{inherit} \PYGborland{err}{file=\PYGborlandZsq{}base\PYGborlandZsq{}}\PYGborland{c+cp}{/\PYGborlandZgt{}}

\PYGborland{c+cp}{\PYGborlandZpc{}} \PYGborland{k}{for} \PYGborland{n}{i} \PYGborland{o+ow}{in} \PYGborland{n+nb}{range}\PYGborland{p}{(}\PYGborland{l+m+mi}{5}\PYGborland{p}{):}
\PYGborland{x}{  }\PYGborland{c+cp}{\PYGborlandZdl{}\PYGborlandZob{}}\PYGborland{n}{i}\PYGborland{c+cp}{\PYGborlandZcb{}}
\PYGborland{c+cp}{\PYGborlandZpc{}}\PYGborland{k}{ endfor}
\end{Verbatim}

If you want to treat the part marked \PYGborland{err} like inherit, then you can make

\PYGborland@tok@err

equivalent to \PYGborland@tok@n+nb, that can be obtained only with \csname; with etoolbox it's easy.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{etoolbox}
\usepackage{minted}
\usemintedstyle{borland}

\csletcs{PYGborland@tok@err}{PYGborland@tok@n+nb}

\begin{document}

\begin{minted}{mako}
<%inherit file='base'/>

% for i in range(5):
  ${i}
% endfor
\end{minted}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .