# How can Bengali v.2 (bng2) be used to typeset Bengali with XeTeX?

This is a follow-up to this question about typesetting Bengali.

As explained in both answers there, XeLaTeX can typeset Bengali given a suitable font using polyglossia and fontspec. For example,

\documentclass[a4paper]{article}
\usepackage{geometry,fontspec,polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{bengali}
\newfontfamily\bengalifont{Noto Sans Bengali}[Script=Bengali]
\begin{document}
x, y, z whatever\dots

\begin{bengali}
আমি
\end{bengali}
\end{document}


produces

[Note that XeTeX is required. LuaTeX does not give correct results.]

As I explain in my answer, the font I used in this example actually offers two different versions of Bengali script, which correspond to two different OpenType scripts for Bengali:

beng            Bengali
bng2            Bengali v.2


As shown above, using the first one is straightforward.

What about the second? As Arun Debray explains in discussion following his answer, there are posts elsewhere suggesting this is possible, but the example which would have shown how to realise this possibility is no longer available at the sign-posted location. That is, the trail goes cold at this point.

Hence, Arun Debray and I thought this question worth asking:

How should the second be used?

Disclaimer: I know nothing whatsoever about Bengali. I am told that the sample above is Bengali and that the output is correct. However, if I was not told this, it could as easily be Psyptizamen and I would never know the difference.

Though this question is about Bengali, several other scripts (e.g. Devanagari, Tamil) have two OpenType versions, so whatever difference there is between these is not specific to just Bengali.

• I found a possible answer, but it doesn't seem to change anything, so I'll wait to post it as an answer until I understand the differences between the two versions, or someone finds a different approach. In §9.18.2 (p. 36) of the fontspec documentation, it suggests \newfontscript{Bengali2}{bng2} and \newfontfamily\bengalifont[Script=Bengali2]{Noto Sans Bengali} to switch versions. However, when I tried this on a paragraph of Bengali text, I could see no difference, so maybe this doesn't actually change anything. Jan 2, 2016 at 4:34
• In the next version of fontspec, "Script=Bengali" will first try bng2 and fall back on beng if that's not found. Jan 23, 2016 at 16:23
• @WillRobertson Good to know. What if you want beng rather than bng2? Or would nobody ever want that? (I have no idea what these are and know nothing about the languages concerned, so maybe nobody ever would.)
– cfr
Jan 23, 2016 at 18:15
• You can always define your own with \newfontscript Jan 24, 2016 at 0:07
• @ArunDebray Does the community wiki answer below answer the question? Although I asked the question, I don't really know enough about the languages/scripts to be certain. (Especially since the answer says the question was addressed in the other questions, which I seem to remember prompting this one.)
– cfr
Mar 6, 2017 at 23:41

This has been answered in the comments on the question by Arun Debray (also at the other question) and by Will Robertson, fontspec developer; just turning it into an "answer" to get this question off the unanswered list.

Briefly, in the command

\newfontfamily\bengalifont{Noto Sans Bengali}[Script=Bengali]

the Script=Bengali is just a convenience, part of fontspec's pre-defined mapping of common names to OpenType script tags. As documented in section "Defining new scripts and languages" of the fontspec manual, you can define your own scripts with \newfontscript.

Thus, if you wish, you can forget about the default fontspec-defined Script=Bengali and define your own explicitly:

\documentclass[a4paper]{article}
\usepackage{geometry,fontspec,polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{bengali}
\newfontscript{BengaliOpenTypeOld}{beng}
\newfontscript{BengaliOpenTypeNew}{bng2}
\newfontfamily\bengalifont{Noto Sans Bengali}[Script=BengaliOpenTypeNew]
\begin{document}
x, y, z whatever\dots

\begin{bengali}
আমি
\end{bengali}
\end{document}


and switch between Script=BengaliOpenTypeNew and Script=BengaliOpenTypeOld as you wish.

Aside: The rest of this answer is completely tangential, but somewhat related to the motivation for asking this question (looking at the other question): the reason XeTeX is required and LuaTeX does not give correct results (currently) is that XeTeX uses the system libraries—such as Harfbuzz—for complex text layout aka text shaping (glyph reordering, glyph positioning, etc.), while LuaTeX hopes to minimize external dependencies and implement everything in Lua code, and this (IMO highly ambitious) work has, at the moment, simply not been done for Indic scripts other than reasonable support for Devanagari script and some basic support for Malayalam script. (See font-odv.lua in ConTeXt source code.)

For example, the word "আমি" consists of three Unicode "characters" (codepoints) in this order:

where the glyph for the vowel-sign needs to be placed to the left of the consonant. This is done by Harfbuzz (or on Windows, possibly DirectWrite),

but in LuaTeX the glyphs are picked from the font and simply placed one after another meaninglessly:

• For others who may come here: this sort of thing also happens with Tamil (and probably lots of other languages that use Indic scripts, and maybe with other complex scripts like Burmese). Among other sequences in Tamil, the sequence 'க ோ' (but without the internal space char) is supposed to be rendered 'கோ' (and is rendered that way with XeLaTeX, and indeed in Internet Explorer), but instead comes out with the first and second glyphs reversed. This kind of issue effectively makes Lua(La)TeX unusable with Indic scripts, afaict. Mar 23, 2018 at 17:39
• @MikeMaxwell Yes indeed. (The old pdfTeX ways of using Indic scripts, involving custom processors and TeX-specific non-Unicode fonts, is the only way to get Indic scripts properly in LuaTeX.) There have been some experiments with combining LuaTeX with Harfbuzz, but that won't be in the major TeX distributions for at least the next few years it looks like. Mar 23, 2018 at 17:55
• the experiments you refer to are these: readytext.co.uk/?p=3186, right? Or are there others? Mar 23, 2018 at 20:35
• @MikeMaxwell I haven't been keeping track, but Google search shows this (slides), this (post), this (and the one you linked), and IIRC I heard there was something recently from the LuaTeX developers themselves, though I can't find it anywhere. (You may get an answer to the question you asked on the LuaTeX mailing list.) Mar 23, 2018 at 20:55
• @MikeMaxwell Also, if Tamil is the only Indic script you care about currently, there are some cumbersome non-Unicode ways to get Tamil (intended for old TeX/pdfTeX, but which will also work in LuaTeX), using some custom packages and preprocessing. (Search for Tamil on this site, or ask a new one if those don't work for you.) Mar 23, 2018 at 20:56