[Tex/LaTex] Changing the Greek math font with mathspec

fontsfontspecgreekmathspecxetex

I've recently changed from pdftex to xetex to be able to write documents in Bembo Std but I'm not quite there yet. While trying to typeset some notes from one of my classes, I tried to typeset Greek symbols both inside (italic) and outside (non italic) of math mode. I tried to type an alpha with the Greek keyboard layout on Mac OS X 10.8 which worked, provided the font has a glyph for it, and I tried to change the font for Greek characters in math mode with the following:

\usepackage{mathspec} 
\setmainfont[Ligatures={Tex}]{Bembo Std}
\setmathsfont(Digits,Latin)[Scale=MatchLowercase]{Bembo Std}
\setmathsfont(Greek)[Scale=MatchLowercase]{STIXGeneral}

I'm using texlive 2012 with Texpad on Mac OS X 10.8. When trying the code above, xetex fails to typeset and seems to be stuck in an infinite loop. Commenting out the last line will make it typeset, but the used font for Greek letters will be Computer Modern. (Bembo Std doesn't contain any Greek glyphs (or at least my version doesn't) hence STIXGeneral.)

I've tried to find the cause of this problem in the log file, but I didn't get any wiser from reading it.

A minimal example:

\RequirePackage[l2tabu, orthodox]{nag} 

% Opmaak
\documentclass[11pt,oneside]{article}
\usepackage[a4paper]{geometry}
% \usepackage[artemisia]{textgreek}
 \usepackage[final,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}

% Wiskunde
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage[math]{mathspec}
\setmainfont[Ligatures={Tex}]{Bembo Std}
\setmathsfont(Digits,Latin)[Scale=MatchLowercase]{Bembo Std}
% \setmathsfont(Greek)[Scale=MatchLowercase]{STIXGeneral}

% Varia
\usepackage{polyglossia}
\setdefaultlanguage{dutch}
\usepackage{hyperref}

\begin{document}

\section{Les 8}
De boeken worden vaak aangeduid met Romeinse cijfers, maar ook met Griekse letters. Zo staat boek I ook gekend als boek A, boek II als boek α $\alpha$ (kleine alpha) en alle volgende boeken krijgen de alfabetisch hier op volgende Griekse letter toegewezen. 

\end{document}

How can I typeset Greek letters in mathmode in a different font? How can I typeset upright Greek letters with another font of my choice if the main font doesn't contain any glyphs for it?

Best Answer

This problem arises in connection with the shorthands in Babel style that were introduced in Polyglossia after mathspec was released.

Basically the shorthand active character " gets a definition that overrides the one given by mathspec and infinite loops are behind the corner.

\documentclass[11pt,oneside]{article}
\usepackage[a4paper]{geometry}
\usepackage[final]{microtype}


% Wiskunde
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{mathspec}
\setmainfont[Ligatures=TeX]{Junicode}
\setmathsfont(Digits,Latin)[Scale=MatchLowercase]{Junicode}
\setmathsfont(Greek)[Scale=MatchLowercase]{STIXGeneral}

%%% this patch must go before loading polyglossia
\makeatletter
\begingroup\lccode`~=`"
\lowercase{\endgroup
  \everymath{\let~\eu@active@quote}
  \everydisplay{\let~\eu@active@quote}
}
\makeatother

\usepackage{polyglossia}
\setmainlanguage{dutch}

% Varia
\usepackage{hyperref}


\begin{document}

\section{Les 8}

De boeken worden vaak aangeduid met Romeinse cijfers, maar ook met Griekse 
letters. Zo staat boek I ook gekend als boek A, boek II als boek α $α$ $\alpha$
(kleine alpha) en alle volgende boeken krijgen de alfabetisch hier op volgende 
Griekse letter toegewezen.

\end{document}

I used Junicode as I don't have Bembo, but it's just the same. Also I showed that you can type both $α$ or $\alpha$ getting the same symbol.

enter image description here