我正在使用同时使用 Devnagari 和拉丁字体的 \LaTeX 文档。
使用的命令是:lualatex -shell-escape -interaction nonstopmode
但是,尽管选择了合适的字体,最少的代码是:
我也尝试使用 polyglossia 包,(按照https://tex.stackexchange.com/a/24731/50653),但仍然没有区别。
\documentclass[10pt]{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hindi}
% From https://tex.stackexchange.com/a/37251
\usepackage{fontspec}
\setmainfont{Noto Serif} % sets the roman font
\setsansfont{Noto Sans} % sets the sans font
\setmonofont{Fira Code} % sets the monospace font
\defaultfontfeatures{Ligatures=TeX} % makes this a feature for all selected fonts
\newfontfamily\hindifont[Script=Devanagari]{Noto Serif Devanagari}
\newfontfamily\hindifontsf[Script=Devanagari]{Noto Sans Devanagari}
\begin{document}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।
\end{document}
同时人们还期望天城文字符也能被呈现。
我之前也尝试过
\documentclass[10pt]{article}
\usepackage[hindi, english]{babel}
% From https://tex.stackexchange.com/a/37251
\usepackage{fontspec}
\setmainfont{Noto Serif} % sets the roman font
\setsansfont{Noto Sans} % sets the sans font
\setmonofont{Fira Code} % sets the monospace font
\defaultfontfeatures{Ligatures=TeX} % makes this a feature for all selected fonts
\begin{document}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।
\end{document}
答案1
这里有两个问题:主要问题是所选字体不包含所讨论的字符,另一个问题是使用 fontspec fontloading 命令而没有明确指定脚本和语言默认为拉丁脚本,因此无法正确地塑造印度脚本。
如果您不想担心字体规范的正确脚本/语言参数,则可以使用 babel 的字体规范包装器来指定您语言的字体。为了使其正常工作(尤其是使特定语言的整形工作),您必须使用或/环境\babelfont
在文档中指示语言更改。如果您用另一种语言编写整个段落\selectlanguage
,则可以使用,对于段落的部分内容,则有。\foreignlanguage
otherlanguage
otherlanguage*
\selectlanguage{new-language}
\foreignlanguage{new-language}{text-in-new-language}
您可以在babel 手册、第 1.2 节(多语言文档)、第 1.7 和 1.8 节(基本/辅助语言选择器)和第 1.14 节(选择字体)。
\documentclass[10pt]{article}
\usepackage[hindi, english]{babel}
\babelfont{rm}{Noto Serif} % sets the roman font
\babelfont{sf}{Noto Sans} % sets the sans font
\babelfont{tt}{Fira Code} % sets the monospace font
\babelfont[hindi]{rm}{Noto Serif Devanagari}
\babelfont[hindi]{sf}{Noto Sans Devanagari}
\begin{document}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
\foreignlanguage{hindi}{येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।}
More English.
\selectlanguage{hindi}
येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए। येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।
येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए। येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।
येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए। येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।
\selectlanguage{english}
And English again.
\end{document}
正如 Davislor 在评论中提到的那样,以下内容需要相当现代的 TeX 安装(于 2020 年 2 月或之后更新),因此可能无法在您的系统上运行,或者如果您尝试在另一个系统上编译文档,可能会中断:
如果你真的不能插入这样的语言切换命令,你只使用每个脚本系统的一种语言,并且你不关心天城文文本中的正确段落间距(例如因为它主要是拉丁语),你也可以使用onchar=ids fonts
:替换
\usepackage[hindi, english]{babel}
和
\usepackage[english]{babel}
\babelprovide[import, onchar=ids fonts]{hindi}
然后,当 babel 遇到梵文字符时,它会自动将字体和连字模式切换为印地语。(当然,如果您主要有印地语文本,english
您可以切换。)hindi
答案2
欢迎来到 TeX.SX!
LuaTeX 整形器dev2
在处理印度文字时有点麻烦,但已经出现了另一个版本deva
,如https://tex.stackexchange.com/a/362738/90407。但是,最近,LuaTeX 还支持使用 HarfBuzz 整形器来代替内置整形器。两种变体应该会给出类似的结果,尽管略有不同。 然而,在这两种情况下,我们都需要为新的字体系列创建字体切换。使用 polyglossia,我们可以添加另一种语言并为该语言定义新的字体系列,它将自动处理无衬线和衬线之间的所有字体切换:
LuaTeX deva
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hindi}
\usepackage{fontspec}
% define Devanagari script using `deva' backend
\newfontscript{Devanagari}{deva,dev2}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
% Create font switches for Devanagari font
% These are hard-coded into polyglossia, if we name them differently
% we get:
% Package polyglossia Error: The current latin font [...] does
% not contain the "Devanagari" script!
% Please define \devanagarifont with \newfontfamily command.
\newfontfamily{\devanagarifont}{Noto Serif Devanagari}[Script=Devanagari]
\newfontfamily{\devanagarifontsf}{Noto Sans Devanagari}[Script=Devanagari]
\defaultfontfeatures{Ligatures=TeX}
\begin{document}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
\texthindi{येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
\texthindi{\textsf{येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।}}
\end{document}
LuaTeX 与 HarfBuzz (LuaHBTeX)
或者,我们不定义新脚本,而只是要求 HarfBuzz 完成繁重的工作:
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
% Create font switches for Devanagari font
% These are hard-coded into polyglossia, if we name them differently
% we get:
% Package polyglossia Error: The current latin font [...] does
% not contain the "Devanagari" script!
% Please define \devanagarifont with \newfontfamily command.
\newfontfamily{\devanagarifont}{Noto Serif Devanagari}[Script=Devanagari,Renderer=Harfbuzz]
\newfontfamily{\devanagarifontsf}{Noto Sans Devanagari}[Script=Devanagari,Renderer=Harfbuzz]
\defaultfontfeatures{Ligatures=TeX}
\begin{document}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
\texthindi{येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।}
All the places marked with red triangles are \emph{sites} from which archaeologists have found evidence of hunter-gatherers. (Hunter-gatherers lived in many more places. Only some are shown on the map). Many sites were located near sources of water, such as rivers and lakes.
\texthindi{\textsf{येह एक प्रयोग है हिन्दी की लिखावट देखने के लिए।}}
\end{document}
以我的浏览器渲染为参考,这对我来说看起来还不错。
如果您不关心适当的间距,您可以不使用多语种,而是使用如下方法:
\usepackage[Devanagari]{ucharclasses}
\setTransitionsFor{Devanagari}{\devanagarifont}
然而,这只会切换字体,并消除多语种实施的任何其他语言调整。