[XeTeX] Nice (plain xetex) macro to ensure matching font sizes

Ron Aaron ron at ronware.org
Wed May 11 13:35:49 CEST 2011


I'm using two different fonts in a Hebrew translation I'm doing, but
ending up with different character heights when I give them the same "at
...pt".  Trial and error gets me close to a matching size, but when I
changed the base font size I had to go through a trial-and-error phase
again.  So it occurred to me that xetex should do the hard work for me.

Here is the macro I'm using, with an example of how I use it:

\newcount\fitfontscaling
\newtoks\fitfonttoks
\def\fitfont#1#2{%
	\begingroup
	\setbox0\hbox{\the\fitfonttoks #2}
	\dimen0=\ht0
	\font\tempfont="#1" scaled 1000
	\setbox1\hbox{\tempfont #2}
	\dimen1=\ht1
	\divide\dimen1 by 1000
	\divide\dimen0\dimen1
	\global\fitfontscaling=\dimen0
	\endgroup
}
\fitfonttoks={\hnormal}
\fitfont{SBL Hebrew:script=hebr,language=IWR,mapping=tex-text,+calt}{אמת}


The macro "\fitfont" takes the name of the font you want to 'fit' as
parameter #1, and sample text you want to 'fit', as the second
parameter.  It sets "\fitfontscaling" to the value you need to use to
scale font #1 so it 'fits' the other font.  Use "\fitfonttoks" to set
whatever font etc. you need before testing the sample text.

In the sample two lines after the macro, you can see how I decide what
scaling factor to use to match my body font ("\hnormal").  Then I have
this line to create the font at the correct size:

\font\hpasuq="SBL
Hebrew:script=hebr,language=IWR,mapping=tex-text,+calt" scaled
\fitfontscaling


More information about the XeTeX mailing list