5

I tried looking for a way to use Alegreya Sans for math mode in pdfLaTeX. I see that it can be done using mathspec in XeLaTeX, but is there a way to do it in pdfLaTeX?

This is because I'm using Alegreya for body text, and I would like the math to "go" with the text. If this is not possible with pdfLaTeX, I would have to switch to XeLaTeX.

Thank you!

4

You can use newtxsf for the Greek letters and mathastext:

\documentclass{scrartcl}
\usepackage{newtxsf}
\usepackage[sfdefault]{AlegreyaSans}
\usepackage[italic]{mathastext}

\begin{document}

This is in Alegreya Sans, with math
$E=mc^2$ and $\sin(\alpha+\beta)=\pi$
\[
\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]

\boldmath Also bold math
$E=mc^2$ and $\sin(\alpha+\beta)=\pi$
\[
\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]

\end{document}

enter image description here

For serif text and sans serif math (but why?), you can use a trick suggested in the manual of mathastext:

\documentclass{scrartcl}
\usepackage{newtxsf}
\usepackage{Alegreya,AlegreyaSans}

\renewcommand\familydefault\sfdefault
\usepackage[italic]{mathastext}
\renewcommand\familydefault\rmdefault

\begin{document}

This is in Alegreya Sans, with math
$E=mc^2$ and $\sin(\alpha+\beta)=\pi$
\[
\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]

\boldmath Also bold math
$E=mc^2$ and $\sin(\alpha+\beta)=\pi$
\[
\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]

\end{document}

enter image description here

  • Perfect; thank you! However, this changes all text to Alegreya Sans. I'm using Alegreya for body text and would like to use Alegreya Sans for math. Is this possible? \rmdefault is not a recognised option with Alegreya. – Ram Iyer Oct 8 '16 at 15:19
  • 1
    @ram7489 Really? What would be the reason for this? However, I added the code. – egreg Oct 8 '16 at 15:27
  • I'm writing a book. Serif font makes the text easier to read. Math, however, looks much better with sans serif. Just my opinion, though. – Ram Iyer Oct 8 '16 at 15:28
  • Here's a sample of what the math looks like in Alegreya (serif). Not even sure if this is acceptable. – Ram Iyer Oct 8 '16 at 15:35
2
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{Alegreya,AlegreyaSans}
\DeclareMathAlphabet{\mathrm}  {T1}{AlegreyaSans-LF}{m}{n}
\SetMathAlphabet{\mathrm}{bold}{T1}{AlegreyaSans-LF}{b}{n}

\DeclareMathAlphabet{\mathit}  {T1}{AlegreyaSans-LF}{m}{it}
\SetMathAlphabet{\mathit}{bold}{T1}{AlegreyaSans-LF}{b}{it}

\DeclareMathAlphabet{\mathbf}  {T1}{AlegreyaSans-Bold-lf-t1}{b}{n}
\SetMathAlphabet{\mathbf}{bold}{T1}{AlegreyaSans-Bold-lf-t1}{b}{n}

\DeclareSymbolFont{operators}  {T1}{AlegreyaSans-LF}{m}{n}
\SetSymbolFont{operators}{bold}{T1}{AlegreyaSans-LF}{b}{n}
\DeclareSymbolFont{letters}    {T1}{AlegreyaSans-LF}{m}{it}
\DeclareSymbolFont{lettersA}   {OML}{zplm}{m}{it}%  for greek letters
\SetSymbolFont{letters}{normal}{T1}{AlegreyaSans-LF}{m}{it}
\SetSymbolFont{letters}{bold}  {T1}{AlegreyaSans-LF}{b}{it}

\DeclareMathSymbol{\alpha}{\mathalpha}{lettersA}{"0B}
\DeclareMathSymbol{\beta}{\mathalpha}{lettersA}{"0C}
\DeclareMathSymbol{\gamma}{\mathalpha}{lettersA}{"0D}
\DeclareMathSymbol{\delta}{\mathalpha}{lettersA}{"0E}
\DeclareMathSymbol{\epsilon}{\mathalpha}{lettersA}{"0F}
\DeclareMathSymbol{\zeta}{\mathalpha}{lettersA}{"10}
\DeclareMathSymbol{\eta}{\mathalpha}{lettersA}{"11}
\DeclareMathSymbol{\theta}{\mathalpha}{lettersA}{"12}
\DeclareMathSymbol{\iota}{\mathalpha}{lettersA}{"13}
\DeclareMathSymbol{\kappa}{\mathalpha}{lettersA}{"14}
\DeclareMathSymbol{\lambda}{\mathalpha}{lettersA}{"15}
\DeclareMathSymbol{\mu}{\mathalpha}{lettersA}{"16}
\DeclareMathSymbol{\nu}{\mathalpha}{lettersA}{"17}
\DeclareMathSymbol{\xi}{\mathalpha}{lettersA}{"18}
\DeclareMathSymbol{\pi}{\mathalpha}{lettersA}{"19}
\DeclareMathSymbol{\rho}{\mathalpha}{lettersA}{"1A}
\DeclareMathSymbol{\sigma}{\mathalpha}{lettersA}{"1B}
\DeclareMathSymbol{\tau}{\mathalpha}{lettersA}{"1C}
\DeclareMathSymbol{\upsilon}{\mathalpha}{lettersA}{"1D}
\DeclareMathSymbol{\phi}{\mathalpha}{lettersA}{"1E}
\DeclareMathSymbol{\chi}{\mathalpha}{lettersA}{"1F}
\DeclareMathSymbol{\psi}{\mathalpha}{lettersA}{"20}
\DeclareMathSymbol{\omega}{\mathalpha}{lettersA}{"21}
\DeclareMathSymbol{\varepsilon}{\mathalpha}{lettersA}{"22}
\DeclareMathSymbol{\vartheta}{\mathalpha}{lettersA}{"23}
\DeclareMathSymbol{\varpi}{\mathalpha}{lettersA}{"24}
\DeclareMathSymbol{\varrho}{\mathalpha}{lettersA}{"25}
\DeclareMathSymbol{\varsigma}{\mathalpha}{lettersA}{"26}
\DeclareMathSymbol{\varphi}{\mathalpha}{lettersA}{"27}
\DeclareMathSymbol{\ldotp}{\mathpunct}{lettersA}{"3A}

\begin{document}\sffamily
 sin(x) $E=mc^2$ $\mathit{E=mc^2}$ \itshape E=mc$^2 \sin(x) \alpha\beta$

\upshape\boldmath
 sin(x) $E=mc^2$ $\mathit{E=mc^2}$ \itshape\bfseries E=mc$^2 \sin(x) \alpha \beta$ 

\end{document}

enter image description here

  • your solution works perfectly. However, \ldots gives out ::: instead of .... Could you help with that, please? – Ram Iyer Oct 8 '16 at 18:15
  • 1
    add the line before \begin{document} in my edited answer – user2478 Oct 8 '16 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.