6

I want to type text that may contain both Devanagari or Roman script, and I don't want to change language mid sentence every time. Is it possible to merge two fonts, one which supports Devanagari glyphs, and one which supports Roman glyphs into one language?

Currently, I am doing

\setdefaultlanguage{sanskrit}
\newfontfamily\sanskritfont[Script=Devanagari]{NotoSansDevanagari-Regular}

And since NotoSansDevangari-Regular does not have glyphs for roman characters, it renders the line

The ending हल् letter of an उपदेश is called 'इत्'.

as

��� ������ हल् ������ �� �� उपदेश �� ������ 'इत्'.

Is it possible to somehow add NotoSans-Regular alongwith NotoSansDevanagari-Regular in the language so that it can render both scripts properly without having to explicitly do \begin{english}\end{english} ?

2 Answers 2

9

It is possible to do this with babel. This new preamble should work with your document, so long as you used \textenglish and \begin{sanskrit} instead of \devanagarifont. It requires luahbtex (lualatex in TeX Live 2020 works), but has a bug with xetex (as of July 2020).

\documentclass{article}
\tracinglostchars=2
\usepackage{iftex} % For \ifluahbtex, \ifxetex, etc.
\usepackage[paperwidth=10cm]{geometry} % Format the MWR for TeX.SX
\pagestyle{empty}

\ifluahbtex
  \usepackage[bidi=basic,main=english]{babel}
  \usepackage{fontspec}
  \defaultfontfeatures{ Renderer=HarfBuzz,
                        Scale=MatchLowercase,
                        Ligatures=TeX }
  \usepackage{microtype}
\else
  % The only other engine that works, as of 2020, is XeTeX.
  \usepackage[bidi=default,main=english]{babel}
  \usepackage{fontspec}
  \defaultfontfeatures{ Scale=MatchLowercase,
                        Ligatures=TeX }
\fi

\babelprovide[onchar=ids fonts]{sanskrit-devanagari}

\babelfont{rm}
          [Ligatures=Common, Scale=1.0,Language=Default]{Noto Serif}
\babelfont{sf}
          [Ligatures=Common,Language=Default]{Noto Sans}
\babelfont[sanskrit-devanagari]{rm}
          {Noto Serif Devanagari}
\babelfont[sanskrit-devanagari]{sf}
          [Language=Default]{Noto Sans Devanagari}
\babelfont{tt}
          [Language=Default]{Noto Sans Devanagari UI}

\babeltags{sanskrit=sanskrit-devanagari} % Add \textsanskrit, \begin{sanskrit}
\babeltags{english=english} % Add \textenglish, \begin{englisn}

\begin{document}
\sffamily
The ending हल्  letter of  an उपदेश is called `इत्'.
\end{document}

Noto Sans font sample

Recall that quotes in TeX are

`foo ``bar" baz' or ‘foo “bar” baz’
4
  • I cannot get this to work. Some of the errors from the log file are: ************************************************* * fontspec warning: "script-not-exist" * * Font 'Noto Sans Devanagari UI' does not contain script 'Latin'. ************************************************* and Could not resolve font "Noto Sans Devanagari UI/I" (it probably doesn't . exist). This one now renders only the English words and boxes for Devanagari script.
    – Hrishikesh
    Jul 26, 2020 at 9:52
  • 1
    @Hrishikesh You need to download the Noto fonts. You can ignore the warning about Noto Sans Devanagari UI or even comment those lines our.
    – Davislor
    Jul 26, 2020 at 10:52
  • I have noto fonts installed. They are located in /usr/share/fonts/truetype/notoIt contains these files NotoSansDevanagari-Bold.ttf, NotoSansDevanagari-Regular.ttf, NotoSansDevanagariUI-Bold.ttf, NotoSansDevanagariUI-Regular.ttf as well as similar for many other languages
    – Hrishikesh
    Jul 26, 2020 at 12:02
  • 1
    Can luaotfload-tool find them? If not, rebuilding your cache might help. You can also comment out the pair of lines declaring the rm and tt fonts in this MWE. It works for me with lualatex in TeX Live 2020, but any previous version would require luahbtex.
    – Davislor
    Jul 26, 2020 at 21:54
1

Seems like you are using XeLaTeX. If so, as @kongo09 mentions in this question, a package called ucharclasses works. Here is the MWE:

\documentclass[xelatex]{article}
\usepackage{fontspec}
\newfontfamily{\defaultfont}{Times New Roman}
\newfontfamily{\latinfont}{Times New Roman}
\newfontfamily{\devanagarifont}{NotoSansDevanagari-Regular}

\usepackage[Latin, Devanagari]{ucharclasses}
\setDefaultTransitions{\defaultfont}{}
\setTransitionsForLatin{\latinfont}{}
\setTransitionTo{Devanagari}{\devanagarifont}

\begin{document}

The ending हल् letter of an उपदेश is called 'इत्'.

\end{document}
4
  • I’ve found the package to be buggy in TeX Live 2020.
    – Davislor
    Jul 26, 2020 at 5:11
  • It also does not work in LuaHBTeX.
    – Davislor
    Jul 26, 2020 at 9:08
  • I have tested with my XeLaTeX 2017 and it worked. @Davisor Thank you very much for your information that it is buggy in TeX Live 2020, I did not know that! :)
    – domperor
    Jul 28, 2020 at 6:34
  • 2
    Another more serious bug in this solution is that it always switches back to \defaultfont, and not the font you had selected before. You can fix this by opening with a \begingroup\devanagarifont and closing with an \endgroup.
    – Davislor
    Jul 28, 2020 at 8:24

You must log in to answer this question.

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