1

How can I insert today's date in groff?

I know I can type today's date directly, but I would like the date to dynamically be produced, so that a document could be recompiled with a new date without any change to the groff source.

Specifically, I would like the date to appear in "<month name>, <day of month> <year>" format, for example, March 7, 2021.

I am using the mom macros. I don't know if inserting today's date is something that is macro-dependent or macro-independent.

2 Answers 2

4

Base troff has number registers with the current date, month, and year (offset from 1900). So you can get a very basic date with:

.nr y 1900+\n(yr
Date is: \n(mo  \n(dy, \ny

This gives you 3 7, 2021. However, you can do better by copying the code from the ms macros:

.ds MONTH1 January
.ds MONTH2 February
.ds MONTH3 March
.ds MONTH4 April
.ds MONTH5 May
.ds MONTH6 June
.ds MONTH7 July
.ds MONTH8 August
.ds MONTH9 September
.ds MONTH10 October
.ds MONTH11 November
.ds MONTH12 December
.ds MO \E*[MONTH\n[mo]]
.ds DY \*[MO] \n[dy], \n[year]

Date is: \*[DY]

You will get March 7, 2021.

0

In mom user guide is description of DATE macro: http://tools.ietf.org/doc/groff/html/mom/letters.html#date

Does this work?

1
  • That macro allows you to enter the date portion of a letter. It will not produce the date for you, you need to manually provide the date as input to the macro. Commented Mar 7, 2021 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .