[XeTeX] fontspec and languages

Javier Bezos listas at tex-tipografia.com
Mon Sep 16 16:04:17 CEST 2013


As I expected, adding fontspec support for babel is not
trivial. I discarded \addfontfeature because it only
sets the current family, and Khaled has given another
reason for not using it. \defaultfontfeaures would
require redefining the fonts, but at least could solve
the issue in subsequent \fontspec's -- if features
were "orthogonal".

So, I've attempted a quite different solution (see below).
It solves (with babel) the two main cases: the three basic
families, and direct use of \fontspec. For the former
\babelFSstore stores the current default fonts for the
rm/sf/tt families, and \babelFSdefault patches \fontspec
so that the current language is always passed as an optional
argument (not an ideal solution).

Javier

-----------

\documentclass{article}

\usepackage[english,turkish,shorthands=off]{babel}
\usepackage{fontspec}

%===========
\makeatletter

\def\babelFSstore#1{%
   \bbl at for\bbl at tempa{#1}{%
     \edef\bbl at tempb{\noexpand\bbl at FSstore{\bbl at tempa}}
     \bbl at tempb{rm}\rmdefault\bbl at save@rmdefault
     \bbl at tempb{sf}\sfdefault\bbl at save@sfdefault
     \bbl at tempb{tt}\ttdefault\bbl at save@ttdefault}}

\def\bbl at FSstore#1#2#3#4{%
   \bbl at csarg\edef{#2default#1}{#3}%
   \expandafter\addto\csname extras#1\endcsname{%
     \let#4#3%
     \ifx#3\f at family
       \edef#3{\csname bbl@#2default#1\endcsname}%
       \fontfamily{#3}\selectfont
     \else
       \edef#3{\csname bbl@#2default#1\endcsname}%
     \fi}%
   \expandafter\addto\csname noextras#1\endcsname{%
     \ifx#3\f at family
       \fontfamily{#4}\selectfont
     \fi
     \let#3#4}}

\let\bbl at langfeature\@empty

\def\babelFSfeature{%
   \let\bbl at ori@fontspec\fontspec
   \renewcommand\fontspec[1][]{%
     \bbl at ori@fontspec[\bbl at langfeature##1]}
   \let\babelFSfeature\bbl at FSfeature
   \babelFSfeature}

\def\bbl at FSfeature#1#2{%
   \expandafter\addto\csname extras#1\endcsname{%
     \babel at save\bbl at langfeature
     \edef\bbl at langfeature{Language=#2,}}}

\makeatother
%============

\setmainfont[Language=Turkish]{Minion Pro}
\setsansfont[Language=Turkish]{Myriad Pro}
\babelFSstore{turkish}

\setmainfont{Minion Pro}
\setsansfont{Myriad Pro}

\babelFSfeature{turkish}{Turkish}

\begin{document}

fi \sffamily fi \fontspec{Antykwa Poltawskiego} fi \sffamily

\selectlanguage{turkish}

fi \rmfamily fi \fontspec[Language=French]{Antykwa Poltawskiego} fi
\fontspec{Antykwa Poltawskiego} fi \rmfamily

\selectlanguage{english}

fi \sffamily fi \fontspec{Antykwa Poltawskiego} fi \sffamily

\selectlanguage{turkish}

fi \rmfamily fi \fontspec{Antykwa Poltawskiego} fi

\end{document}






More information about the XeTeX mailing list