3

There are three digraphs in Croatian language (as in many others): dž, lj and nj. Common way of typesetting does not include usage of dedicated Unicode codepoints (which exist) - people just type them as two characters.

Assuming that font contains dedicated symbols, what would be the right way to e.g. render (two characters in source) as "dž" (single character in output)? Maybe babel/polyglossia? Is there any example of such?

Can a "fallback" to "dž" (two characters in output) be also supported in case that font does not contain dedicated symbols?

Edit 1 Thanks for the ligatures variant! This is the idea which I want to accomplish (pdflatex variant):

\documentclass{article}
\usepackage{lmodern} % I know that my font has appropriate Unicode slots for digraphs...
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[croatian]{babel}
\languageattribute{croatian}{unicodedigraphs} % ...so I will explicitly load something implemented in babel's Croatian definition file...

\begin{document}
dž % ...and these consecutive characters will be automatically rendered as U+01C6
\end{document}

Can something like that be achieved? Is using and enhancing babel (pdflatex) and polyglossia (xelatex) the right approach?

Edit 2 I thought of implementing something with catcodes... Let me get back once I make progress on that.

  • 1
    With an OpenType font? It’s hard to say without knowing how the font is designed. Usually, the source should contain the individual characters, while the font’s features supply the ligature in the output (as one usually enters ‘f’ and ‘i’ in the source but gets ‘fi’ in the output). You may need to turn on discretionary ligatures or localizations, depending on the font. – Thérèse Oct 25 '17 at 9:51
  • What are the codepoints? – Thérèse Oct 25 '17 at 10:05
  • @Thérèse, I used the phrasing as Wikipedia did. Nothing special, "Unicode slots" actually. – Ivan Kokan Oct 25 '17 at 10:21
  • OK, found them. U+01C4 and following. Agmena is a typeface that offers this as a discretionary ligature (you’d enter the components separately in your source). But I don’t think a perfectly general answer is possible, because font designers may use features differently to achieve similar results. – Thérèse Oct 25 '17 at 10:35
  • I am more interested in using Unicode slot than in ligatures, though. – Ivan Kokan Oct 25 '17 at 11:37
8

Many fonts do not contain these digraphs, with the result that entering them manually in your source may lead to a PDF file with missing glyphs.

Most fonts containing the digraphs seem to replace the components with the digraphs through the liga feature (on by default), or the calt feature (on by default in xetex; be sure to turn it on in luatex), or sometimes the dlig feature (not on by default).

If you have a font which contains the digraph but provides no obvious means to use it, and if you are using luatex, you can create a feature or add to an existing feature. I haven’t yet found a freely available font which illustrates exactly the case you have in mind, but here’s the dz digraph (U+02a3) in Heuristica.

If you do nothing, you get the components or the digraph you type in your source:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Heuristica}
\begin{document}
dz ʣ
\end{document}

output of above example

Now let’s add “dz” to the default ligatures:

\documentclass{article}
\usepackage{fontspec}
\directlua{
  fonts.handlers.otf.addfeature{
    name = "liga",
    type = "ligature",
    data = {
      ʣ = { "d", "z" },
    },
  }
}
\setmainfont{Heuristica}
\begin{document}
dz
\end{document}

output of second example

There’s the unicode glyph you want in the output, but you no longer have to enter it directly in the source. And if you want to change to a font that doesn’t have the glyph, all you need to do is delete the call to \directlua and adjust the invocation of \setmainfont (whereas if you had typed digraphs directly in your source, you would need to search for them throughout the document and replace them with their components).

The only time I type digraphs directly into my source is when the language in question sometimes requires the component characters to remain separate (e.g., in French, where some words require “œ” and others require “oe”).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.