1

Somehow I cannot get the AlegreyaSans font to work in Beamer with mathspec. The standard fontenc call for AlegreyaSans works for PDFLaTeX, but I need to use auto-pst-pdf for a table, thus the use of XeLaTeX (please correct me if I'm wrong there!). As such, I hope to specify the math font in XeLaTeX, thus the use of mathspec. But somehow I cannot manage to get it to work; I constantly receive: "AlegreyaSans-Regular" cannot be found. See the given MWE.

I've wondered if it's an issue with a dash or space: Alegreya Sans vs. AlegreyaSans vs. Alegreya-Sans, but this does nothing. I have checked the fonts on the system: they are definitely titled AlegreyaSans-Regular, etc.

I'm using TeXLive 2015 on OSX.11.13.

EDIT: AlegreyaSans is a free font; it can be downloaded for free here.

\documentclass{beamer}
\usepackage{mathspec}
%\usepackage[T1]{fontenc}
%\usepackage[sfdefault]{AlegreyaSans}
\setmainfont[
    Extension = .otf, %does not work with ttf either
    UprightFont = AlegreyaSans-Regular,
    ItalicFont = AlegreyaSans-Italic,
    BoldFont = AlegreyaSans-Bold,
    BoldItalicFont = AlegreyaSans-BoldItalic,
    UprightFeatures = {SmallCapsFont = AlegreyaSansSC-Regular},
    ItalicFeatures = {SmallCapsFont = AlegreyaSansSC-Italic},
    BoldFeatures = {SmallCapsFont = AlegreyaSansSC-Bold},
    BoldItalicFeatures = {SmallCapsFont = AlegreyaSansSC-BoldItalic},
    Ligatures = TeX]
    {AlegreyaSans}
\setmathsfont(Digits,Latin,Greek)[Numbers={Lining,Proportional}]{AlegreyaSans}
\makeatletter
     \DeclareMathSymbol{0}{\mathalpha}{\eu@DigitsArabic@symfont}{`0}
     \DeclareMathSymbol{1}{\mathalpha}{\eu@DigitsArabic@symfont}{`1}
     \DeclareMathSymbol{2}{\mathalpha}{\eu@DigitsArabic@symfont}{`2}
     \DeclareMathSymbol{3}{\mathalpha}{\eu@DigitsArabic@symfont}{`3}
     \DeclareMathSymbol{4}{\mathalpha}{\eu@DigitsArabic@symfont}{`4}
     \DeclareMathSymbol{5}{\mathalpha}{\eu@DigitsArabic@symfont}{`5}
     \DeclareMathSymbol{6}{\mathalpha}{\eu@DigitsArabic@symfont}{`6}
     \DeclareMathSymbol{7}{\mathalpha}{\eu@DigitsArabic@symfont}{`7}
     \DeclareMathSymbol{8}{\mathalpha}{\eu@DigitsArabic@symfont}{`8}
     \DeclareMathSymbol{9}{\mathalpha}{\eu@DigitsArabic@symfont}{`9}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{frame}
1 $S_1$
\end{frame}

\end{document}
Richard
  • 2,084

1 Answers1

5

The default beamer theme uses the sans serif font. So if you want to change the font in beamer you either have to set the sans font with \setsansfont or change to the serif font theme \usefonttheme{serif}.

fontspec usually does a very good job setting the font features automatically, if you load them by font name. So in case of the Alegreya font it should be enough to just set the font family and the small caps fonts.

\setsansfont[UprightFeatures = {SmallCapsFont = Alegreya Sans SC},
             ItalicFeatures = {SmallCapsFont = Alegreya Sans SC Italic},
             BoldFeatures = {SmallCapsFont = Alegreya Sans SC Bold},
             BoldItalicFeatures = {SmallCapsFont = Alegreya Sans SC Bold Italic}]{Alegreya Sans}

In case of the math font I would also propose to load the font by font name (I actually don't know if mathspec even supports loading fonts by filename). So here the following line should be enough.

\setmathsfont(Digits,Latin,Greek)[Numbers={Lining,Proportional}]{Alegreya Sans}

But the numbers setting Lining doesn't seem to work. To solve this you have to use the class option professionalfont, which suppresses some internal replacements performed by beamer. For more information on this have a look into the beamer manual.

Complete MWE:

\documentclass[professionalfont]{beamer}
\usepackage{mathspec}
\setsansfont[UprightFeatures = {SmallCapsFont = Alegreya Sans SC},
             ItalicFeatures = {SmallCapsFont = Alegreya Sans SC Italic},
             BoldFeatures = {SmallCapsFont = Alegreya Sans SC Bold},
             BoldItalicFeatures = {SmallCapsFont = Alegreya Sans SC Bold Italic}]{Alegreya Sans}
\setmathsfont(Digits,Latin,Greek)[Numbers={Lining,Proportional}]{Alegreya Sans}

\begin{document}

\begin{frame}{Font feature test}
  \begin{itemize}
    \item Regular
    \item \textit{Italic}
    \item \textsc{SmallCaps}
    \item \textbf{Bold}
    \item \textbf{\textit{Bold Italic}}
    \item \textbf{\textsc{Bold SmallCaps}}
    \item \textbf{\textsc{\textit{Bold Italic SmallCaps}}}
    \item Math: $a^2+b^2 = c^2$
    \item Numbers in Math: $1234567890$
  \end{itemize}
\end{frame}

\end{document}

Output:

output

Benjamin
  • 4,781
  • This is terrific @Benjamin, thanks! I should have known to have used setsansfont--just a dumb mistake on my part--but the rest was still needed. Thanks again! – Richard Feb 13 '16 at 21:50
  • professionalfont option was necessary to circumvent missing fonts with beamer class. – Vesnog May 09 '17 at 15:31