0

I am hoping to produce a custom version of all Computer Modern glyphs, where the parameters are tweaked such that the pen strokes are very thin (essentially no filling, just central skeleton strokes). My objective is to use autotrace to convert those strokes to SVG paths, resulting in single-stroke glyphs for use in other programs (pen-plotters, Mathjax, etc.)

The Metafont and CM books are a bit overwhelming, so I would appreciate advice / simple examples to point me in the right direction, specifically:

  1. How would one go about producing all of CM's glyphs, with a current TeX distribution?

  2. What's the best place to find all the parameters that will need to be tuned to make thin, constant-width strokes?

Edit: to clarify, here's a depiction of what I'm after

Starting from the Metafont sources (here copied from Wikipedia)

%file name: beta.mf
%mode_setup;
% Define a beanlike shape for the character B
beginchar("B",11pt#,11pt#,0);
  % Setup coordinates as an equation system
  y1=y2=y3=0;
  y4=y5=y6=h;
  x1=x4=0;
  x2=x5=w;
  x3=x6=2*w;

  % Define pen
  pickup pencircle xscaled 0.2w yscaled 0.04w rotated 45;

  % Draw the character curve
  % z1 is the same as (x1, y1)
  draw z1..z3..z6{z2-z6}..z5..{z4-z2}z4..cycle;
endchar;

end

one can produce a glyph (raster or vector, it's not important), which is then processed by autotrace (e.g. via Inkscape) to get just the central line,

screenshot of the autotrace

Now, I wish to do this programmatically for over 2200 glyphs from Computer Modern, and many have strokes that will confuse the algorithm because they vary too much in thickness. I would like to help the autotrace algorithm by first producing a version of CM glyphs that have nearly uniform strokes.

3
  • Welcome to the site! Have you checked out cmathbb?
    – Davislor
    May 6 at 23:53
  • The original METAFONT sources are designed to produce bitmap, not outline fonts. For a new variant of Computer Modern, you might want to edit an OpenType clone in a program such as FontForge.
    – Davislor
    May 7 at 0:12
  • @Davislor I've edited the question, hopefully it's clearer now May 7 at 2:25

1 Answer 1

1

The Metafont sources for CM fonts are in fonts/source/public/cm/ in TeXlive. Each file with real font name (for example cmr10.mf) includes setting about 60 parameters and the last line is generate roman or generate textit etc. This runs the files where all characters are described by procedures, these procedures use the mentioned parameters as global variables. So, if you change a parameter in cmr10.mf then all characters are changed.

You can run mf '\mode=supre; mode_setup; input cmr10.mf' to generate cmr10.2400gf file with bitmaps of all characters in 2400 dpi resolution. You can apply gftopk cmr10.2400gf to create compressed format of the mf output in the file cmr10.2400pk. The high resolution is desired for the next autotracing process.

If you whish to generate all CM glyphs by single command, try

for i in cm*.mf ; do mf '\mode=supre; mode_setup; input' $i; done

Edit If you want to create png files (one character per one file), then you can use dvipng software. First, create your version of bitmap from cmr10.2400pk to cmr10.2400pk using gftopk and leave it in your actual directory. Then you can create a file (say cm.tex):

\font\f=cmr10 scaled 6000
\f
\nopagenumbers

a
\vfil\break 
b
\vfil\break % ... etc

\bye

Run tex cm to create cm.dvi. Each letter is at single page. Finally run dvipng --freetype0 cm. It creates a bunch of cm*.png files. Because the default resolution of dvipng is 400, we scale fonts 6times (see \font command) to get the resolution 2400 in our result. When the --freetype0 option is used, then dvipg uses bitmap fonts, it searches fonts in 6x400=2400 resolution and uses the file cmr10.2400pk prepared by you.

4
  • Thanks, that's helpful. I wonder if there's an easy "pk to png" kind of utility that outputs individual glyphs as png files? May 7 at 4:46
  • Also wondering if it's easy to locate the parameters that would influence the pen width / width variation (I guess it'll best described in the Metafont / CM book?) May 7 at 4:47
  • I added information about dvipng.
    – wipet
    May 7 at 7:31
  • Thanks – I found another thread on making CM bolder, so that should be similar May 8 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.