1

In the MWE below, I get an error on \glsaddall when the default language of the document is Farsi, but not when it is English.

\documentclass{book}
\usepackage{polyglossia}
\usepackage[xindy]{glossaries}

\setdefaultlanguage[numerals=eastern]{farsi}
\setotherlanguage[variant=american]{english}

% the error goes away with this
%\setdefaultlanguage[variant=american]{english}
%\setotherlanguage[numerals=eastern]{farsi}

\setmainfont{Adobe Arabic}
\newfontfamily\englishfont{Charis SIL}
\newfontfamily\farsifont{Adobe Arabic}
\makeglossaries
\begin{document}
\newglossaryentry{entry}{name={some entry},description={some description}}
\glsaddall % error occurs here
% \glsadd{entry} % this triggers the same error
\printglossary
\end{document}

Here is the portion of the log.

! Extra \else.
<argument> \else 
l.20 \printglossary
I'm ignoring this; it doesn't match any \if.

Is there anything that can be done about this? I tried switching the order of the packages, but that didn't make a difference.

1

glossaries redefines \number locally (probably not a really good idea) and this breaks the farsi numbers. You can get around it like this (but I don't know if this will give the correct output in the glossaries). But imho you should make a bug report for glossaries, quite a number of languages try to change the number format and rely on the \number primitive.

\documentclass{book}
\usepackage{polyglossia}
\usepackage[xindy]{glossaries}

\setdefaultlanguage[numerals=eastern]{farsi}
\setotherlanguage[variant=american]{english}

% the error goes away with this
%\setdefaultlanguage[variant=american]{english}
%\setotherlanguage[numerals=eastern]{farsi}

\setmainfont{Arial Unicode MS}
\newfontfamily\englishfont{Charis SIL}
\newfontfamily\farsifont{Arial Unicode MS}

\makeglossaries

\makeatletter
\let\farsiorgnumber\number %save number
\def\farsinumber#1{%
  \if@western@numerals
    \number#1%
  \else
    \ifnum\XeTeXcharglyph"06F0 > 0%
      \farsidigits{\farsiorgnumber#1}%changed
      %%{\protect\addfontfeature{Mapping=farsidigits}\number#1}%
    \else%
      \arabicdigits{\farsiorgnumber#1}%changed
      %%{\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
    \fi
  \fi}
\makeatletter

\begin{document}


\newglossaryentry{entry}{name={some entry},description={some description}}

 \glsaddall % error occurs here
 \glsadd{entry} % this triggers the same error


\printglossary
\end{document}
  • The problem is that \number\c@page must be deferred until the next paragraph break, but any other counter shouldn't be deferred. There's a hook to allow for other formats so you could try \renewcommand\@wrglossarynumberhook{\let\number\orgnumber} to counteract the change but test to see what happens when an entry is indexed at the start of a page in a paragraph that spans the page break. – Nicola Talbot Apr 19 '16 at 12:19
  • @NicolaTalbot Why can't you use the same method as the \label command? It is quite able to output the current counter but wait for the page number for the next page break (I assume that you meant the next page break). – Ulrike Fischer Apr 19 '16 at 12:38
  • I did originally, but it's a lot more complicated than \label. Some elements need to be expanded immediately and some have to be deferred. That's why \glsaddprotectedpagefmt is provided for additional numbering systems. – Nicola Talbot Apr 19 '16 at 12:50
  • I don't think that \glsaddprotectedpagefmt works here. After \glsaddprotectedpagefmt{@farsi@digits} xelatex hangs. – Ulrike Fischer Apr 19 '16 at 13:04
  • \glsaddprotectedpagefmt expects a command name that can accept a count register as the argument so it won't work with @farsi@digits. It works fine for me if I just add \glsaddprotectedpagefmt{@arabic} to the OP's MWE. (That's one that ought to be automatically added, and will be in the next version.) – Nicola Talbot Apr 19 '16 at 13:12
0

Ulrike's answer certainly addresses the problem, but adds the complication that glossaries prints a Farsi number in the .glo file (۱۲۳۴۵۶۷۸۹۰ instead of 1234567890), which confuses xindy. (I searched but was unable to find a way to teach xindy about non-Western numbers.) If one instead uses xepersian, this problem goes away.

(For other languages, of course, Ulrike's solution may be better. We happen to have very good packages available for typesetting Persian text.)

\documentclass{book}
\usepackage[xindy]{glossaries}
\usepackage{xepersian}
\settextfont[Script=arab,Scale=1.4,Ligatures={NoCommon}]{Adobe Arabic}
\setlatintextfont[Mapping=tex-text,Renderer=ICU,ItalicFont=Charis SIL Italic,BoldFont=Charis SIL Bold]{Charis SIL}
\makeglossaries
\begin{document}
\newglossaryentry{entry}{name={some entry},description={some description}}
\glsaddall
\printglossary
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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