# Can I turn a variable width font into a fixed-width font?

I found a free ancient-typewriter font I'd like to use in a project, but the person who made it apparently traced some scanned outlines and poured them into a variable width truetype font. That is not very typewritery, and I'd rather repair that. Can I do that from inside XeLaTeX/fontspec/microtype or will I have to learn how to use a full-blown font editor like fontforge?

The project is a book where various chapters have different "moods" and narrative perspectives and I'm trying to reflect them in the font used. The old-typewriter font is for an exchange of letters between two agencies in the 1950s. So, I guess I'd need hyphenation, for example.

• What kind of text do you want to typeset? Depending on the details, it could be possible to place each character in a fixed-width box (this can be done automatically). – Bruno Le Floch Jun 3 '14 at 19:20
• Note that Latin Modern features a variable width typewriter, along with the mono one. It still looks fairly typewritery although I assume you are right about the most realistic option. @BrunoLeFloch Wouldn't fixed width boxes break hyphenation? – cfr Jun 3 '14 at 23:54
• @cfr Good catch. The soul package might help, since it has the tools to analyse text and find hyphenation points (it provides letterspacing out of the box, but that is not quite what you need). – Bruno Le Floch Jun 4 '14 at 12:48
• Something like \usepackage{soul}\newcommand{\fw}[1]{\begingroup\def\SOUL@everytoken{\hbox to 7pt{\hfil\the\SOUL@token\hfil}}\SOUL@{#1}\endgroup} might work to define an \fw command which places each character in a box but still respects hyphenation. Not tested, and probably incomplete. – Bruno Le Floch Jun 4 '14 at 12:53
• Yes, the monospacing is there. Albeit without the spaces/whitespace, and apparently without hyphenation. I fiddled around with fontforge, and find that editing the font itself is probably the proper way to go. – Blackface Jun 4 '14 at 20:38

You can use the luaotfload.patch_font callback when using LuaTeX. Here I just go over the complete font to find the widest glyph (probably emdash or so) and the go over the font a second time and set every character's width to the maximum.

It might be better to just go over the alphabetic range instead of the whole font when finding the maximum, but then I don't have your font and I don't know your intentions.

\documentclass{article}
\usepackage{fontspec}
\directlua{

local function monospace(tfmdata)
local max = 0
for _,char in pairs(tfmdata.characters) do
max = max < char.width and char.width or max
end
print(max)
for _,char in pairs(tfmdata.characters) do
char.width = max
end
end


}