0

I want to use a special character(U+2225) with minted for Haskell syntax:

\begin{document} 
$\parallel$ this works as expected

\begin{minted}{haskell} regardless which method I use in here I cannot get the paralell symbol to accure... \end{minted}

\end{document}

I allso experimentated with \DeclareUnicodeCharacter but couldn't get it to work... Any suggestions?

1 Answers1

0

It is not entirely clear what your experiments with \DeclareUnicodeCharacter have been so far, but the following works with pdflatex:

\documentclass{article}
\DeclareUnicodeCharacter{2225}{$\parallel$}
\usepackage{minted}
\begin{document} 
$\parallel$ this works as expected

\begin{minted}{haskell} parseOr :: Parser Operator parseOr = Or <$> oneOf "v+∥" \end{minted}

\end{document}

Result:

enter image description here

When you use ∥ outside of a string minted thinks that there is a syntax error and will display a red box around the character. You can switch this off by escaping to LaTeX before you print the symbol:

\documentclass{article}
\usepackage{minted}
\DeclareUnicodeCharacter{2225}{$\parallel$}
\begin{document} 
$\parallel$ this works as expected

\begin{minted}[escapeinside=##]{haskell} parseOr :: Parser Operator parseOr = Or <$> oneOf "v+∥"

doSomething = doFirst #∥# doSecond \end{minted}

\end{document}

The problem here is that you need to find a character that you don't use anywhere in your code and that is allowed for escapeinside (basically only standard ASCII).

An alternative is to switch off the error boxes altogether:

\documentclass{article}
\usepackage{minted}
\DeclareUnicodeCharacter{2225}{$\parallel$}
\makeatletter
\AtBeginEnvironment{minted}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\makeatother
\begin{document} 
$\parallel$ this works as expected

\begin{minted}{haskell} parseOr :: Parser Operator parseOr = Or <$> oneOf "v+∥"

doSomething = doFirst ∥ doSecond \end{minted}

\end{document}

Result in both cases:

enter image description here

Source: Minted red box around greek characters.

Marijn
  • 37,699
  • this is working - but now the ∥ is surrounded with a red square – Thomas Meyer Feb 27 '22 at 15:31
  • that is probably because it is not allowed in Haskell at that position - or it is allowed but Minted thinks it is not. See https://tex.stackexchange.com/questions/343494/minted-red-box-around-greek-characters or https://tex.stackexchange.com/questions/424421/code-validation-in-minted-package-how-to-disable-it for example. I will make an edit to this post as well. – Marijn Feb 27 '22 at 16:18