5

I have a document with Bangla as its main language (using babel package) and English as the secondary language. Bangla is used for regular text. However, whenever I am using Bangla in the equation in math mode, text in Bangla is not showing at all. For example,

$৩৪^২$ %34^2
\begin{align*}
    ৩৪২ &= (৩৪+৪)(৩৪-৪) + ৪২\\
    &= ৩৮৩০ + ৪২
\end{align*}

This code shows only symbols = ( + )( − ) + . I have a solution to show the Bangla text using \text{} command. But its a hazard. I need a generous solution for it without using \text{}. Can anyone help?

Complete example:

\documentclass{article}

\usepackage[english]{babel}
\babelprovide[import, onchar = fonts ids]{bengali}
% \babelfont[bengali]{rm}[Renderer=Harfbuzz]{FreeSerif}
\babelfont[bengali]{rm}[Renderer=Harfbuzz,AutoFakeBold,AutoFakeSlant=0.3]{Kalpurush}
\babelcharproperty{`।}{locale}{bengali}

% bangla numerals
\babelprovide[maparabic,alph=alphabetic]{bengali}

% fix `matra` in bangla text
\makeatletter
\AtBeginDocument{%
 \def\bbl@mapdir#1{%
   {\def\languagename{#1}%
    \let\bbl@ifrestoring\@firstoftwo % To avoid font warning
    \bbl@switchfont
    \ifnum\fontid\font>\z@
      \directlua{
        Babel.locale_props[\the\csname bbl@id@@#1\endcsname]%
              ['/\bbl@prefontid'] = \fontid\font\space}%
    \fi}}}%
\makeatother

\usepackage{amsmath}

\begin{document}
    $৩৪^২$ %34^2
\begin{align*}
    ৩৪২ &= (৩৪+৪)(৩৪-৪) + ৪২\\
    &= ৩৮৩০ + ৪২
\end{align*}
\end{document}
3
  • ! LaTeX Error: Environment align* undefined. Nov 15, 2021 at 7:53
  • @David Carlisle, I just cut some of code to be shorten.
    – mmr
    Nov 15, 2021 at 7:55
  • 4
    yes but you need the example to show the problem yoy are asking about (I fixed it this time). You will need unicode-math I thought \usepackage{unicode-math} \setmathfont{latinmodern-math.otf} \setmathfont[range={"0980-"09FF}]{fontkalpurush.ttf} should be enough be enough but that is still using a latin font for the Begali range for some reason. Nov 15, 2021 at 8:20

2 Answers 2

5

You need unicode-math but its rangeoption is not working as I expect, this appears to work though, However I'm not sure all the font shaping required for Bengali text is available in math mode, it may yet be better to use \text{....}

enter image description here

\documentclass{article}

\usepackage[english]{babel}
\babelprovide[import, onchar = fonts ids]{bengali}
% \babelfont[bengali]{rm}[Renderer=Harfbuzz]{FreeSerif}
\babelfont[bengali]{rm}[Renderer=Harfbuzz,AutoFakeBold,AutoFakeSlant=0.3]{Kalpurush}
\babelcharproperty{`।}{locale}{bengali}

% bangla numerals
\babelprovide[maparabic,alph=alphabetic]{bengali}

% fix `matra` in bangla text
\makeatletter
\AtBeginDocument{%
 \def\bbl@mapdir#1{%
   {\def\languagename{#1}%
    \let\bbl@ifrestoring\@firstoftwo % To avoid font warning
    \bbl@switchfont
    \ifnum\fontid\font>\z@
      \directlua{
        Babel.locale_props[\the\csname bbl@id@@#1\endcsname]%
              ['/\bbl@prefontid'] = \fontid\font\space}%
    \fi}}}%
\makeatother

\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{latinmodern-math.otf}
\setmathfont{fontkalpurush.ttf}[range={"0980-"09FF}]

\newcount\tmpcount
% re-do range No idea why this is needed
\AtBeginDocument{
\tmpcount="0980
\loop
\Umathcode\tmpcount 0 4 \tmpcount
\ifnum\tmpcount<"09FF
\advance\tmpcount 1
\repeat
}




\begin{document}


text
    ৩৪২

math
    $৩৪^২$ %34^2
\begin{align*}
    ৩৪২ &= (৩৪+৪)(৩৪-৪) + ৪২\\
    &= ৩৮৩০ + ৪২
\end{align*}
\end{document}
2
  • I am also using \usepackage{amsthm,amssymb} in my input file. May be it contradicts with new definition. I got 7 errors like: /usr/local/texlive/2021/texmf-dist/tex/latex/amsfonts/amssymb.sty, line 240 LaTeX Error: Command \eth' already defined.` Also is shows LaTeX Error: Command \digamma' already defined.`
    – mmr
    Nov 15, 2021 at 10:11
  • 1
    @mmr don't use amssymb with unicode-math (it defines all the amssyb characters already) (you dont need asmmath either as it includes that always if you have a recent version) Nov 15, 2021 at 11:12
4

You need to set up the math code of the Bangla digits so that a suitable font can be assigned to them.

In the example below I use Bangla MN as a fallback for Kalpurush that I don't have. Any font supporting Bangla can be used.

\documentclass{article}

\usepackage[english]{babel}
\usepackage{amsmath}

\babelprovide[import, onchar = fonts ids]{bengali}
% \babelfont[bengali]{rm}[Renderer=Harfbuzz]{FreeSerif}
\babelfont[bengali]{rm}[
  Renderer=Harfbuzz,
  AutoFakeBold,
  AutoFakeSlant=0.3,
  NFSSFamily=bangla,
]{Bangla MN}
\babelcharproperty{`।}{locale}{bengali}

% bangla numerals
\babelprovide[maparabic,alph=alphabetic]{bengali}

% fix `matra` in bangla text
\makeatletter
\AtBeginDocument{%
 \def\bbl@mapdir#1{%
   {\def\languagename{#1}%
    \let\bbl@ifrestoring\@firstoftwo % To avoid font warning
    \bbl@switchfont
    \ifnum\fontid\font>\z@
      \directlua{
        Babel.locale_props[\the\csname bbl@id@@#1\endcsname]%
              ['/\bbl@prefontid'] = \fontid\font\space}%
    \fi}}}%
\makeatother

\DeclareSymbolFont{bangla}{\encodingdefault}{bangla}{m}{n}
\Umathcode"09E6 = "1 \symbangla "09E6 % 0
\Umathcode"09E7 = "1 \symbangla "09E7 % 1
\Umathcode"09E8 = "1 \symbangla "09E8 % 2
\Umathcode"09E9 = "1 \symbangla "09E9 % 3
\Umathcode"09EA = "1 \symbangla "09EA % 4
\Umathcode"09EB = "1 \symbangla "09EB % 5
\Umathcode"09EC = "1 \symbangla "09EC % 6
\Umathcode"09ED = "1 \symbangla "09ED % 7
\Umathcode"09EE = "1 \symbangla "09EE % 8
\Umathcode"09EF = "1 \symbangla "09EF % 9

% typeset the digits otherwise strange things happen
\AtBeginDocument{%
  \sbox0{^^^^09e6^^^^09e7^^^^09e8^^^^09e9^^^^09ea^^^^09eb^^^^09ec^^^^09ed^^^^09ee^^^^09ef}%
}

\begin{document}

$৩৪^২$ %34^2
\begin{align*}
৩৪^২ &= (৩৪+৪)(৩৪-৪) + ৪^২\\
&= ৩৮৩০ + ৪^২
\end{align*}

\end{document}

enter image description here

4
  • 1
    not that it really changes your answer but Kalprush is in texlive as /usr/local/texlive/2021/texmf-dist/fonts/truetype/public/bangla/fontkalpurush.ttf Nov 15, 2021 at 9:55
  • this doesn't copy&paste well for me unless I use the digits also once in text mode. Nov 15, 2021 at 10:25
  • @UlrikeFischer Thanks. I find it a little weird.
    – egreg
    Nov 15, 2021 at 10:46
  • @egreg I asked Marcel in the chat. Nov 15, 2021 at 10:52

You must log in to answer this question.

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