7

When reproducing a typographic layout from print I often run into the usual difficulty of a font's "point size" not being easily measureable on a page. On the other hand, features such as x-height and cap-height are easy to measure but fontspec doesn't accept them as a size specification (as far as I know).

IOW, is something like \newfontface[xheight=<dim>]{EB Garamond} available?

  • Could you give an example or two of what you have in mind? You probably now that fontspec provides the Scale=<some positive scalar> option. However, from the description you've given so far I can'te tell if this option might be useful for you. – Mico Aug 12 '15 at 19:39
  • 1
    How do I get "EB Garamond at a point size such that x-height=4.78pt" with fontspec? – Jared Kulik Aug 12 '15 at 20:27
  • @JaredKulik May be that's not a job for fontspec but for the font size of the document? – Manuel Aug 12 '15 at 20:38
  • As you probably know, the "x-height" of a font and the height of the letter x are not always identical. E.g., for EB Garamond, the x-height is 4.0pt whereas the height of the (roman/upright) letter x is 4.05pt. Thus, measuring the heights of uppercase and lowercase letters may not give you the font's caps height and x-height, respectively. – Mico Aug 12 '15 at 21:31
  • Actually, I had hoped that wasn't the case but at least the delta should be reasonably small and good enough for a starting point, measurements invariably have an error component as well after all. – Jared Kulik Aug 12 '15 at 21:37
  • 2

1 Answers1

10

I assume you're using LuaTeX. If so, one can set up a macro called \Setxheight and use it with fontspec's Scale option. Note that the macro uses Lua's division routine instead of TeX's own built-in routine since the scaling factor will likely not be integer-valued.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
%% x-height of font is stored in \fontdimen5
\newcommand\Setxheight[1]{\directlua{%
    tex.sprint(#1/(\the\numexpr\dimexpr 
    \the\fontdimen5\font\relax\relax/65536))}}

\begin{document}
\setmainfont{EB Garamond}
\the\fontdimen5\font  % show value of x-height

\setmainfont[Scale=\Setxheight{4.78}]{EB Garamond} % reload the font

\the\fontdimen5\font % show value of x-height
\end{document}

Edit: XeLaTeX version

% !TEX TS-program = xelatex
\documentclass{article}
\usepackage{fontspec}
%% x-height of font is stored in \fontdimen5
\ExplSyntaxOn
\newcommand\Setxheight[1]{
\fp_eval:n{(#1/(\the\numexpr\dimexpr 
\the\fontdimen5\font\relax\relax/65536))}}
\ExplSyntaxOff

\begin{document}
\setmainfont{EB Garamond}
\the\fontdimen5\font  % show value of x-height

\setmainfont[Scale=\Setxheight{4.78}]{EB Garamond} % reload the font

\the\fontdimen5\font % show value of x-height
\end{document}
Mico
  • 506,678