# setting font size in XeLaTeX

Previous questions have sought a straightforward way to specify font size (e.g., in points) of a new font family when using fontspec. One reason for why this might be needed is that some journals require specific font sizes of various pieces of text—such as 9.5pt or 11.5pt, which most document classes don't support.

Previous popular answers have suggested using Scale, which can supposedly simply act as a factor to the font size that is fed to the document class in order to have control over specific font size. For example, if 10pt is specified for the document class, and Scale=1.2 for a new font family, then one should expect that font to display at a size of 12 points.

Using Scale in this way works fine when the font being scaled is the main font. However, when a different font is involved, Scale=1.0 produces a different size font than Scale=MatchLowercase. With the example above, with a document font size of 10pt, I presume this new font would also be 10pt using Scale=MatchLowercase and not Scale=1.0. However, I don't understand enough about the inner workings of fontspec or font metrics in general to know if this is right.

A mwe of this example is provided here:

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{DejaVu Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\dejavusansten[Scale=1.0]{DejaVu Sans}
\newfontfamily\dejavusanstwelve[Scale=1.2]{DejaVu Sans}

\begin{document}

This is a test of DejaVu Serif, as mainfont\\

{\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}\\

{\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}\\

\textsf{This is a test of DejaVu Sans, MatchLowercase}\\

{\dejavusansten This is a test of DejaVu Sans, Scale=1.0}\\

{\dejavusanstwelve This is a test of DejaVu Sans, Scale=1.2}\\

\end{document}


Output:

In this example, two DejaVu fonts are used, so the different fonts with equal values of Scale appear to be about the same size. However, when the fonts are entirely different, this is not the case. A modified version of the mwe above, with Latin Modern Sans instead of DejaVu Sans, is provided here:

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\lmsansten[Scale=1.0]{Latin Modern Sans}
\newfontfamily\lmsanstwelve[Scale=1.2]{Latin Modern Sans}

\begin{document}

This is a test of DejaVu Serif, as mainfont\\

{\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}\\

{\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}\\

\textsf{This is a test of Latin Modern Sans, MatchLowercase}\\

{\lmsansten This is a test of Latin Modern Sans, Scale=1.0}\\

{\lmsanstwelve This is a test of Latin Modern Sans, Scale=1.2}\\

\end{document}


Output:

In this example, the MatchLowercase version of Latin Modern Sans appears to be the same size as the DejaVu Serif main font, while the Scale=1.0 version appears to be much smaller.

My question is whether using Scale like this to set exact font sizes is really a reasonable approach. If so, then is the assumption that even though the second font "looks" like it's a different size at a numerically equal scale, it's really the same size, in font points? An accompanying good explanation of the relevant aspects of font metrics and/or fontspec are also welcome.

use the SizeFeature instead of Scale. The last line shows that the two 10pt lines have the same height:

\documentclass[10pt]{article}
\usepackage{fontspec}
\parindent=0pt
\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[SizeFeatures={Size=10}]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[SizeFeatures={Size=12}]{DejaVu Serif}

\newfontfamily\lmsansten[SizeFeatures={Size=10}]{Latin Modern Sans}
\newfontfamily\lmsanstwelve[SizeFeatures={Size=12}]{Latin Modern Sans}

\begin{document}
This is a test of DejaVu Serif, as mainfont\\
{\dejavuseriften This is a test of DejaVu Serif, Size=10\\}
{\dejavuseriftwelve This is a test of DejaVu Serif, Size=12\\}

This\textsf{This is a test of Latin Modern Sans, MatchLowercase\\}% compare
%loercase
{\lmsansten This is a test of Latin Modern Sans, Size=10\\}
{\lmsanstwelve This is a test of Latin Modern Sans, Size=12\\}

\makebox[0pt][l]{This is a test of DejaVu Serif, as mainfont}%
{\lmsansten This is a test of Latin Modern Sans, Size=10\\}

\end{document}


• I notice that the output looks about the same as using Scale, but this seems like a better way (thanks!) to get that output. Can you provide any background on font metrics that explains why the result is like this? Semantically it seems better, but could it be understood as really just being equivalent to using Scale? – Jonathan W. Jun 19 '16 at 16:33
• Scale depends to the given size of the glyphs, whereas Size is an absolute value for the fontsize – user2478 Jun 19 '16 at 18:48
• If that's the case, then why is Latin Modern Sans 10 so much smaller than DejaVu Serif 10 in your example? – Jonathan W. Jun 19 '16 at 18:53
• that is an optical illusion. See the last line in my edited answer where I typeset both lines one over the other. They have the same height for uppercase but not for lowercase. The reason why the Latin Modern Sans looks smaller than the DejaVu Serif – user2478 Jun 19 '16 at 19:27
• Aha, interesting! Thank you for this. I'd like to mark this answer as accepted, but it would be nice to have some of the information from these comments integrated into the answer. – Jonathan W. Jun 19 '16 at 21:39

My advice is to not use Scale in this way. You'll note that you are defining a 'new font family' with \newfontfamily, so it is not reasonable to expect it to intuit that this 'new' family is in fact not new.

Perhaps a better way is to use the regular LaTeX2e font command, \DeclareTextCommand:

\documentclass[10pt]{article}
\parindent 0pt

\usepackage{fontspec,multicol,xcolor}% xcolor is just for fun...

\setmainfont{DejaVu Serif}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}

\newfontfamily\dejavuseriften[Scale=1.0]{DejaVu Serif}
\newfontfamily\dejavuseriftwelve[Scale=1.2]{DejaVu Serif}

\newfontfamily\dejavusansten[Scale=1.0]{Latin Modern Sans}
\newfontfamily\dejavusanstwelve[Scale=1.2]{Latin Modern Sans}

\DeclareTextCommand{\djx}{EU1}{\rmfamily\fontsize{10}{12}\selectfont}
\DeclareTextCommand{\djxii}{EU1}{\rmfamily\fontsize{12}{14.4}\selectfont}

\DeclareTextCommand{\lmsx}{EU1}{\sffamily\fontsize{10}{12}\selectfont}

\DeclareTextCommand{\textdjx}{EU1}[1]
{{\rmfamily\fontsize{10}{12}\selectfont #1}}
\DeclareTextCommand{\textdjxii}{EU1}[1]
{{\rmfamily\fontsize{12}{14.4}\selectfont #1}}

\DeclareTextCommand{\textlmsx}{EU1}[1]
{{\sffamily\fontsize{10}{12}\selectfont #1}}
\DeclareTextCommand{\textlmsxii}{EU1}[1]
{{\sffamily\fontsize{12}{14.4}\selectfont #1}}

\begin{document}

\section*{Scale' vs fontsize'}

\begin{multicols}{2}
This is a test of DejaVu Serif, as mainfont

{\dejavuseriften This is a test of DejaVu Serif, Scale=1.0}

{\dejavuseriftwelve This is a test of DejaVu Serif, Scale=1.2}

\columnbreak

This is a test of DejaVu Serif, as mainfont

{\djx This is a test of DejaVu Serif, at 10pt}

{\djxii This is a test of DejaVu Serif, at 12pt}
\end{multicols}

\begin{multicols}{2}
\textsf{This is a test of Latin Modern Sans, MatchLowercase}

{\dejavusansten This is a test of Latin Modern Sans, Scale=1.0}

{\dejavusanstwelve This is a test of Latin Modern Sans, Scale=1.2}

\columnbreak

\textsf{This is a test of Latin Modern Sans, as mainfont}

This is a test of Latin Modern Sans, at 10pt}

{\lmsxii This is a test of Latin Modern Sans, at 12pt}
\end{multicols}

\section*{rmfamily vs sffamily}

\begin{multicols}{2}
This is a test of DejaVu Serif, as mainfont

{\djx This is a test of DejaVu Serif, at 10pt}

{\djxii This is a test of DejaVu Serif, at 12pt}

\columnbreak

\textsf{This is a test of Latin Modern Sans, as mainfont}

at This is a test of Latin Modern Sans, at 10pt}

{\lmsxii This is a test of Latin Modern Sans, at 12pt}
\end{multicols}

\end{document}