2

I am trying to use lualatex to typeset a document which has a mixture of Hindi and English languages. The following MWE works:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hindi}
\setotherlanguage{english}
\usepackage{fontspec}
\newfontscript{Devanagari}{deva,dev2}
\newfontfamily{\devanagarifont}{Noto Serif Devanagari}[Scale=1.1,Script=Devanagari]
\newfontfamily{\englishfont}{Noto Serif}
\begin{document}
 
This is a test.
 
 यह एक परीक्षा है।
\end{document} 

and gives the correct output.

enter image description here

However, if I change the default language to English and the other language to Hindi as in the MWE below

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hindi}
\usepackage{fontspec}
\newfontscript{Devanagari}{deva,dev2}
\newfontfamily{\devanagarifont}{Noto Serif Devanagari}[Scale=1.1,Script=Devanagari]
\newfontfamily{\englishfont}{Noto Serif}
\begin{document}
 
This is a test.
 
 यह एक परीक्षा है।
\end{document} 

the Hindi Characters don't show. What is the problem? enter image description here

1
  • you must switch the language explicitly, e.g. \foreignlanguage{hindi}{यह एक परीक्षा है।}. This is not done automatically by polyglossia. (You could try babel instead, it has code to switch depending on the script). Apr 24 at 8:13

1 Answer 1

4

Polyglossia doesn’t automatically detect the language. (Babel has a command to do this.) You want to select it with \texthindi or \textenglish. It so happened that your Hindi font also supports English, so using that as the default happened to work. If you check the fonts, you will see that it is using only your Devanagari font, not the English font you specified.

If you’re switching languages, you should add the command, near the top of your source:

\tracinglostchars=3

This makes it an error to request a glyph that your current font doesn’t have, instead of silently ignoring it (with a message in the middle of the .log file). You could instead turn it into a warning on the console with \tracinglostchars=2.

The following solution with Babel sets the main language to English, and automatically detects which language you are typing in:

\documentclass{article}
\tracinglostchars=3
\usepackage[english, bidi=basic]{babel}
\usepackage{fontspec}

\babelprovide[import=hi, onchar=fonts ids]{hindi}

\babelfont{rm}
          [Ligatures={Common, TeX}]{Noto Serif}
\babelfont[hindi]{rm}
          [Scale=MatchUppercase]{Noto Serif Devanagari}

\begin{document}

This is a test.
 
यह एक परीक्षा है।
\end{document}

Noto Serif sample

If your existing source uses commands such as \texthindi or \textdevanagari, you might also want to declare \babeltags for compatibility with Polyglossia.

You must log in to answer this question.

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