# Complex ligatures in Devanāgarī

Ligatures are known to the Western European languages, however it isn't that common to spot vertical or complex form of them. As an exercise in typography I tried to get some complex ligatures in Devanāgarī script.

I've downloaded the chandas.ttf file (Southern style; uttara.ttf would serve well as a test case) with complex ligatures in it as well as the Sanskrit 2003 font which doesn't contain complex ligatures to show common form of writing.

I've opened the font in FontForge where we can see those ligatures and their names. Ligatures are properly mapped, so we can use them. I only changed some letters to fit transliteration schemes: Y as nj or J, G as ng and I am using Lexilogos and Sanscript to get the portion of words.

Note: In case you are wondering what I am trying to achieve I can say that I try to convert transliterated words sorted in Xindy (Sanskrit, Pāḷi, hopefully even Tamiḻ and Siṇhala later) and I am checking what options I have to display index entries. As mapping is not supported in LuaTeX, I am trying to prepare standalone Lua scripts which will replace Latin letters.

In theory, I have two problems now:

1) How to turn off those complex ligatures locally in document and how to get regular form of writing, if needed? To preview a common form I used different font in the example below. After using otfinfo -f chandas.ttf we know there are three features, but it is not helping if we turn them off.

2) How to get complex ligatures in LuaLaTeX? As far as I know the support for Indic languages is very limited. Under normal circumstances I am using \char to get a specific glyph, but those complex ligatures are not mapped as Unicode glyphs in the private use areas (PUA). I would be able to use \XeTeXglyph and the glyph's slot, but it is not easy as well. FontForge is showing 3417 (0x0D59) for DNjYa glyph, but the actual position got from XeTeX (\the\XeTeXglyphindex"DNjYa") is 2510 (0x09CE). What a day!

A bonus. There is even more fun, if we try to get two complex ligatures next to each other (I cannot say if it is correct linguistically, it is not almost certainly), e.g. DNjJ+DNjJa, the middle letters form ligature earlier while typing it. The solution is to use \mbox{}, see the last line in the example.

I enclose an example and a preview of my efforts. We can run xelatex and lualatex. If you are interested, an encoding table can be obtained from http://www.sanskritweb.net/cakram/chandas-encoding.pdf and a preview of all ligatures from http://www.sanskritweb.net/cakram/saMyoga-pattra.pdf

% run: xelatex or lualatex mal-sanskrit.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{ifxetex}
\usepackage{fontspec}
% Possible addtion for LuaLaTeX (1 line):
%\usepackage{luatextra}
% Possible addition for XeLaTeX (3 lines):
%\usepackage{polyglossia}
%\setmainlanguage{sanskrit}
%\newfontfamily{\devanagarifont}{Sanskrit2003}
\parindent=0pt
\begin{document}
Correct form in Xe\LaTeX, incorrect in Lua\LaTeX\ (2 lines):\par
\setmainfont[Script=Devanagari]{Sanskrit2003.ttf}
ड्ण्ज्ञ​ (common form; using different font [Sanskrit2003.ttf])\par % ड्ण्ज्ञ
\setmainfont[Script=Devanagari]{chandas.ttf}
ड्ण्ज्ञ​ (glyph DNjYa; DNjnja [Lexilogos] or DNjJa [Harvard-Kyoto])\par\medskip
% Y as nj or J, G as ng
\setmainfont[Script=Devanagari,RawFeature=-liga;-mkmk;-mark]{chandas.ttf}
ड्ण्ज्ञ​ (a form of ligature; Devanāgarī script)\par
\setmainfont[Script=Latin]{chandas.ttf}
ड्ण्ज्ञ​ (incorrect form; Latin script)\par
\setmainfont[Script=Devanagari]{chandas.ttf}
ड्\mbox{}ण्\mbox{}ज्ञ​ (incorrect form; separated glyphs, \verb.\mbox.)\par\medskip
\ifxetex
3417 as \XeTeXglyph"0D59\ versus % 3417
\the\XeTeXglyphindex"DNjYa"\ as % 2510
\XeTeXglyph2510\ or\ \XeTeXglyph"09CE\ (getting slot number)\par
ड्ण्ज्ञ्ड्ण्ज्ञ / ड्ण्ज्ञ्\mbox{}ड्ण्ज्ञ (DNjJ DNjJa)
\fi
\end{document}


• I will confess up front to having no particular knowledge of the exigencies of the writing systems you're dealing with. That said, if you work with Lua(La)TeX you could try using the selnolig package to suppress certain ligatures on either a document-wide or a more limited scale. The package currently onlz provides rules to suppress ligatures selectively for English and German documents. However, it should be adaptable to any writing system. – Mico May 6 '14 at 9:13
• @Mico Thank you for your feedback! I'd love to test it, but I am not getting those complex ligatures in LuaLaTeX at the moment. I am one step behind. – Malipivo May 6 '14 at 9:17
• While your question subjects are often quite esoteric, relevant for only a narrow segment of the general TeX population, I am always impressed at their depth and even more so at the difficulties faced by people who work in a multilingual typesetting environment. +1 – Steven B. Segletes May 6 '14 at 10:09
• @StevenB.Segletes Thank you for your comment! I am new in those areas/languages, well, the problems are challenges. – Malipivo May 6 '14 at 12:04
• Many of these consonant clusters never occur in Sanskrit (some I doubt are even pronounceable), so it's better to stick to ligatures that actually occur in the language. These are also the ones the font designers are likely to have spent effort on (if they were choosing wisely). – ShreevatsaR May 3 '15 at 16:44