[NTG-context] \getscaledglyph for width-only

Brian R. Landy brian at landy.cx
Thu Aug 18 18:30:00 CEST 2016

On Thu, 18 Aug 2016, Hans Hagen wrote:

> On 8/18/2016 1:12 AM, Brian R. Landy wrote:
>>> On Aug 17, 2016, at 5:45 PM, Hans Hagen <pragma at wxs.nl> wrote:
>>> On 8/17/2016 9:56 PM, Brian R. Landy wrote:
>>>> Hi, I was wondering if there is a way to call \getscaledglyph to 
>>>> scale a
>>>> glyph only horizontally, leaving the height untouched?  Or maybe an
>>>> alternate command?
>>>> I can sort of accomplish this with (for example)
>>>> \scale[sx=0.75,sy=1.0]{}{A}, but that encloses the glyph in an 
>>>> \hbox,
>>>> which can be problematic.  \getscaledglyph doesn't cause me any
>>>> problems, except that it scales the height too.
>>> \starttext
>>> \definefontfeature[whatever][default][extend=2.5]
>>> \definedfont[Serif*whatever at 12pt]
>>> whatever
>>> \stoptext
>> Thank you.  One thing that \getscaledglyph does it works agnostic to 
>> the currently selected font.  For example:
> scaling glyphs in one direction is kind of bad anyway so if you want 
> just one glyph you can do
> \inframed{\scale[width=3em,height=1ex]{...}}
> or whatever suits the purpose

Agreed.  Here's a little more background, so it makes some sense why I 
want to scale horizontally, and then I describe my final solution.  I 
have a specific case where I use a minus, a hyphen-minus, and a plus 
close to each other, and it's always bugged me that most fonts don't 
vertically align the hyphen-minus with the other two glyphs. An example 


I was thinking that math fonts did align these symbols, hence my 
question on Monday on how to get the hyphen-minus in math mode (and 
thanks for the quick answer on that) but unfortunately was wrong.  So 
that got me searching for a way to horizontally shrink a minus, so it 
would retain the same height and line thickness as the minus. 
Horizontal-only scaling of a hyphen/dash/minus isn't so bad.

\scaled[] worked perfectly, but it breaks inside a natural table with 
character alignment enabled.  I have a commented example of this below. 
\getscaledglyph works in the table, but the vertical shrink is a 

Here's an example:


This is my starting point:

\bTR \bTD \mathminus100-00+ \eTD \eTR
\bTR \bTD           100-00  \eTD \eTR
\bTR \bTD \mathminus 99-00+ \eTD \eTR
\bTR \bTD \mathminus 99-00  \eTD \eTR

% This table won't typeset:
% \bTABLE[aligncharacter=yes,alignmentcharacter={text->:}]
% \bTR \bTD \mathminus100\scaled[sx=0.5,sy=1.0]{\mathminus}00:+ \eTD \eTR
% \bTR \bTD           100\scaled[sx=0.5,sy=1.0]{\mathminus}00:  \eTD \eTR
% \bTR \bTD \mathminus 99\scaled[sx=0.5,sy=1.0]{\mathminus}00:+ \eTD \eTR
% \bTR \bTD \mathminus 99\scaled[sx=0.5,sy=1.0]{\mathminus}00:  \eTD \eTR


But I came up with a solution that works.  Rather than attempt to shrink 
the minus glyph, I define a new glyph that corrects the height of the 

      local function addsmallminus(tfmdata)
          local hchar    = tfmdata.characters[0x002D]
          local mchar    = tfmdata.characters[0x2212]
          tfmdata.characters[0xFE000]   = {
              width    = hchar.width,
              height   = mchar.height,
              commands = {
                  { "down", hchar.height-mchar.height },
                  { "char", 0x002D },

      fonts.constructors.newfeatures("otf").register {
          name        = "smallminus",
          description = "small minus",
          manipulators = {
              base = addsmallminus,
              node = addsmallminus,




\bTR \bTD \mathminus100\smallminus00+ \eTD \eTR
\bTR \bTD           100\smallminus00  \eTD \eTR
\bTR \bTD \mathminus 99\smallminus00+ \eTD \eTR
\bTR \bTD \mathminus 99\smallminus00  \eTD \eTR


So this looks good and works with any font.  The only issue is fonts 
that use a different line thickness for the minus and hyphen-minus; this 
top-aligns the glyphs.

Is there a way to make this glyph available in math-mode?  I get a "?" 
when I try:


Thanks for all your help!


More information about the ntg-context mailing list