From 9dcab3a30d499f6fed5db56e34636610366cff37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 21 Jun 2021 21:55:44 +0200 Subject: Implement selectable date formats for d --- example.t | 81 ++++++++++++++++++++++++++++++++++++++++----------------------- g.tmac | 37 ++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 37 deletions(-) diff --git a/example.t b/example.t index 78a3879..2fc9bd1 100644 --- a/example.t +++ b/example.t @@ -30,14 +30,13 @@ .. .ec . -. . \" start document .t .x Mg , a simple macro package for troff -.d \& -John Ankarstr\(:om .d +John Ankarstr\(:om +.d e . . .h @@ -252,8 +251,7 @@ There is a large group of macros that provide block-level formatting: .n 1 .c d , -centered date (or given string, or nothing, if given -.c \\\\& ) +centered date or text .n .c h , heading @@ -279,15 +277,27 @@ to create a centered header: .l \&.t Document title -\&.d \\& +\&.d First author -\&.d \\& +\&.br Second author -\&.d \\" current date +\&.d i \\" current date formatted as YYYY-MM-DD .p -Here, you can see that the +In the example above, you can see that the +.c d +macro may be used for other things than just dates. +This works because .c d -macro may be used for other things than dates. +displays the date only if given +an argument describing the desired date format: +.n 1 a ) +.c i : +international date, like +.q 2021-06-21 +.n +.c e : +English date, like +.q "21 June 2021" . .s Other macros @@ -295,40 +305,48 @@ Other macros Finally, there are a few macros that belong to neither category: .n 1 +.ne 2 .c ( , begin footnote .n .c ) , end footnote .n +.ne 2 .c q , quotation .n .c w , want space .p -The footnote macros +The macros .c ( and .c ) -are used like this\c -.( -Note that +create footnotes, +placing a numerical reference at the place of their invocation. +Both .c ( and .c ) take an optional argument, -which is output immediately before or after -the footnote number. -.) : +which is output either immediately before or immediately after +the inline reference. +For example, the following code .l -\&.p -A line of text\\c +\&.q +This is a quotation\\c \&.( -.ne 2 -A footnote. +This is a footnote. \&.) . .p +creates the following reference: +.q +This is a quotation\c +.( +This is a footnote. +.) . +.p .i Mg does not account for cases where a footnote, because of its height, pushes the place where it is referenced to the next page. @@ -352,22 +370,23 @@ This is an inline .p The .c w -macro is a wrapper around troff's -.c ne , +macro is an alternative to troff's +.c ne +request, which ensures that a given amount of space is available on the page -\(em otherwise, a line break is issued \(em +\(en otherwise, a line break is issued \(en but unlike .c ne , which takes an exact amount of space as its argument, .c w takes a declarative specification -describing the amount of space desired +describing the amount of desired space in terms of .i mg environments. For example: .l -\\" want space for... +\&.\\" want space for... \&.w s p \\" a subheading of one line + a paragraph of one line \&.w s pp \\" a subheading of one line + a paragraph of two lines \&.w ss p \\" a subheading of two lines + a paragraph of one line @@ -379,12 +398,12 @@ Internal macros .i Mg 's internal macros are generally not meant to be used outside of .i g.tmac . -The group of macros controlling the environment \(en +The environment-related macros .c (e , .c @e and .c @c -\(en are excepted from this rule, +are, however, excepted from this rule, as it may be desirable to define custom environments for advanced documents. .p @@ -395,6 +414,7 @@ is nothing more than a wrapper around troff's built-in but it may eventually be redefined in order to offer compatibility with implementations of troff without support for named environments. +.p .c @e and .c @c @@ -402,7 +422,10 @@ are equivalent to troff's .c ev and .c evc , -but keep track of a few extra variables (see +but perform some extra work to keep track of +.i mg 's +special environment variables +(see .i Environments above). .p diff --git a/g.tmac b/g.tmac index 917a0ba..8475988 100644 --- a/g.tmac +++ b/g.tmac @@ -279,16 +279,37 @@ ___________________ .\" Environment macros ------------------------- . . -.\" d -- date +.\" d -- centered date .de d . br . @e d -. af mo 00 -. af dy 00 -. ie '\$1'' \n[year]-\n(mo-\n(dy -. el .if !'\$1'\&' \$1 -. af mo 1 -. af dy 1 +. +. \" international format +. ie '\$1'i' \{\ +. af mo 00 +. af dy 00 +\n[year]-\n(mo-\n(dy +. af mo 1 +. af dy 1 +. \} +. +. \" english format +. el .if '\$1'e' \{\ +\n(dy +. ie \n(mo=1 January +. el .ie \n(mo=2 February +. el .ie \n(mo=3 March +. el .ie \n(mo=4 April +. el .ie \n(mo=5 May +. el .ie \n(mo=6 June +. el .ie \n(mo=7 July +. el .ie \n(mo=8 August +. el .ie \n(mo=9 September +. el .ie \n(mo=10 October +. el .ie \n(mo=11 November +. el December +\n[year] +. \} .. .\" h -- heading .de h @@ -317,7 +338,7 @@ ___________________ . @e s .. . -.\" t -- title +.\" t -- centered title .de t . br . @e t -- cgit v1.2.3