4

In the page 10 of the following document I define a label. When I give a reference to the page number of this label in the following page, the number is not shown properly. The number appears as 01 instead of 10. Is there a way to solve this problem?

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

\begin{document}
\selectlanguage{farsi} 
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\newpage
$\ $
\label{page10}
\newpage
\pageref{page10}

\end{document}

Edited: This question is related to my previous question Problem with theorem's numbering when using Arabi package

In that situation the problem was solved by putting \renewcommand\thethm{\revarabic{thm}} after defining \revarabic. In the current situation I tried to mimicking the previous solution by putting the following without success

\renewcommand\thepageref[1]{\revarabic{\pageref[#1]}} (makes error)

\renewcommand\pageref[1]{\revarabic{\pageref[#1]}} (makes error)

\renewcommand\thepage{\revarabic{page}} (solves the problem with \pageref by but makes another inconvenience: now the number of the page 10 becomes 01)

3
  • looks like the same problem reported as Problem with theorem's numbering when using Arabi package Commented Nov 12, 2014 at 20:54
  • @barbarabeeton in the problem which you provided a link, egreg solved the problem by putting \renewcommand\thethm{\revarabic{thm}} after defining \revarabic. In this situation what I should put?
    – Name
    Commented Nov 12, 2014 at 21:05
  • hmm. i didn't realize that problem was also submitted by you. unfortunately, applying that solution isn't quite as straightforward as i thought, although i'm sure the approach is in general the correct one. i'll keep trying, although i hope that egreg will see this problem and respond. Commented Nov 12, 2014 at 21:41

1 Answer 1

4

If the writing direction is always right-to-left when calling \pageref, this will do.

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

\ExplSyntaxOn
% the following is from the other answer, not really needed here
\DeclareExpandableDocumentCommand{\revarabic}{m}
 {
  \tl_reverse:f { \arabic{#1} }
 }
\cs_generate_variant:Nn \tl_reverse:n { f }

% the command needed here
\NewDocumentCommand{\reversed}{m}
 {
  \tl_reverse:n { #1 }
 }
\ExplSyntaxOff

% patch \label so that it writes \thepage (expanded) as argument to \reversed
\patchcmd{\label}{\thepage}{\reversed{\thepage}}{}{}

\begin{document}
\pageref{page10}
% generate nine pages
\count255=0 \loop\ifnum\count255<9 \advance\count255 by 1 \null\newpage\repeat
% on the tenth put a label    
\null\label{page10}\newpage

\end{document}

I don't know arabi, but probably it has some switch that can enable the reversing of the argument only if the write direction is right-to-left.

Here's the version without xparse:

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

\makeatletter
% the following is from the other answer, not really needed here
\def\revarabic#1{%
  \expandafter\num@reverse\expandafter{\romannumeral-`Q\arabic{#1}}%
}
% the command needed here
\protected\def\reversed#1{\num@reverse{#1}}

% the auxiliary commands
\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

% patch \label so that it writes \thepage (expanded) as argument to \reversed
\patchcmd{\label}{\thepage}{\reversed{\thepage}}{}{}

\begin{document}
\pageref{page10}
% generate nine pages
\count255=0 \loop\ifnum\count255<9 \advance\count255 by 1 \null\newpage\repeat
% on the tenth put a label    
\null\label{page10}\newpage

\end{document}
1
  • Thank you very much, I confirm that your solution perfectly works.
    – Name
    Commented Nov 16, 2014 at 9:57

You must log in to answer this question.

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