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?

6
  • 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
  • 2
    Nice idea! <github.com/wspr/fontspec/issues/210> – Will Robertson Aug 13 '15 at 1:30
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}
4
  • 1
    That works fine. Can you manage a xetex version for completeness? – Jared Kulik Aug 12 '15 at 21:40
  • @JaredKulik - I'm afraid I don't know how to do division arithmetic in XeTeX. Maybe a more knowledgeable person will jump in and provide a parallel answer. – Mico Aug 12 '15 at 21:59
  • 3
    @JaredKulik — Untested: replace \directlua{tex.sprint( by \fp_eval:n{( and surround the definition of Setxheight in \ExplSyntaxOn...\ExplSyntaxOff. – Will Robertson Aug 13 '15 at 1:31
  • Yup, that works. – Jared Kulik Aug 13 '15 at 1:51

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.