fontspec
fontspec copied to clipboard
Auto-detect monospace fonts
By testing the widths of the i and m glyphs, we should be able to check whether the current font is monospaced. In which case, we should specify sensible defaults for the WordSpace and PunctuationSpace options -- for the latter, even an option to add two ‘spaces’ instead of one might be a nice customisation.
These should also be controlled by an explicit fontspec font feature that is not passed to fonts loaded with \setmonofont but can be if desired (because the heuristic fails or the user wants to bypass the test, for efficiency). I.e., \setmonofont will still detect monospace fonts according to the feature above, but if you load a non-monospace font here (the command should really be called \setcodefont) we don't want the spaces to be screwed up.
See additional (excellent) comments here.
I think we should not bother with auto-detection and just set the correct \fontdimens with \setmonofont and may be provide and option to do the same for other font loading comments. For documentations purposes, the dimensions to be set are:
- 3 (stretch): 0pt
- 4 (shrink): 0pt
- 7 (extra space): the same as 2 (space)