# Conflict with unicode-math and listings

\documentclass{article}
\usepackage{unicode-math}
\usepackage{listings}
\usepackage{fancyvrb}

\begin{document}
\lstset{fancyvrb}
\begin{Verbatim}[commandchars=\\\{\}]
\pm
\end{Verbatim}
\end{document}


This is the minimal code. And I get the error "Improper alphabetic constant".

PS: I need \lstset{fancyvrb}.

• A warm welcome to TeX.SE! – A Feldman Apr 4 '16 at 4:54

\pm is internally defined as "the character ±". In the listings code \pm is used in an \lccode assigment but its value is much too large. You can avoid the problem by converting \pm to a macro. This is handled differently by listings. E.g.

\documentclass{article}
\usepackage{unicode-math}
\usepackage{listings}
\usepackage{fancyvrb}

\AtBeginDocument{%
\let\ORIpm\pm
\renewcommand\pm{\ORIpm}}

\begin{document}

\lstset{fancyvrb}
\begin{Verbatim}[commandchars=\\\{\}]
\pm
\end{Verbatim}

\end{document}