How can I improve my Turkish Small Capitals (XeTeX)

Status update

In a private email, Bogusław Jackowski (to whom my sincere thanks) has recognised this as a bug in the TeX Gyre fonts. As the TeX Gyre team are all working hard on another piece of the TeX Gyre project, he cannot commit to a date for fixing this, but his best estimate is sometime next year.

Turkish characters to small caps and Turkish characters to uppercase attempt to address the tribulations of those of us who need to deal with the dotted letter i/İ, in full-size and small capitals. As far as I can see, all the answers address the pdftex engine.

Here's my MWE to illustrate my annoyance:

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\begin{document}
\noindent
{\Huge
\textsc{Eb\.ı} \.Incelemesi\\[6pt]
\textsc{Eb\.{}\kern -0.215em ı} \.Incelemesi
}
\end{document}


and here's the output:

Now, can anyone, please, explain to me:

1. (Curiosity) Why is the dot accent over the B so badly out-of-joint?
2. (Real question) Given that (a) none of my fonts appears to have the TRK feature; (b) although they have a small caps dotted İ, the position in the glyph table varies, and the Unicode code point, of course, is at some random location in the Private Area; and (c) the time I spent hand-tuning the "-0.215em" will almost certainly need to be spent again if I change fonts; then what better and more robust method is there for producing the second line?

Further to EGreg's interesting comment, I 'made up' a new MWE, with an extra ı just to emphasize the problem:

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\setmainfont[%
Script=Latin,
Language=Turkish,
\begin{document}
\noindent
{\Huge
\textsc{Ebiı} İncelemesi\\[6pt]
}
\end{document}


Here's the output; the dot is still missing:

So now I'm getting irritated with myself, and I add another option:

\setmainfont[%
Script=Latin,
Language=Turkish,
Letters=UppercaseSmallCaps,


which gives the same result.

Then I switched to Brill, with the same options, and got this:

which, of course, is not what I want, as EBİ is now all uppercase, not SC.

At which point I'm going to sleep on it. What's the correct behaviour for Letters=UppercaseSmallCaps?

-
Actually otfinfo run over TeX Gyre Adventor claims that the TRK feature is available. – egreg Aug 14 '12 at 9:31
¡Oh! Missed that, I'll give it a try shortly. You are amazing, but you already knew that :) – Brent.Longborough Aug 14 '12 at 13:33
@doncherry: Thanks. – Brent.Longborough Aug 14 '12 at 13:34
Should we close the question, or do you want to answer it @egreg? – ℝaphink Sep 3 '12 at 8:31
@Raphink The question is very interesting; what I believe is that the TRK feature is uncorrectly implemented in the TeX Gyre fonts. – egreg Sep 3 '12 at 9:35

This seems to be a bug in the implementation of the TRK feature in the TeX Gyre fonts. Here's an example:

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainfont{Brill}
\setmainlanguage{turkish}
\newfontfamily{\termes}[Language=Turkish]{TeX Gyre Termes}
\begin{document}
\textsc{Ebi} İncemelesi \textsc{ıIiİ}

\termes
\textsc{Ebi} İncemelesi \textsc{ıIiİ}

\end{document}


and here's the result

The log file makes clear that the TRK feature is selected for both fonts:

.................................................
. fontspec info: "defining-font"
.
. Font family 'TeXGyreTermes(0)' created for font 'TeX Gyre Termes' with
. options [Language=Turkish].
.
. This font family consists of the following shapes:
.
. * 'normal' with NFSS spec.:
. <->"TeX Gyre Termes/ICU:script=latn;language=TRK;"
.
. * 'small caps' with NFSS spec.:
. <->"TeX Gyre Termes/ICU:script=latn;language=TRK;+smcp;"

[...]

. fontspec info: "defining-font"
.
. Font family 'Brill(1)' created for font 'Brill' with options
. [,Language=Turkish].
.
. This font family consists of the following shapes:
.
. * 'normal' with NFSS spec.:
. <->"Brill/ICU:script=latn;language=TRK;"
.
. * 'small caps' with NFSS spec.:
. <->"Brill/ICU:script=latn;language=TRK;+smcp;"

[...]


Here's the relevant part of the interaction between polyglossia and fontspec (line numbers from polyglossia.sty):

253 \def\xpg@addfontfeature@lang#1#2{% #1 is langtag, #2 is langname
254   % Turkish is a special case: tag can be TRK or TUR
255   \edef\tmp@Turkish{Turkish}%
256   \edef\tmp@@langname{#2}%
257   %  \ifstrequal{#2}{Turkish}%
258   \ifx\tmp@@langname\tmp@Turkish
259     \fontspec_if_language:nTF {TRK}%
261       {\fontspec_if_language:nTF {TUR}%
263         {}}%
264     % else not Turkish
265   \else
266      \edef\tmp@@langparam{Language=#2}%
267      \expandafter\expandafter\expandafter\fontspec_if_language:nTF \expandafter{#1}%
269       {}%
270   \fi
271 }


Essentially, the Language=... option is passed to the defined font families (and fontspec creates a new one, as results from the log file reported above). The fact that Turkish is treated in a special way is a happy coincidence.

If you're not using polyglossia, then you should define a font family for Turkish anyway, or \textsc won't give the expected result on "i" when a non-Turkish language is involved.

-
It looks like the Latin Modern open type fonts may suffer from the same problem. I've emailed Bogusław for an opinion on the TeX Gyre ¿problem?... – Brent.Longborough Sep 6 '12 at 20:07
I have also emailed Michael Everson. His documentation of the Turkish alphabet appears to be missing «Capital I with Dot Above»; I wonder if that led the TeX Gyre team astray? – Brent.Longborough Sep 7 '12 at 16:58

The fontspec accent code looks a bit suspect to me.

if you drop back to the classic TeX accent command but using the dot accent from Unicode position things look a bit better. The alignment still seems slightly off for the full size I.

\documentclass[a4paper,12pt]{article}

\def\dotabove#1{{\accent729 #1}}

\usepackage{fontspec}
\begin{document}

\Huge
\textsc{Eb\.ı} \.Incelemesi

\textsc{Eb\.{}\kern -0.215em ı} \.Incelemesi

\textsc{Eb\dotabove ı} \dotabove Incelemesi

\end{document}

-
Fontspec itself does not do accent positioning (or any rendering at all, for that matter), it merely passes font names and requested feature to the engine. As for accent positioning, the font has to supply needed information on how to properly position the marks and if the font lacks such info the glyphs will be just laid as is, no \accent like positioning is attempt. – Khaled Hosny Sep 3 '12 at 11:05
Ah interesting. Still it shows a possible workaround to use \accent for accent/base/font combinations for which the font doesn't supply accurate metrics. – David Carlisle Sep 3 '12 at 11:11
David, thank you for some additional insight. In the end, @egreg got the prize, simply because his answer addressed my initial concerns more directly. – Brent.Longborough Sep 4 '12 at 9:57
That's OK @egreg needed the points anyway:-) – David Carlisle Sep 4 '12 at 10:07