2

I want to make numbering in caption right-to-left. For example Change in the caption: شکل 01 to شکل 10.

The reason I want something like this is I am working with right-to-left language and I can make the numbers in document to show correctly using \LR but I have no control over caption numbers. So 10th caption will be something like Figure 01.

Here is my MWE to imply what I want. I tried to keep it as general as possible.

\documentclass{beamer}

\usepackage[persian]{babel}
\usepackage{caption}

\setbeamertemplate{caption}[numbered]

\setmainfont[Script=Arabic,Numbers=Arabic]{XB Zar}
\setsansfont[Script=Arabic,Numbers=Arabic]{XB Zar}

\begin{document}
        \begin{frame}
            \begin{figure}
                \caption{شکل \LR{1}}
                \caption{شکل \LR{2}}
                \caption{شکل \LR{3}}
                \caption{شکل \LR{4}}
                \caption{شکل \LR{5}}
                \caption{شکل \LR{6}}
                \caption{شکل \LR{7}}
                \caption{شکل \LR{8}}
                \caption{شکل \LR{9}}
                \caption{شکل \LR{10}}
            \end{figure}
        \end{frame}
\end{document}

I saw \renewcommand{\thefigure}{\textbf{\arabic{figure}}} change the caption numbering to bold so I thought something like \renewcommand{\thefigure}{\LR{\arabic{figure}}} should work, but it does not. Another thing that I taught of was to make a list of numbers in right format, so instead of Counter style, LaTeX follows my numbering style, but I'm not clearly that expert. Please use LuaLaTeX for typesetting.

Here is Persian.ldf for option persian to babel.

\ProvidesLanguage{persian}
       [2010/01/03 v0.3 Persian support for the babel system]

\LdfInit{persian}{captionspersian}

\ifx\l@persian\@undefined
  \@nopatterns{Persian}
  \adddialect\l@persian0
\fi

\addto\captionspersian{%
  \def\prefacename{\RL{پیشگفتار}}%
  \def\refname{\RL{منابع}}
  \def\abstractname{\RL{چکیده}}%
  \def\bibname{\RL{منبع}}%
  \def\chaptername{\RL{فصل}}%
  \def\appendixname{\RL{پیوست}}%
 %\def\contentsname{\RL{فهرست مطالب}}
  \def\contentsname{\RL{فهرست}}%
  \def\listfigurename{\RL{لیست تصاویر}}%
  \def\listtablename{\RL{لیست جدولها}}%
  \def\indexname{\RL{نمایه}}%
  \def\figurename{\RL{شکل}}%
  \def\tablename{\RL{جدول}}%
  \def\partname{\RL{قسمت}}%
  \def\enclname{\RL{المرفقات}}
  \def\ccname{\RL{رونوشت}}% <<
  \def\headtoname{\RL{به}}
  \def\pagename{\RL{صفحه}}%
  \def\seename{\RL{ببینید}}%
  \def\alsoname{\RL{هم‌چنین ببینید}}%
  \def\proofname{\RL{برهان}}% for AMS-\LaTeX
  \def\glossaryname{\RL{واژه‌نامه}}%<<
  }

\AtEndOfPackage{
\RequirePackage{luatextra}
\RequirePackage{ifluatex}
%\luatexRequireModule{persian}

\ifluatex
\else
   \newlinechar`\^^J
   \typeout{^^JTo avoid this error message,^^J%
     run LuaTeX engine instead of regular TeX.^^J}
   \errmessage{[Persian Support Error: use LuaTeX engine}%
\fi

\@switch@dir{TRT}\@rltrue
}


\def\@page@dir#1{\luatexpagedir #1}
\def\@body@dir#1{\luatexbodydir #1}
\def\@para@dir#1{\luatexpardir #1}
\def\@text@dir#1{\luatextextdir #1}
\def\@math@dir#1{\luatexmathdir #1}
\def\@switch@dir#1{\@page@dir{#1}\@body@dir{#1}\@para@dir{#1}\@text@dir{#1}}


\newif\if@rl
\def\LR#1{{\@rlfalse\@text@dir{TLT}#1}}
\def\RL#1{{\@rltrue\@text@dir{TRT}#1}}
\def\setRL{\@rltrue\@switch@dir{TRT}}
\def\setLR{\@rlfalse\@switch@dir{TLT}}
\newenvironment{rltext}{\@rltrue\@para@dir{TRT}\@text@dir{TRT}}{}
\newenvironment{lrtext}{\@rlfalse\@para@dir{TLT}\@text@dir{TLT}}{}


\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      \if@rl{\@text@dir{TRT}#7}%
      \else{\@text@dir{TLT}#7}\fi}%
  \else
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}}


% BEGIN TABULAR

% my "buggy" code
%\def\@tabular{\leavevmode \hbox \bgroup \if@rl\@math@dir{TRT}\fi $\let\@acol\@tabacol
%   \let\@classz\@tabclassz
%   \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray}

% the follwing from Vafa
\def\@array[#1]#2{%
  \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
  \bgroup
  \setbox\@arstrutbox\hbox{%
    \vrule \@height\arraystretch\ht\strutbox
           \@depth\arraystretch \dp\strutbox
           \@width\z@}%
  \@mkpream{#2}%
  \edef\@preamble{%
    \ialign \noexpand\@halignto
      \bgroup \@arstrut \@preamble \tabskip\z@skip \cr}%
  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
  \let\tabularnewline\\%
    \let\par\@empty
    \let\@sharp##%
    \set@typeset@protect
    \lineskip\z@skip\baselineskip\z@skip
    \ifhmode \@preamerr\z@ \@@par\fi
  \if@rl\@text@dir{TRT}\fi
    \@preamble}

% swap right and left
\def\@testpach#1{\@chclass \ifnum \@lastchclass=\tw@ 4 \else
    \ifnum \@lastchclass=3 5 \else
     \z@ \if #1c\@chnum \z@ \else
                              \if \if@rl#1r\else#1l\fi\@chnum \@ne \else
                              \if \if@rl#1l\else#1r\fi\@chnum \tw@ \else
          \@chclass \if #1|\@ne \else
                    \if #1@\tw@ \else
                    \if #1p3 \else \z@ \@preamerr 0\fi
  \fi  \fi  \fi  \fi  \fi  \fi
\fi}
% END TABULAR

\newif\if@rlmath

\def\@my@startmath{\if@rl\if@rlmath\bgroup\@math@dir{TRT}\fi\fi$}
\def\@my@stopmath{$\if@rl\if@rlmath\egroup\fi\fi}
\def\@my@startdisplaymath{\if@rl\if@rlmath\bgroup\@math@dir{TRT}\fi\fi$$}
\def\@my@stopdisplaymath{$$\if@rl\if@rlmath\egroup\fi\fi}
\def\({\relax\ifmmode\@badmath\else\@my@startmath\fi}
\def\){\relax\ifmmode\ifinner\@my@stopmath\else\@badmath\fi\else \@badmath\fi}
\def\[{%
   \relax\ifmmode
      \@badmath
   \else
      \ifvmode
         \nointerlineskip
         \makebox[.6\linewidth]{}%
      \fi
      \@my@startdisplaymath%%$$ BRACE MATCH HACK
   \fi
}
\def\]{%
   \relax\ifmmode
      \ifinner
         \@badmath
      \else
         \@my@stopdisplaymath%%$$ BRACE MATCH HACK
      \fi
   \else
      \@badmath
   \fi
   \ignorespaces
}

\def\@seccntformat#1{{%
\if@rl%
  \@text@dir{TRT}%
\else%
  \@text@dir{TLT}%
\fi%
\csname the#1\endcsname\quad}}


\def\datepersian{\def\today{\luadirect{tex.sprint(jalali.today())}}}

\ldf@finish{persian}

\endinput

The Problem with caption numbering

4
  • 2
    Welcome to TeX.SX! It would be better if you show the context using right-to-left writing.
    – egreg
    Jun 30, 2015 at 16:26
  • I fixed the issue. I taught it will be more general by using left-to-right writing and using article class. I apologize for any inconvenient.
    – user81104
    Jun 30, 2015 at 16:57
  • Sorry, but the option persian to babel is unknown.
    – egreg
    Jun 30, 2015 at 17:01
  • You are right. I should attach persian.ldf file to the question.
    – user81104
    Jun 30, 2015 at 17:12

1 Answer 1

3

Here's a way:

\documentclass{beamer}

\usepackage[persian]{babel}
\usepackage[compatibility=false]{caption}

\setbeamertemplate{caption}[numbered]

\DeclareCaptionLabelFormat{rlnumber}{#1 \LR{#2}}
\captionsetup{labelformat=rlnumber}

\setmainfont[Script=Arabic]{XB Zar}
\setsansfont[Script=Arabic,Numbers=Arabic]{XB Zar}

\begin{document}

\begin{frame}

\setcounter{figure}{8}
\begin{figure}

\caption{شکل \LR{9}}
\caption{شکل \LR{10}}

\end{figure}

\end{frame}

\end{document}

enter image description here

2
  • But this method does not work when you have subfigures. Because it change the whole numbering to \LR and subcaptions like شکل 10-1 would become شکل 1-10.
    – user81104
    Jul 1, 2015 at 7:05
  • @user81104 I can answer the questions you make. This is a completely different topic.
    – egreg
    Jul 1, 2015 at 7:21

You must log in to answer this question.

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