This supposed to be a comment not an answer but since it is long, I could not submit it as a comment. David Carslie stated that
siunitx
and bidi
seem to be fighting over \everymath
bidi
does not work with \everymath
.
Joseph Wright said:
The problem here is not with siunitx
nor (really) with amsmath (I
think), but is with how bidi
sets out to modify the \text
command.
bidi
needs to modify \text
command the way it does for its RTL puprposes. It is siunitx
problem which is not bidi
-aware.
He also said:
What seems to be happening is that if only amstext is loaded, bidi
leaves the \text
command unmodified, and so standard behaviour is
seen.
I admit that bidi
should check for amstext
not amsmath
but that does not make any difference here.
He also said:
However, bidi
does check for amsmath
, and if it is loaded modifies
\text
to have definition
\text #1->\@@text {\if@Latin \else \beginR \fi #1\if@Latin \else \endR
\fi }
where \@@text
is the original \text
command. If you trace
through, it seems that \if@Latin
is set incorrectly here.
\if@Latin
is only a conditional that bidi
package provides so that packages like polyglossia
set it to false for non-RTL languages and set it to true for RTL languages. xepersian
makes extensive use of this conditional. On the other hand, as I said above \text
needs to be modified for RTL purposes so that it typesets text RTL in math mode.
He also said:
where \@@text
is the original \text
command. If you trace through, it
seems that \if@Latin
is set incorrectly here. So
\documentclass{article}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{bidi}
\csname @Latintrue\endcsname
\begin{document}
\text{Jk}
\end{document}
You are always making the conditional \if@LAtin
true which is not the purpose of bidi
package. For making it more clear, lets look at the following example:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xepersian}
\begin{document}
\[
1+2=3\qquad\text{این یک فرمول است.}
\]
\end{document}
As you can see, the text comes out RTL as it should. Let's see how \if@Latin
works:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xepersian}
\begin{document}
\[
1+2=3\qquad\text{این یک فرمول است.}
\]
\begin{latin}
\[
1+2=3\qquad\text{This is an equation.}
\]
\end{latin}
\end{document}
So now what is wrong with your example:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xepersian}
\csname @Latintrue\endcsname
\begin{document}
\[
1+2=3\qquad\text{این یک فرمول است.}
\]
\end{document}
The text comes out LTR which is obviously wrong. Hence the problem is not bidi
; the problem is siunitx
which is not bidi
-aware.
Conclusion: siunitx
needs to always output LTR SI units by using LTR \text
because even if it uses RTL \text
in RTL mode, the output would be RTL which is not right.