4

When I use a theorem style environment with Arabi package, the numbering become corrupted just after the numbers with two digits start.

Here an example. The number of the last one should be 10 but it shows 01.

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

\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{exer}[thm]{تمرین}
\theoremstyle{plain}

\begin{document}
\selectlanguage{farsi}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\end{document}
1

1 Answer 1

4

The number is of printed backwards, so we want to reverse it:

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

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

\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{exer}[thm]{تمرین}
\theoremstyle{plain}
\renewcommand\thethm{\revarabic{thm}}

\begin{document}
\selectlanguage{farsi}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\end{document}

enter image description here

Here is a version that doesn't use expl3; the macro is the same as in this answer of mine

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

\makeatletter
\def\revarabic#1{%
  \expandafter\num@reverse\expandafter{\romannumeral-`Q\arabic{#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}%
}
\makeatother


\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{exer}[thm]{تمرین}
\theoremstyle{plain}
\renewcommand\thethm{\revarabic{thm}}

\begin{document}
\selectlanguage{farsi}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\end{exer}
\begin{exer}\label{x}\end{exer}

\ref{x}
\end{document}

I added a \label to show the reference is correct.

4
  • when I compile the file I get the following error: ERROR: Undefined control sequence. --- TeX said --- l.13 \cs_generate_variant:Nn \tl_reverse:n { f }
    – Name
    Oct 10, 2014 at 10:56
  • @Name You have an outdated TeX system. I'll add later a version independent on expl3, but you should upgrade your TeX distribution anyway.
    – egreg
    Oct 10, 2014 at 10:59
  • I would be really grateful if you could provide a version independent form expl3.
    – Name
    Oct 10, 2014 at 11:09
  • @Name I added it and also fixed the expl3 version.
    – egreg
    Oct 10, 2014 at 12:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .