How to create (in simple terms) a Monospace Font?

I have improved the script that can be run in the Macro Panel to slightly scale wide glyphs down horizontally:

# Make your font Monospace!
print("Script by Charles @ https://wonderunit.com/")
print("Improved by Philipp Guehring @ https://futureware.at/")

# JUST CHANGE THIS VALUE FOR WIDTH:
width = 660

maxchange=0.15 #0.15 means +-15% , if the glpyh is more than maxchange, then the change is limited to maxchange, this is to avoid too obvious thickness changes of 
minchange=0.01 #0.01 means +-1% , if the glyph is within +- minchange, the glyph is not changed at all, to avoid unnecessary changes
  
import math

# Clear the kerning table, if any
Glyphs.font.kerning = {}

#analyze how wide the glyphs need to be
maxwidth={}

num = 0

for glyph in Glyphs.font.glyphs:
  for layer in glyph.layers:
    glyphWidth = layer.bounds.size.width
    if glyphWidth > width:
        print(glyph.name+" on layer "+layer.name+" is too wide: "+str(glyphWidth))
      
for glyph in Glyphs.font.glyphs:
  for layer in glyph.layers:
    glyphWidth = layer.bounds.size.width
    factor=1
    if glyphWidth>0:
        factor=width/glyphWidth*0.96
    if factor < (1-maxchange):
        factor = (1-maxchange)
    if factor > (1+maxchange):
        factor = (1+maxchange)
    if factor<=(1-minchange): # or factor >=(1+minchange):
        print("Adapting "+glyph.name+" on "+layer.name+" from "+str(glyphWidth)+" with factor "+str(factor))
        for path in layer.paths:
            for node in path.nodes:
                node.x *= factor
    #recalculate:
    glyphWidth = layer.bounds.size.width
    leftSpace = math.floor((width - glyphWidth)/2)
    layer.LSB = leftSpace
    layer.width = width
    num+=1
    
print("Done! {} glyphs were monospaced.".format(num))

I have been thinking about using different widths for the different masters (I would call it “variable monospace”) so that the condensed monospace font would be thinner than the bold monospace font, but decided for a common width for now (I would call that “fixed monospace”), so that you can switch between font-widths without resulting in a different monospace width.

1 Like

I found at least one answer to this ancient question. The excellent Mac app HexFiend (https://hexfiend.com), a hexadecimal editor, has a Font menu which is built by accumulating only the installed fonts which have their fixed pitch flag set. (It’s open source and I verified that this is what the font menu code is doing under the hood.)

Just one data point here.