3

Consider the MWE below. Here, I am trying to use Bengali numerals for enumeration as per the solution found here.

\documentclass{article}

% For bilingual document
\usepackage{fontspec}
\usepackage{polyglossia}

% Bangla
\setmainlanguage[numerals=Devanagari]{bengali}
\newfontfamily\bengalifont[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontbf[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifonttt[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontsf[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontit[Script=Bengali]{SolaimanLipi}

% English
\setotherlanguage{english}

% Times New Roman used
\newfontfamily{\englishfont}[Mapping=tex-text, Ligatures=TeX]{Times New Roman}

% Bangla numerals
\makeatletter
\def\bengalidigits#1{\expandafter\@bengali@digits #1@}
\def\@bengali@digits#1{%
  \ifx @#1
  \else
    \ifx0#1০\else\ifx1#1১\else\ifx2#1২\else\ifx3#1৩\else\ifx4#1৪\else\ifx5#1৫\else\ifx6#1৬\else\ifx7#1৭\else\ifx8#1৮\else\ifx9#1৯\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@bengali@digits
  \fi
}

\def\bengalinumber#1{\bengalidigits{\number#1}}
\def\bengalinumeral#1{\bengalinumber{\csname c@#1\endcsname}}

\renewcommand\theenumi{\bengalinumeral{enumi}}

\makeatother

% \usepackage{enumitem}

\begin{document}

\begin{enumerate}
\item এক
\item দুই
\item তিন
\end{enumerate}


\end{document}

The above code works fine as you can see from this output.

enter image description here

However, as soon as the line, \usepackage{enumitem}, is put into action, all the enumerations get numbered as zeros.

enter image description here

I need to use enumitem, because, without it, I am going to loose a substantial amount of formatting in my lists.

Masroor
  • 17,842

2 Answers2

4

Only a first version, working for digits only, not for numbers > 9.

In short: enumitem needs special counter output information for such setups, i.e. an \AddEnumerateCounter macro must be used. The special setup is valid here only for digits, unfortunately.

\documentclass{article}

% For bilingual document
\usepackage{fontspec}
\usepackage{polyglossia}


 \usepackage{enumitem}


% Bangla
\setmainlanguage[numerals=Devanagari]{bengali}
\newfontfamily\bengalifont[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontbf[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifonttt[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontsf[Script=Bengali]{SolaimanLipi}
\newfontfamily\bengalifontit[Script=Bengali]{SolaimanLipi}

% English
\setotherlanguage{english}

% Times New Roman used
%\newfontfamily{\englishfont}[Mapping=tex-text, Ligatures=TeX]{Times New Roman}

% Bangla numerals
\makeatletter
\def\bengalidigits#1{\expandafter\@bengali@digits #1}
\def\@bengali@digits#1{%
  \ifcase #1
  ০\or১\or২\or৩\or৪\or৫\or৬\or৭\or৮\or৯\fi
}


\def\bengalinumber#1{\bengalidigits{\number#1}}
\def\bengalinumeral#1{\bengalinumber{\csname c@#1\endcsname}}


\AddEnumerateCounter*{\bengalnumeral}{\bengalinumeral}{5}

\makeatother


\begin{document}

\begin{enumerate}[label={\bengalinumeral*}]
\item এক
\item দুই
\item তিন
\end{enumerate}


\end{document}

enter image description here

  • I'll try to update for larger numbers later on –  Apr 03 '16 at 18:01
  • Yes, it works. Thanks. Waiting in anticipation for the complete solution. – Masroor Apr 03 '16 at 23:59
  • @Masroor: I'll try to update soon. My first trials failed, however –  Apr 04 '16 at 09:06
  • @Masroor: I failed so far to extend the solution, due to expansion issues. This really bothers me. I am sorry that there's no progress –  Apr 09 '16 at 17:50
  • Since the current solution serves my purpose, I will accept it. But I will keep my hopes open. – Masroor Apr 09 '16 at 23:34
1

The babel package provides a Bengali localization of \arabic and (as an undocumented bonus feature) alph. If this is satisfactory, you can express the following without defining your own counters. This will also localize the numbers of pages, chapters, sections, table of contents entries, etc.

\tracinglostchars=2 % Warn if a glyph is not in the current font
\documentclass[11pt]{article}
\usepackage{iftex}
\usepackage{enumitem}

\ifLuaTeX
  \usepackage[english, bidi=basic, layout=sectioning.counters]{babel}
  \usepackage{fontspec}
  \defaultfontfeatures{Renderer=HarfBuzz, Scale=MatchLowercase, Ligatures = TeX}
\else % XeLaTeX?
  \usepackage[english, bidi=default, layout=sectioning.counters]{babel}
  \usepackage{fontspec}
  \defaultfontfeatures{Scale=MatchLowercase, Ligatures = TeX}
\fi

\babelprovide[import, main, maparabic, alph=alphabetic]{bengali}

%% From: https://github.com/potasiyam/Kalpurush
%% A matching font family might be Gentium.
\babelfont{rm}
          [Scale = 1.0,
           BoldFont = *,
           BoldFeatures = {FakeBold = 1.1}
          ]{Kalpurush}

\begin{document}

\section*{বাংলায়  enumeration }
\begin{enumerate}[label=\arabic*।]
   \item  1st item
   \item 2nd item
     \begin{enumerate}[label=(\alph*)]
       \item 1st sub item
       \item 2nd sub item 
     \end{enumerate}
\end{enumerate}

\end{document}

Kalpurush sample

As of June 2020, an incompatibility between babel and fontspec prevents XeTeX from compiling the MWE correctly, but it works in LuaLaTeX 1.12.0. XeLaTeX from TeX Live 2019 might also work.

Davislor
  • 44,045
  • I've investigated the problem with XeTeX and there is a limitation in the way this engine gets rid of the hyphen, namely, there is no way to git rid of it in XeTeX itself . A trick is to set the hyphenchar to "200B, as explained here: https://tex.stackexchange.com/questions/124430/how-to-get-rid-of-the-hyphenchar-in-xelatex . babel is assuming this character exists, but sadly not all fonts contain it. So, very likely it must be set by hand. – Javier Bezos Jun 12 '20 at 14:51
  • @JavierBezos I haven’t liiked into the internals, but would \iffontchar work? Although, the character is invisible anyway, so it really shouldn’t be necessary to choose a font to “display” it. – Davislor Jun 12 '20 at 18:41
  • Very likely. IIR, this would mean babel shouldn't rely on HyphenChar, which is set when the font is loaded (ie, before we can test if a char exists). – Javier Bezos Jun 13 '20 at 08:17