3

Unfortunately I have a similar problem as in \pageref dosen't properly show the page number when using arabi package. When I use the command \cite, the digits are reversed. In fact I am not able to use the same solution for pageref. If I put \cite{ten} between $ $, i.e., using $\cite{ten}$ my problem for \cite is solved but not for the bibitems. I suppose that it is not the canonical way of solving this problem.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE,OT1]{fontenc}
\usepackage[farsi,english,arabic]{babel}

\begin{document}
\selectlanguage{farsi} 

\cite{ten}

\begin{thebibliography}{MM}
\bibitem{one}
\bibitem{two}
\bibitem{three}
\bibitem{four}
\bibitem{five}
\bibitem{six}
\bibitem{seven}
\bibitem{eight}
\bibitem{nine}
\bibitem{ten}
\bibitem{eleven}
\bibitem{twelve}
\end{thebibliography}
\end{document}
Name
  • 2,816

2 Answers2

3

The problem is always the same: numbers are reversed.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE,OT1]{fontenc}
\usepackage[english,arabic,farsi]{babel}

\usepackage{xparse}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_reverse:n { f }
\DeclareExpandableDocumentCommand{\revarabic}{m}
 {
  \tl_reverse:f { \arabic{#1} }
 }
\DeclareExpandableDocumentCommand{\reverse}{m}
 {
  \tl_reverse:f { #1 }
 }
\ExplSyntaxOff

\makeatletter
\renewcommand\@bibitem[1]{\item\if@filesw \immediate\write\@auxout
   {\string\bibcite{#1}{\revarabic{enumiv}}}\fi\ignorespaces}
\renewcommand\@biblabel[1]{[\reverse{#1}]}
\makeatother

\begin{document}

\cite{ten}

\begin{thebibliography}{MM}
\bibitem{one}
\bibitem{two}
\bibitem{three}
\bibitem{four}
\bibitem{five}
\bibitem{six}
\bibitem{seven}
\bibitem{eight}
\bibitem{nine}
\bibitem{ten}
\bibitem{eleven}
\bibitem{twelve}
\end{thebibliography}
\end{document}

enter image description here

Here's the version without expl3.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE,OT1]{fontenc}
\usepackage[english,arabic,farsi]{babel}

\makeatletter
\def\revarabic#1{%
  \expandafter\num@reverse\expandafter{\romannumeral-`Q\arabic{#1}}%
}
\def\reverse#1{%
  \expandafter\num@reverse\expandafter{\romannumeral-`Q#1}%
}
\def\num@reverse#1{\num@rev#1\num@rev@a\num@rev@b}
\def\num@rev#1#2\num@rev@a#3\num@rev@b{%
  \if\relax\detokenize{#2}\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {#1#3}%
  {\num@rev#2\num@rev@a#1#3\num@rev@b}%
}
\renewcommand\@bibitem[1]{\item\if@filesw \immediate\write\@auxout
   {\string\bibcite{#1}{\revarabic{enumiv}}}\fi\ignorespaces}
\renewcommand\@biblabel[1]{[\reverse{#1}]}
\makeatother

\begin{document}

\cite{ten}

\begin{thebibliography}{MM}
\bibitem{one}
\bibitem{two}
\bibitem{three}
\bibitem{four}
\bibitem{five}
\bibitem{six}
\bibitem{seven}
\bibitem{eight}
\bibitem{nine}
\bibitem{ten}
\bibitem{eleven}
\bibitem{twelve}
\end{thebibliography}
\end{document}
egreg
  • 1,121,712
1

By using the idea from two answers https://tex.stackexchange.com/a/39254/39306 and https://tex.stackexchange.com/a/214575/39306, I came up with the following solution which is still unsatisfactory as I use $$'s.

\makeatletter
\renewcommand\@bibitem[1]{\item\if@filesw \immediate\write\@auxout
   {\string\bibcite{#1}{$\theenumiv$}}\fi\ignorespaces}
\renewcommand\@biblabel[1]{[$#1$]}
\makeatother
Name
  • 2,816