UPDATE
With version 33.2 of bidi
, released 2018/09/15, the issue has been solved. Note that listings
version 1.7, released 2018/09/02 (or later) has to be used or the issue would present itself again.
Original answer
The error is in the helper file listings-xetex-bidi.def
where the starting code is
\lst@Key{captiondirection}{textdirection}{%
\lstKV@SwitchCases{#1}%
{textdirection&\\%
RTL&\chardef\bidi@lst@caption@direction\@ne\\%
LTR&\chardef\bidi@lst@caption@direction\z@%
}{\PackageError{Listings}{direction #1 unknown}\@ehc}}
\lst@Key{captionscript}{textscript}{%
\lstKV@SwitchCases{#1}%
{textscript&\\%
latin&\chardef\bidi@lst@caption@script\@ne\\%
nonlatin&\chardef\bidi@lst@caption@script\z@%
}{\PackageError{Listings}{direction #1 unknown}\@ehc}}
which is wrong. The \lstKV@SwitchCases
macro wants a different delimiter than &
; the correct code should be
\lst@Key{captiondirection}{textdirection}{%
\lstKV@SwitchCases{#1}%
{textdirection:\\%
RTL:\chardef\bidi@lst@caption@direction\@ne\\%
LTR:\chardef\bidi@lst@caption@direction\z@%
}{\PackageError{Listings}{direction #1 unknown}\@ehc}}
\lst@Key{captionscript}{textscript}{%
\lstKV@SwitchCases{#1}%
{textscript:\\%
latin:\chardef\bidi@lst@caption@script\@ne\\%
nonlatin:\chardef\bidi@lst@caption@script\z@%
}{\PackageError{Listings}{direction #1 unknown}\@ehc}}
Note that :
should go instead of &
.
To the bidi
author's discharge, the change in syntax is quite recent (just a few days) and in the previous versions of listings
the delimiter used to be &
. See https://sourceforge.net/p/persian-tex-dist/tickets/9/
Indeed, a minimal example showing the error is
\documentclass[12pt,a4paper]{article}
\usepackage{listings}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[locale=morocco]{arabic}
\setmainfont[Scale=1.15]{Amiri}
\begin{document}
عربي
\end{document}
It appears in your document because the most
option to tcolorbox
loads listings
. If you don't need listings
just avoid loading it and issue
\usepackage[many]{tcolorbox}
manually loading the possible missing libraries.
If you do need listings
there's little to do except to copy listings-xetex-bidi.def
into your working directory and change the six appearances of &
into :
as shown above, at least until the wrong code is fixed in the bidi
distribution.