6

After discovering the magic of microtype, I've decided to switch to LuaLaTeX from XeLaTeX for a large document. Unfortunately, I'm having some difficulties mimicking my mathspec practices from the prior engine; the desired font is Alegreya. Here's what I'm trying to fix:

  1. Music accidentals ($\flat \sharp \natural$) should all be the standard Computer Modern glyphs. I clarify this because, as shown in the MWE, I'm also using the lilyglyphs package.

  2. All superscript and subscript numbers should be Alegreya (with old-style numbers). This is easy enough with amsmath's \text in math-mode, but I use it so often I'd like to make it the default.

  3. Letters in math mode ($x$, for instance) should be Alegreya italic.

I've experimented with some unicode-math fixes, but I can't seem to get what I'm looking for.

MWE:

%LuaLaTeX
\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage[osf]{Alegreya}
\usepackage{amsmath} %% \text in math mode

%\usepackage{unicode-math}
%\setmathfont[]{Alegreya} %% option range=0048-0057 ?

\let\origflat\flat %% this is included just in case; I use lilyglyphs but not its sharp, flat, or natural
\let\origsharp\sharp
\let\orignatural\natural
\usepackage{lilyglyphs}
\let\flat\origflat
\let\sharp\origsharp
\let\natural\orignatural

\begin{document}

$x$ and $y$ %% should be Alegreya italic

$\flat \sharp \natural$ % should all be standard CM

$^5_3$ %% should be Alegreya, old-style numbers

\end{document}
Richard
  • 2,084

1 Answers1

8

To have the text font in math mode, you might want to use the mathastext package. To use this package with LuaLaTeX you also have to load fontspec with the no-math option. Because fontspec is loaded internally by Alegreya we do

\PassOptionsToPackage{no-math}{fontspec}
\usepackage[osf]{Alegreya}
\usepackage[italic]{mathastext}

Instead of saving and restoring the definitions of \flat, \natural and \sharp, we simply undefine them and redeclare them with their original mathcodes and the Computer Modern family. We do so after loading lilyglyphs.

\usepackage{lilyglyphs}
\let\flat\undefined \let\natural\undefined \let\sharp\undefined
\DeclareMathSymbol\flat   \mathord{letters}{"5B}
\DeclareMathSymbol\natural\mathord{letters}{"5C}
\DeclareMathSymbol\sharp  \mathord{letters}{"5D}

Additionally, the \usepackage[T1]{fontenc} is superfluous, as the fontspec package will switch to TU encoding anyway. Also, \usepackage{amsmath} is not needed for the example.

\documentclass{article}
\PassOptionsToPackage{no-math}{fontspec}
\usepackage[osf]{Alegreya}
\usepackage[italic]{mathastext}
\usepackage{lilyglyphs}
\let\flat\undefined \let\natural\undefined \let\sharp\undefined
\DeclareMathSymbol\flat   \mathord{letters}{"5B}
\DeclareMathSymbol\natural\mathord{letters}{"5C}
\DeclareMathSymbol\sharp  \mathord{letters}{"5D}
\begin{document}

$x$ and $y$ % should be Alegreya italic

$\flat \sharp \natural$ % should all be standard CM

$^5_3$ % should be Alegreya, old-style numbers

\end{document}

enter image description here

Henri Menke
  • 109,596