# Reversed numbers with bidi and mathspec

I've recently updated from Debian 'jessie' to Debian 'stretch', and have started having a problem with numbers being formatted backwards when using the bidi package in conjunction with the mathspec package. Here's a MWE:

\documentclass{article}
\usepackage{mathspec}
\usepackage{bidi}
\begin{document}
Per 2.7.1 of the RFC.
\end{document}


On Debian 'jessie', when built with xelatex, this produces "Per 2.7.1 of the RFC." But on 'stretch' this gives "Per 1.7.2 of the RFC."

Any suggestions of how to fix this?

• If I compile with bidi version 19.1 (TeX Live 2015), the numbers are OK; with version 19.6 (TL 2016) they're reversed. – egreg Sep 8 '16 at 16:33

The bidi package added in version 19.6 (the current one) the following code:

\newcount\bidi@digits
\XeTeXinterchartokenstate=\@ne
\newXeTeXintercharclass\bidi@digits@charclass
\newXeTeXintercharclass\bidi@dot@charclass
\XeTeXcharclass \. \bidi@dot@charclass
\bidi@digits=\0 \loop \XeTeXcharclass \bidi@digits \bidi@digits@charclass \ifnum\bidi@digits<\9
\bidi@digits=\۰ \loop \XeTeXcharclass \bidi@digits \bidi@digits@charclass \ifnum\bidi@digits<\۹
\XeTeXinterchartoks \bidi@digits@charclass  \bidi@dot@charclass = {\DigitsDotInterCharToks}
\XeTeXinterchartoks \bidi@dot@charclass  \bidi@digits@charclass = {\DigitsDotInterCharToks}
\newcommand*{\DigitsDotInterCharToks}{\if@Latin\else\char"200F \fi}


This has the consequence that when XeTeX finds a digit followed by a period or conversely, it issues U+200F RIGHT-TO-LEFT MARK unless \if@Latin is set to true. But it never uses either \@Latintrue or \@Latinfalse, leaving that to the user or to other packages.

The issue is not due specifically to mathspec, but appears as soon as you load fontspec and is similar in essence to Equation numbers are shown in reverse parentheses

The solution is the same:

\documentclass{article}

\usepackage{mathspec}
\usepackage{bidi}

\makeatletter
\AtBeginDocument{\@Latintrue}
\makeatother

\begin{document}

Per 2.7.1 of the RFC.

\end{document}


If you use polyglossia`, there should be no problem, as the package realizes direction changes in a different way.

• I did wonder whether it was related to the equation number issue, but was a bit confused by what the solution was. This works perfectly. Thanks. – richard Sep 8 '16 at 17:03