4

I'm trying to create a hand-writing animation effect for video presentations. The standard open tool trick for this is to draw SVG paths and animate the dash pattern from 0 to the end of the path.

This works well for standard paths, but if I convert naively a letter, or a mathematical symbol, to SVG paths, they come out as filled outlines, and drawing the path looks unnatural at best.

For standard text, there are fonts such as Hershey that have just the central stroke, which should work fine, but with math fonts I have not had any luck finding one that LaTeX followed by svg conversion would produce single strokes (and ideally in a natural calligraphic drawing order).

Of course this all is quite reminiscent of Metafont itself — pick up a pen, move there, etc. Makes me thin that the most elegant solution would be a Metafont/post-created font that only has single strokes (no filling) and has all the kerning etc. bells-and-whistles for use in TeX.

I've looked a bit into the Punk font, http://metapolator.com, and the like but having no experience with Metapost it's unclear to me how difficult the task would be. In essence, I'd like to make a dumbed-down copy of a standard Metafont, such that every glyph is a skeleton rather than a filled outline.

I'm not too worried about the poor aesthetics as typically the final SVG would be drawn with a fairly thick pen, again with the intention to mimic chalk/whiteboard pen handwriting — no fine serifs etc. there...

PS: One possible variation of this idea is to use the skeleton font as SVG mask to uncover a better-looking font behind it — the single strokes simply define the order of unveiling what's behind.

Edit: simplified sub-problem


Let's assume I have created all the glyphs I need, both text and maths, e.g. tracing over a comprehensive list such as that of Stix glyphs, imported it into FontForge and created a font out of it (I'm not sure how some aspects work, but sounds doable). How would I then enable it for LaTeX (/xe/lua, ...), such that the boxes containing those strokes are correctly positioned?


Addendum:

After even more googling I found a couple of relevant links:

How to create non-outlined SVG files from LaTeX formulae

https://github.com/KaTeX/katex-fonts/

It sounds like standard font formats don't like single-line descriptions, so the question become: how do I use a SVG font with a TeX-like box-positioning engine? Might be that Katex/Mathjax is the easier route here (with obvious limitations, but I'm interested in simple-enough output).

Edit (2021): after further searching and experimenting (dvisvgm, notably) I believe I've found a promising strategy with Mathjax, which can produce SVG output from given equations (the coverage is quite substantial). SVG paths are stored in Mathjax internal routines but in principle one can replace them with single-stroke alternatives. Now all that's left for me to do is draw them ;) (or, ideally, convince Metapost to do it for me?)

enter image description here

5
  • 1
    I just saw this lme.tf.fau.de/pattern-recognition-blog/… and it reminded me of your post, so I thought I'd pass this on to you in case it's useful. – Don Hosek Jun 12 '20 at 2:53
  • I don't know if you're still interested in this (as it's just returned to the main page). If so, the "fonts" I designed for loopspace.mathforge.org/CountingOnMyFingers/Calligraphy are written as single strokes rather than filled paths. – Andrew Stacey Jan 9 at 12:49
  • @AndrewStacey Thanks, I am still very much interested in the subject – in fact I've finally made progress with help from Mathjax devs. The bottleneck is drawing a comprehensive set of single-stroke glyphs so if you have such paths to share I would love to get in touch! – baptiste Jan 9 at 20:54
  • @baptiste I've just dug around in my old code. What I have is a LaTeX file containing TikZ code that will draw my gothic font on that webpage as single-stroke paths. I'd be happy to share that with you. The other fonts were created using iFontMaker which, I think, means that they will be filled shapes and so of less use to you. I think that converting a filled glyph to a stroked one will be quite hard to to automatically as there's no direction information in the fill and the shape might have multiple components of its boundary (such as the letter B). – Andrew Stacey Jan 10 at 14:50
  • @AndrewStacey Thanks, I'd be keen to reuse your nice gothic font and it shouldn't be too hard to get SVG paths from tikz code. For the other glyphs (and there's a lot of them!) I agree that once the shape is described by an outline it seems hopeless to "erode" it into a stroke-only shape (and even if such an operation could be applied (such as "trace path" in inkscape etc,) it would not have the natural calligraphic order to animate the drawing. That being said, I still wonder if the original Metafont description of the path doesn't have the right "trajectory-only" info in them. I'll check. – baptiste Jan 10 at 18:29
3
+500

Doing simple shapes with metafont is not especially difficult especially with the scheme that you've outlined. For learning MF, the essential tools would be the Metafontbook and optionally Knuth's Computer Modern Typefaces (Volume E of Computers & Typesetting).

But, I'd note that in some ways, MF is not much more high level than writing straight svg. It provides algebraic tools to make it easier to specify the locations of points programmatically, and I think that its specification for how to fit curves between points is more intuitive than anything else available, but getting from MF to SVG might be less than obvious. Perhaps your best option is to get a visual SVG editor and draw the glyphs you need by hand?

8
  • you hit on the nail – I'm hoping to leverage existing glyph descriptions and simplify them down to single strokes, rather than draw them one by one manually. In either case I'm not clear how the letter-spacing/kerning/position etc. of individual glyphs is encoded in a font and made accessible to TeX, which is a critical part for the success of this idea. The conversion to svg worries me less as there seem to be various tools to go from one vector format to another, though my understanding is that original metafont outputs rasters and here I'd want vector shapes. – baptiste May 26 '20 at 0:39
  • I have Knuth's book so could use the MF descriptions without too much trouble, and I suppose adapt them without too much effort once I grok the language, but I'm not sure what to do with the metafont-to-usable-vector-strokes aspect. – baptiste May 26 '20 at 0:42
  • As I'm thinking about how Metapost works (based on my vague memories of John Hobby's original presentation at Stanford in '89), I'm thinking it might not do what you want anyway. If I recall correctly, even though MF can draw shapes with a pen, I think it might still convert that to trace outlines. Also, if I recall correctly, the only pen-stroke characters in the whole CM character set are the calligraphic script letters. – Don Hosek Jun 1 '20 at 2:20
  • 1
    @baptiste -- The change you mention, from pen strokes to filled outlines, was the change from Metafont 80 to Metafont84. The corresponding fonts were the am series -- "Almost Modern". I'm not sure whether these can still be found anywhere, but certainly there's no currently workable binary for Metafont80. – barbara beeton Jun 1 '20 at 11:31
  • 1
    @barbarabeeton It looks like saildart.org has the MF80 source code for the am fonts, although not in an easily browsable format in my casual search and not like it could be easily used as you well know. But while a pure outline approach was taken for the CM fonts, MF84 did retain pen drawing and looking at calu.mf, my memory of it using pen drawing and a nib was correct (although I had forgotten that Neenie Billawalla (whatever happened to her?) had designed the calligraphic capitals). – Don Hosek Jun 1 '20 at 19:52

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.