2

I'm learning troff for typesetting documents. I found the me macros nice and beautiful out of the box and want to avoid mom. me defaults everything to serif fonts which is ugly for larger text like the cover page and headings. How can I change the font to something sans serif for those passages?

I tried .ft H and other .ft commands, non of those seemed to do anything (they worked with ms/mom).

1

The me macros in groff use the following font positions for various types of text:

  1. Normal text font
  2. (unused?)
  3. Title font and section font

The macros will switch to use the fonts loaded at these positions when setting the text for e.g. a section title, so the .ft macro would be ineffective. You would still be able to use e.g.

.sh 1 "\f(HBSection title"

to switch to a bold sans-serif font for the section title, but the numbering of the section would still be using a serif font.

The me macro file sets up a number of parameters that they use for things like fonts and point sizes etc., so much of the interesting stuff is quite easy to modify by just changing a few number registers and things like that, but this is unfortunately not covered by the groff_me(7) manual. It's also well hidden in the e.tmac macro file (due to the file having had comments stripped out of it). I had to read the original (un-stripped) e.tmac-u file in the groff source distribution to figure this out:

.\"             *** PARAMETRIC INITIALIZATIONS ***
.
.
.rr x
.nr $v \n(.v00+\n(.sp-1/\n(.sp  \" vs as % of ps for .sz request
.nr $V \n($v                    \" same for displays & footnotes
.nr hm 4v                       \" header margin
.nr tm 7v                       \" top margin
.nr bm 6v                       \" bottom margin
.nr fm 3v                       \" footer margin
.nr tf 3                        \" title font: (real) Times Bold
.nr tp 10                       \" title point size
.hy 6
.nr bi 4m                       \" indent for blocks
.nr pi 5n                       \" indent for paragraphs
.nr pf 1                        \" normal text font
.nr pp 10                       \" normal text point size
.nr qi 4n                       \" indent for quotes
.nr qp -1                       \" down one point
.nr ii 5n                       \" indent for .ip's and .np's
.nr $m 1                        \" max number of columns
.nr $s 4n                       \" column separation
.nr sf 3                        \" section font -- Times Bold
.nr sp 10                       \" section title pointsize
.nr ss 12p                      \" section prespacing
.nr si 0                        \" section indent

To change the section and title font to a bold sans-serif font, use

.fp 3 HB

to load the HB font into position 3. This would then be picked up by the .sh macro and others.

Example:

.fp 3 HB
.bp
.sh 1 "Heading 1"
.lp
Text text.
.sh 2 "Heading 2"
.lp
Text text.

This would generate

Rendered PDF output from groff

|improve this answer|||||
  • looks promising. I will try once I'm done with my work. Thank you! – sirjofri Mar 6 '19 at 10:51
  • 1
    It works great. Now I also have a much better understanding about fonts in groff. Thank you – sirjofri Mar 6 '19 at 15:48

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.