Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
How to get devanagari numerals in latex or xetex

I am using XeLaTeX (XeTeX, Version 3.1415926-2.4-0.9998 on TeX Live 2012/W32TeX). I want Devanagari (Indic) page numbers in my own custom font. I could use \pagenumbering{skt} or \pagenumbering{devanagari} in skt or devanagari packages but they provide a standard font.

I wrote my own command using \StrSubtitute in xstring package to convert Arabic numerals to Devanagari and used fancyhdr page style to invoke the command in page footer. Below is a minimal working example

\documentclass[14pt]{article}
\usepackage{fontspec}
\usepackage{lipsum}
\setmainfont[Script=Devanagari]{Arial Unicode MS}
\usepackage{fancyhdr}
\usepackage{xstring}
\renewcommand\thepage{\arabic{page}}
\newcommand{\arabictodevnag}[1]%
{%
  \StrSubstitute{#1}{0}{०}[\num]
  \StrSubstitute{\num}{1}{१}[\num]
  \StrSubstitute{\num}{2}{२}[\num]
  \StrSubstitute{\num}{3}{३}[\num]
  \StrSubstitute{\num}{4}{४}[\num]
  \StrSubstitute{\num}{5}{५}[\num]
  \StrSubstitute{\num}{6}{६}[\num]
  \StrSubstitute{\num}{7}{७}[\num]
  \StrSubstitute{\num}{8}{८}[\num]
  \StrSubstitute{\num}{9}{९}
}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\cfoot{\fancyplain{}{\Large \arabictodevnag{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\tableofcontents
\pagebreak
\section{One}
\lipsum[1-8]
\pagebreak
\end{document}

This works fine for all pages except for page numbers in Table of Contents. I want Devanagari page numbers Table of Contents also, but I could not find a way to figure this out. I tried redefining \thepage as follows but it does not work.

\renewcommand\thepage{\arabictodevnag{page}}   % Does not work

I think I need to first convert page value to Arabic and then pass it on to my \arabictodevnag command. Any pointers?

share|improve this question
add comment

marked as duplicate by egreg, Kurt, Thorsten, Guido, lockstep Nov 17 '12 at 17:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 3 down vote accepted

You can define \thepage so it is safe to use in contents and headers directly:

enter image description here

\documentclass[14pt]{article}
\usepackage{fontspec}
\usepackage{lipsum}
\setmainfont[Script=Devanagari]{Arial Unicode MS}
\usepackage{fancyhdr}
\usepackage{xstring}
\renewcommand\thepage{\Devnag{page}}
\DeclareRobustCommand\Devnag[1]{\expandafter\arabictodevnag\expandafter{\the\csname c@#1\endcsname}}
\newcommand{\arabictodevnag}[1]%
{%
  \StrSubstitute{#1}{0}{०}[\num]
  \StrSubstitute{\num}{1}{१}[\num]
  \StrSubstitute{\num}{2}{२}[\num]
  \StrSubstitute{\num}{3}{३}[\num]
  \StrSubstitute{\num}{4}{४}[\num]
  \StrSubstitute{\num}{5}{५}[\num]
  \StrSubstitute{\num}{6}{६}[\num]
  \StrSubstitute{\num}{7}{७}[\num]
  \StrSubstitute{\num}{8}{८}[\num]
  \StrSubstitute{\num}{9}{९}
}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\cfoot{\fancyplain{}{\Large \thepage}}
\renewcommand{\headrulewidth}{0pt}
\tableofcontents
\pagebreak
\section{One}
\lipsum[1-8]
\pagebreak
\end{document}\documentclass[14pt]{article}
\usepackage{fontspec}
\usepackage{lipsum}
\setmainfont[Script=Devanagari]{Arial Unicode MS}
\usepackage{fancyhdr}
\usepackage{xstring}
\renewcommand\thepage{\arabic{page}}
\newcommand{\arabictodevnag}[1]%
{%
  \StrSubstitute{#1}{0}{०}[\num]
  \StrSubstitute{\num}{1}{१}[\num]
  \StrSubstitute{\num}{2}{२}[\num]
  \StrSubstitute{\num}{3}{३}[\num]
  \StrSubstitute{\num}{4}{४}[\num]
  \StrSubstitute{\num}{5}{५}[\num]
  \StrSubstitute{\num}{6}{६}[\num]
  \StrSubstitute{\num}{7}{७}[\num]
  \StrSubstitute{\num}{8}{८}[\num]
  \StrSubstitute{\num}{9}{९}
}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\cfoot{\fancyplain{}{\Large \arabictodevnag{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\tableofcontents
\pagebreak
\section{One}
\lipsum[1-8]
\pagebreak
\end{document}
share|improve this answer
    
Thanks a lot, @DavidCarlisle. But another question now. The above works as long as hyperref package is not included. If I add the following to the preamble: \hypersetup{bookmarksnumbered,pdfstartview={FitH},urlcolor=cyan,linkcolor=blue}‌​, there is a conflict and XeLaTex complains Undefined control sequence. \arabictodevnag I tried \protect{\tableofcontents} but that too fails. –  user22209 Nov 17 '12 at 0:15
    
ah that could be fixed I'll have to remind myself what hyperref is doing there. But I don;t think pdf bookmarks can use those numbers, can they? do you want arabic numbers in the bookmarks? –  David Carlisle Nov 17 '12 at 9:47
    
The bookmarks would have the chapter names - I do not have numbers in the bookmarks. I plan to use \setcounter{secnumdepth}{-1} with bookmarks like \section[\texorpdfstring{\protect{\Large तृतीयः\ सर्गः\ -\ गुरूपसत्तिः}}{III. Gurūpasattiḥ}]{\protect{{\huge तृतीयः\ सर्गः}}}. So the chapters would not be numbered and yet included in table of contents with a different text under PDF bookmarks without arabic or devanagari numbers. I read that hyperref conflicts with many macros and packages, but my familiarity with latex code is not enough to understand how to resolve them. –  user22209 Nov 17 '12 at 12:33
    
OK I'll look later you shouldn't really be putting \Large in a section heading though, if you need large headings that should be the definition of the heading, and never follow \protect by a { bad things will definitely happen if you do that:-) –  David Carlisle Nov 17 '12 at 12:46
    
I made the preamble end in \usepackage{hyperref}\hypersetup{bookmarksnumbered,pdfstartview=FitH},urlcolor=‌​cyan,linkcolor=blue}‌​\begin{document} and got no error. If you get an error in a document check you have removed all uses of \protect{ which will always generate errors and then make an example that shows the problem in a new question. –  David Carlisle Nov 17 '12 at 13:03
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.