我有一份以孟加拉语为主要语言(使用babel
包)并以英语为次要语言的文档。孟加拉语用于常规文本。但是,每当我在数学模式的等式中使用孟加拉语时,孟加拉语文本根本不显示。例如,
$৩৪^২$ %34^2
\begin{align*}
৩৪২ &= (৩৪+৪)(৩৪-৪) + ৪২\\
&= ৩৮৩০ + ৪২
\end{align*}
此代码仅显示符号= ( + )( − ) +
。我有一个使用命令显示孟加拉语文本的解决方案\text{}
。但这很危险。我需要一个不使用的慷慨解决方案\text{}
。有人可以帮忙吗?
完整示例:
\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}
答案1
你需要unicode-math
,但它的range
选项没有像我预期的那样工作,虽然这似乎有效,但我不确定孟加拉语文本所需的所有字体形状是否在数学模式下可用,使用可能更好\text{....}
\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
您需要设置孟加拉数字的数学代码,以便为它们分配合适的字体。
在下面的例子中,我使用 Bangla MN 作为我没有的 Kalpurush 的后备。可以使用任何支持 Bangla 的字体。
\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}