fontspec icon indicating copy to clipboard operation
fontspec copied to clipboard

language related font changes

Open u-fischer opened this issue 7 years ago • 3 comments

In documents with more than one language/script it is sometimes also necessary to change some font features at a language change. polyglossia does it in some places with \addfontfeature. But \addfontfeature doesn't survive a \normalfont and so is not really suited for the task:

\documentclass[11pt]{memoir}

\usepackage{fontspec,xcolor}
\setmainfont{Linux Libertine O}

\begin{document}
In Turkish,  `\textsc{ı}' and `\textsc{i}' are different
letters.

\addfontfeature{Language=Turkish,Color=red}\selectfont
In Turkish,  `\textsc{ı}' and `\textsc{i}' are different
letters.

\addfontfeature{Language=Turkish,Color=red}\normalfont
In Turkish,  `\textsc{ı}' and `\textsc{i}' are different
letters.
\end{document}

Imho some interface is needed to change the font setup at language switches so that the fonts then stay stable as long as the language is active. Such a change can mean to add an open type feature like "Language=Turkish" to the current fonts, but it could also mean a completly different font should be used. I don't know if a unified interface for both tasks is possible.

I have some doubts that the font changes could (or should) be done with simple tex groups. But imho it would be okay to have something similar as for colors: a \font@begingroup and \font@endgroup pair that related package should then use to group a fontsetup.

u-fischer avatar Mar 09 '18 12:03 u-fischer

Idle though — maybe "language" is sufficiently orthogonal to everything else that it should be an NFSS axis.

I had always assumed that code like babel and so on would do the legwork of defining the necessary font switches, but maybe I underestimated the difficulty (and whether the fontspec APIs are good enough). Changing the language of the font is just a special case of changing the font, and also needs to be accompanied by a change of hyphenation patterns, and so on, which is why I never saw this as fontspec's problem to solve.

But I'd definitely like to add sufficient features to help...

wspr avatar Mar 11 '18 04:03 wspr

Now that you mention it I realize that I haven't look for quite some time at babel. Javier is really extending it and it has a working frame to switch fonts:

\documentclass{article}
\usepackage[turkish,english]{babel}
\babelfont[english]{rm}[Language=Default]{Linux Libertine O}
\babelfont[turkish]{rm}[Language=Turkish]{Linux Libertine O}
\begin{document}
english  `\textsc{ı}' and `\textsc{i}' are different%
\footnote{english `\textsc{ı}' and `\textsc{i}'}

\selectlanguage{turkish}

turkish,  `\textsc{ı}' and `\textsc{i}'
\footnote{turkish,  `\textsc{ı}' and `\textsc{i}'}

\selectlanguage{english}
`\textsc{ı}' and `\textsc{i}'
\end{document}

(Without the Language=Default one gets a warning about non existing language "English").

I'm quite impressed, there is even a way to define new font families.

u-fischer avatar Mar 11 '18 16:03 u-fischer

That does look really impressive! Given that, is there anything in fontspec that now needs to be addressed?

wspr avatar Mar 12 '18 12:03 wspr