# Fontspec matching lower case between roman, mono and math fonts

I have been trying to make roman, mono and math fonts match the lower case. More specifically, I am using Palatino for roman, AMS-Euler for math and dejavu sans for mono. However, I have been unsuccessful so far. The situation that I have is shown in the picture. From the left to the right, we have the math font, the roman font and mono font.

Here is the MWE

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex

\documentclass[a4paper,12pt]{article}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text,Ligatures={TeX,Common},Scale=MatchLowercase,Color=textcolor}
\defaultfontfeatures[\rmfamily]{Scale=1} % To scale all fonts correctly

\setromanfont[Numbers=OldStyle]{Palatino Linotype}
\setmainfont[Numbers=OldStyle]{Palatino Linotype}
\setmonofont{DejaVuSansMono.ttf}
% Setting Euler as math font
\usepackage[math-style=TeX,vargreek-shape=unicode,math-style=upright]{unicode-math}

\begin{document}

Upper case: $W$W{\tt W}

Lower case: $w$w{\tt w}

\end{document}


Would someone know how to scale these fonts so that the upper and/or the lower case matches?

• For some reason I don't claim to understand, the code you've presented works -- meaning that the x-heights of the lowercase letters are matched -- doesn't work as expected under XeLaTeX. However, it does work under LuaLaTeX. – Mico Sep 26 '16 at 13:15
• Thank you for your response, Mico. However my question is why it does not work with Xelatex – Cybernetician Sep 26 '16 at 20:20
• As I noted in my comment, I do not know either why the Scale=MatchLowercase option doesn't work as expected under XeLaTeX. :-( – Mico Sep 26 '16 at 20:22

\begin{EDIT}{2018-05-17}

You might want to look at this answer going into detail about how best to use Neo Euler. One major thing to consider, is that Neo Euler hasn't been worked since 2011 and the github repo states

this project is abandoned, the repository is left for achælogical purposes

so I don't know if using Euler, AMS Euler or Neo Euler is still a good idea. You might want to leave the dead rest in peace and work with living fonts. Have a look at the latest version unicode-math documentation to make a more educated decision as to how to best move on.

\end{EDIT}

The option Scale=MatchLowercase works under XeLaTeX. I have found by chance, that the "correct" way to do it is to follow Example 1 of the documentation:

\setmainfont{texgyrebonum-regular.otf}
\setsansfont{lmsans10-regular.otf}[Scale=MatchLowercase]
\setmonofont{Inconsolatazi4-Regular.otf}[Scale=MatchLowercase]


that is, not to set the Scale=MatchLowercase as an argument in

\defaultfontfeatures{...}


but rather as an optional argument of the "secondary" fonts, which will then orient themselves to the main font, which has been set by \setmainfont{...}

Second (yeahr, I ain't mentioned 'first', get over it), from the fontspec documentation, we get:

The fontspec package must also be loaded after any maths font packages (e.g., euler) to be successful. (Actually, it is only euler that is the problem.5)

5: Speaking of euler, if you want to use its [mathbf] option, it won’t work, and you’ll need to put this after fontspec is loaded instead: \AtBeginDocument{\DeclareMathAlphabet\mathbf{U}{eur}{b}{n}

Third, there seems to be a problem with Palatino Linotype as main font, since the following code...

\documentclass{article}
\usepackage[math-style=upright]{unicode-math}
\setmathfont[Color={00D419},Scale=MatchLowercase]{ams-euler.otf}
\usepackage{fontspec}
\setmainfont{Palatino Linotype}
\setmonofont[Color={0019D4},Scale=MatchLowercase]{DejaVu Sans Mono}
\begin{document}
Upper case: $W$W{\tt W}

Lower case: $w$w{\tt w}
\end{document}


yields

but if I just change the font to, say Libertinus Serif (I didn't test other ones), ...

\documentclass{article}
\usepackage[math-style=upright]{unicode-math}
\setmathfont[Color={00D419},Scale=MatchLowercase]{ams-euler.otf}
\usepackage{fontspec}
\setmainfont{Libertinus Serif}
\setmonofont[Color={0019D4},Scale=MatchLowercase]{DejaVu Sans Mono}
\begin{document}
Upper case: $W$W{\tt W}

Lower case: $w$w{\tt w}
\end{document}


we get nicely lowercase-matched types. It also works with MatchUppercase.

PS: Could anyone enlighten me as to where \setromanfont comes from? This term is nowhere to be found in the fontspec documentation.