Any help please for this message error?

! Package Listings Error: direction textdirection unknown.

I'm using polyglossia, and getting this error after updating to texlive 2018.

I managed to limit the error in tcolorbox package in preambule. Here is a simple code that results the error:

% !TeX TS-program = xelatex
\documentclass[12pt,a4paper]{article}

\usepackage{xcolor}
\colorlet{mygray}{gray!6!white}

\usepackage[most]{tcolorbox}

\newtcolorbox{myindex}{ %somthing wrong happens here
arc=2mm,
colback=white,
}

\usepackage{fontspec}
\setmainfont[Scale=1.15]{Amiri}

\usepackage{polyglossia}
\setmainlanguage[locale=morocco]{arabic}

\begin{document}
عربي
\end{document}
  • Make a complete, small example that demonstrates the error and can be used for tests. Tell also how you are compiling (xelatex or lualatex?). – Ulrike Fischer Sep 14 at 7:09
up vote 3 down vote accepted

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.