完整文件如下这里。 梅威瑟:
\documentclass[11pt,fancy,authoryear,twoside]{elegantbook}
%--------------------------------------------------
%Bengali Font in Document
%--------------------------------------------------
\tracinglostchars=2
% For a bilingual document
\RequirePackage{fontspec}
\RequirePackage{polyglossia}
\defaultfontfeatures{Ligatures=TeX, Scale=MatchUppercase}
% Times New Roman used for English
%\setmainfont{Times New Roman}
%\setmainfont{Times New Roman}[NFSSFamily=ntxtlf]
\setmainlanguage{bengali}
\setotherlanguage{english}
% Bengali
\newfontfamily\bengalifont{Kalpurush}[
Script=Bengali,
Language=Bengali,
AutoFakeBold = 0.2,
AutoFakeSlant = 0.15 ]
\renewcommand{\chaptermark}[1]{\markboth{\chaptername~\thechapter \, #1\,}{}}
\titleformat{\chapter}[\style]{\bfseries}
{\filcenter\LARGE\enspace\bfseries{\color{structurecolor}%
\IfAppendix{\appendixname}{\chaptername~\thechapter}\enspace}}
{1pt}{\bfseries\color{structurecolor}\LARGE\filcenter}[]
%End--------------------------------------------
\usepackage{listings}
\begin{document}
\maketitle
\frontmatter
\tableofcontents
\mainmatter
\begin{lstlisting}
import numpy as np
\end{lstlisting}
\end{document}
当我使用 Listings 时,出现错误:“
! Package polyglossia Error: The current roman font does not contain the Bengal
“。除了包“ ”,其他都很好\usepackage{listings}
。我该如何修复这个问题?
答案1
从对十几种随机字体的试验来看,Kalpurush 字体似乎没有必要的连字。尝试使用 Nikosh 字体作为主字体。
此外,并非所有字体都能在进入列表环境后继续存在。请尝试 Mukti 字体。
在列表中,非 ASCII 字符需要转义,需要用 Latex 处理的命令等也需要转义。
并非所有字体都具有:(1) 所有字符、(2) 所有连字和 (3) 孟加拉语和拉丁语的组合;因此,在列表环境中获取可打印副本所需的工作量取决于需要的内容。可能需要做出一些选择和决定来节省打字量。
注意:“Poly env {bengali}”用于测试 listings 环境,指的是\begin{bengali}\fontoverride ... text\end{bengali}
代码结构。例如,Nikosh 字体在 plain 环境中完全没问题,但字体覆盖则不行,因此在 listings 中会失效。
该引文来自维基百科的太阳系文章。
平均能量损失
\documentclass[11pt,fancy,authoryear,twoside]{elegantbook}
%--------------------------------------------------
%Bengali Font in Document
%--------------------------------------------------
\tracinglostchars=2
% For a bilingual document
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{bengali}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures=TeX, Scale=MatchUppercase}
% Times New Roman used for English
%\setmainfont{Times New Roman}
%\setmainfont{Times New Roman}[NFSSFamily=ntxtlf]
%\setmainlanguage{bengali}
%\setotherlanguage{english}
%সৌরজগৎ
\setmonofont{Mukti}[Colour=blue,Scale=1.2]%Mitra Mono}%Akaash}%Jamrul}%Likhan}
\newfontface\fban{Vrinda}
\newcommand{\য}{\textcolor{red}{সৌরজগৎ} হল সূর্য ও প্রত্যক্ষ বা পরোক্ষভাবে[ক] সূর্য-প্রদক্ষিণকারী তথা পরস্পরের প্রতি অভিকর্ষজ টানে আবদ্ধ মহাজাগতিক বস্তুগুলিকে নিয়ে গড়ে একটি ব্যবস্থা। আকাশগঙ্গা ছায়াপথের কেন্দ্রস্থল থেকে ২৬,০০০ আলোকবর্ষ দূরে কালপুরুষ বাহুতে এই গ্রহ ব্যবস্থাটি অবস্থিত। }
\newcommand{\প্রতি}{abc প্রতি xyz 123}
% Bengali
\newfontfamily\bengalifont{Nikosh}[
Script=Bengali,
Language=Bengali,
% AutoFakeBold = 0.2,
AutoFakeSlant = 0.15 ]
\newfontface\fbana{Vrinda}[Script=Bengali]
\newfontface\fbanb{Akaash}[Script=Bengali,Scale=1.5]
\newfontface\fbanc{Jamrul}[Script=Bengali,Scale=1.2]
\newfontface\fband{Noto Serif Bengali}[Script=Bengali]
\newfontface\fbane{Likhan}[Script=Bengali,Scale=1.2]
\newfontface\fbanf{Mitra Mono}[Script=Bengali,Scale=1.5]
\newfontface\fbang{Sagar}[Script=Bengali,Scale=1.5]
\newfontface\fbanh{Nikosh}[Script=Bengali]
\newfontface\fbani{Mukti}[Script=Bengali,Scale=1.5]
\newfontface\fbanj{Kalpurush}[Script=Bengali]
\newfontface\fbank{Lohit Bengali}[Script=Bengali,Scale=1.5]
\newfontface\fbanl{Ekushey Saraswatii}[Script=Bengali,Scale=1.5]
\newcommand\tbn{সৌরজগৎ প্রতি abc }
\renewcommand{\chaptermark}[1]{\markboth{\chaptername~\thechapter \, #1\,}{}}
\titleformat{\chapter}[\style]{\bfseries}
{\filcenter\LARGE\enspace\bfseries{\color{structurecolor}%
\IfAppendix{\appendixname}{\chaptername~\thechapter}\enspace}}
{1pt}{\bfseries\color{structurecolor}\LARGE\filcenter}[]
\newcommand\bb[1]{\begin{bengali}#1\end{bengali}}
%End--------------------------------------------
\usepackage{listings}
\begin{document}
\maketitle
\frontmatter
\tableofcontents
\mainmatter
\chapter{সৌরজগৎ}
\য
%\begin{english}
\begin{lstlisting}[escapechar=\#]
import numpy as np
\newcommand{#\textbackslash#য}{#\textbackslash#textcolor{red}{# \fbani সৌরজগৎ#} #হল সূর্য ও# ...}
#\textbackslash য#
#\textbackslash##\fbani প্রতি# $\mapsto$ #\fbanl\প্রতি#
#\textbackslash##\begin{bengali} প্রতি \end{bengali}#
\end{lstlisting}
%\end{english}
\begin{tabular}{ccr}
Standalone font & Poly env \{bengali\} & Font \\
\hline
\fbana\tbn & \bb{\fbana\tbn} & Vrinda\\
\fbanb\tbn & \bb{\fbanb\tbn} & Akaash\\
\fbanc\tbn & \bb{\fbanc\tbn} & Jamrul\\
\fband\tbn & \bb{\fband\tbn} & Noto Serif Bengali\\
\fbane\tbn & \bb{\fbane\tbn} & Likhan\\
\fbanf\tbn & \bb{\fbanf\tbn} & Mitra Mono\\
\fbang\tbn & \bb{\fbang\tbn} & Sagar\\
\fbanh\tbn & \bb{\fbanh\tbn} & Nikosh\\
\fbani\tbn & \bb{\fbani\tbn} & Mukti\\
\fbanj\tbn & \bb{\fbanj\tbn} & Kalpurush\\
\fbank\tbn & \bb{\fbank\tbn} & Lohit Bengali\\
\fbanl\tbn & \bb{\fbanl\tbn} & Ekushey Saraswatii\\
\hline
\end{tabular}
\end{document}
答案2
在这种情况下,问题是 polyglossia 想要访问程序列表中的孟加拉语脚本,即使您没有在那里输入孟加拉语。由于那里的字体是打字机类型,而 Computer Modern 打字机字体不支持孟加拉语,所以您得到了这个答案。
两种可能的解决方案:选项一,找到支持孟加拉语的打字机字体(例如 FreeMono)。选项二(这可能是更好的选择),用...包装您的listing
环境。\begin{english}
\end{english}