Typesetting arbitrary fractions

Last-Updated: 2021-08-30


Description of the issue

Some fractions are readily available in groff like ½, ¾ or ⅝. The following macro tries to extend this to all fractions.

The .frac macro

In this macro (2005-11/msg00029) written by Ted Harding, we are going to use the PostScript symbol named "fraction" whose groff name is "\(f/" to create the .frac macro with the goal to use it like so:

.frac numerator denominator

Here is the definition:

.de frac
.nr n0 \\n[.s]
.nr n1 \\n[n0]*6/10
.nr dn (\\n[n0]-\\n[n1])*8/10

You can test it:

.frac 1 2
.frac 999 1000
.frac 1 2
.frac 999 1000
.frac 1 2
.frac 999 1000

Note: Be wary of the registers used here and adapt them to fit your use case. The name used caused issues in the past (2013-09/msg00022).