aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example.pdfbin82588 -> 84913 bytes
-rw-r--r--example.t155
-rw-r--r--g.tmac125
3 files changed, 170 insertions, 110 deletions
diff --git a/example.pdf b/example.pdf
index b69f26b..c0146d3 100644
--- a/example.pdf
+++ b/example.pdf
Binary files differ
diff --git a/example.t b/example.t
index 2fc9bd1..87f6bd0 100644
--- a/example.t
+++ b/example.t
@@ -1,5 +1,16 @@
.so g.tmac
.
+.de @h
+. sp |36p
+. tl ''-%-''
+. sp |1i
+..
+.
+.de @f
+. sp |\\n(.pu-48p
+. tl ''\\*(%e''
+..
+.
. \" configure environments
.@e p
. nr sq \n(sp
@@ -160,42 +171,6 @@ and do not support these registers.
.
.
.h
-Global settings
-.p
-Thanks to the reliance on environments,
-there are only four global string values
-controlling the state of
-.i mg :
-.n 1
-.c mt ,
-the margin at the top of the page
-.n
-.c mb ,
-the margin at the bottom of the page
-.n
-.c tt ,
-the text in the top margin
-.n
-.c tb ,
-the text in the bottom margin
-.p
-The
-.c tt
-and
-.c tb
-registers are passed to troff's
-.c tl
-request and should be formatted accordingly.
-By default,
-.c tt
-is empty and
-.c tb
-is set to
-.c ''%'' ,
-displaying the page number in the center.
-.
-.
-.h
External macros
.p
.i Mg
@@ -298,6 +273,14 @@ international date, like
.c e :
English date, like
.q "21 June 2021"
+.p
+The date formats are defined in strings prefixed with a percent sign
+.c % ): (
+.c %i
+and
+.c %e
+are provided by default,
+but more may be added by the user.
.
.s
Other macros
@@ -337,6 +320,7 @@ For example, the following code
\&.q
This is a quotation\\c
\&.(
+.ne 1
This is a footnote.
\&.) .
.p
@@ -347,12 +331,14 @@ 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.
-In such cases, the reference will simply appear on the page
-following the footnote.
-When this happens, the user must account for it manually.
+If
+.c (
+and
+.c )
+are called at such a position that the collected footnotes
+cannot fit on the current page,
+.i mg
+will print the footnotes on the next page instead.
.p
The
.c q
@@ -398,14 +384,59 @@ Internal macros
.i Mg 's
internal macros are generally not meant to be used outside of
.i g.tmac .
+Documented in this section are the exceptions to this rule.
+For examples of how these macros are used in practice,
+see the FAQ section below.
+.
+.s
+Margin macros
+.p
+The
+.c @h ,
+.c @f ,
+.c @th
+and
+.c @tf
+macros control the page header and footer.
+.p
+At document initialization,
+.i mg
+automatically creates traps for
+.c @th
+and
+.c @tf .
+When sprung,
+.c @th
+and
+.c @tf
+call
+.c @h
+and
+.c @t ,
+which control the text and spacing of the header and footer.
+.p
+.i Mg
+will avoid creating a trap for
+.c @tf
+if any trap has already been set before document initialization.
+This means that users can override the position of the
+.c @tf
+trap by setting it themselves.
+Likewise, users can redefine
+.c @h
+and
+.c @f
+to change the content of the header and footer.
+.
+.s
+Environment macros
+.p
The environment-related macros
.c (e ,
.c @e
and
.c @c
-are, however, excepted from this rule,
-as it may be desirable to define custom environments
-for advanced documents.
+may be used in advanced documents to define custom environments.
.p
At the present,
.c (e
@@ -428,14 +459,6 @@ special environment variables
(see
.i Environments
above).
-.p
-For examples of how
-.c (e ,
-.c @e
-and
-.c @c
-are used in practice,
-see the FAQ section below.
.
.
.h
@@ -509,6 +532,32 @@ How do I customize the default appearance of footnotes?
\&.ps +1p
.
.s
+How do I redefine the page header?
+.l
+\&.de @h
+\&. \\" set position of header text
+\&. sp |36p
+\&. \\" set header text
+\&. tl 'left'center'right'
+\&. \\" set position of page text
+\&. sp |1i
+\&..
+.
+.s
+How do I redefine the page footer?
+.l
+\&.\\" set position of footer trap
+\&.\\" (must be done before any macros have been called)
+\&.wh -1i @tf
+\&.
+\&.de @f
+\&. \\" set position of footer text
+\&. \\" (must be below the footer trap)
+\&. sp |\\\\n(.pu-48p
+\&. tl 'left'center'right'
+\&..
+.
+.s
How do I prevent a section from being broken up by a page break?
.p
Some macro packages have a concept of
diff --git a/g.tmac b/g.tmac
index 8475988..48ecc6e 100644
--- a/g.tmac
+++ b/g.tmac
@@ -12,16 +12,16 @@
.\" When editing the source of mg, keep the "/.
.\" following rules in mind: "/.
.\" "/.
-.\" * Prefix temporary registers with _. "/.
-.\" * Prefix temporary strings with _. "/.
-.\" * Prefix internal environments with @. "/.
-.\" * Prefix internal registers with @. "/.
+.\" * Prefix temporary strings and registers "/.
+.\" with _. "/.
+.\" * Prefix internal registers and environ- "/.
+.\" ments with @. "/.
.\" * Prefix internal macros with @ (normal "/.
-.\" macros), * (variants of the same macro) "/.
-.\" or % (strings). "/.
+.\" macros), * (variants of the same "/.
+.\" macro) or % (strings). "/.
.\" * Place macros in alphabetical order. "/.
-.\" * Do not use .ev and .evc outside of "/.
-.\" wrapper macros like (e, @e and @c. "/.
+.\" * Do not use .ev and .evc directly; use "/.
+.\" (e, @e and @c instead. "/.
.\" "/.
.
.eo \" disable backslash escapes
@@ -31,15 +31,9 @@
.\" @a -- setup document
.de @a
.
-. \" configure initial options
-. @nr mt 1i \" top margin
-. @nr mb 1i \" bottom margin
-. @ds tt '''' \" text in top margin
-. @ds tb ''%'' \" text in bottom margin
-.
. \" initialize document
. wh 0 @th
-. wh -\n(mbu @tf
+. if \n(.t=\n(.p .wh -1i @tf
. sp 1u \" trigger header
.
. \" configure environments
@@ -96,6 +90,30 @@
. (e @m \" margins (header, footer)
. @c 0
. (e
+.
+. \" set date formats
+. af mo 00
+. af dy 00
+. ds %i \n[year]-\n(mo-\n(dy
+. af mo 1
+. af dy 1
+. ds %e \n(dy
+. ie \n(mo=1 .ds %e \*(%e January
+. el .ie \n(mo=2 .ds %e \*(%e February
+. el .ie \n(mo=3 .ds %e \*(%e March
+. el .ie \n(mo=4 .ds %e \*(%e April
+. el .ie \n(mo=5 .ds %e \*(%e May
+. el .ie \n(mo=6 .ds %e \*(%e June
+. el .ie \n(mo=7 .ds %e \*(%e July
+. el .ie \n(mo=8 .ds %e \*(%e August
+. el .ie \n(mo=9 .ds %e \*(%e September
+. el .ie \n(mo=10 .ds %e \*(%e October
+. el .ie \n(mo=11 .ds %e \*(%e November
+. el .ds %e \*(%e December
+. ds %e \*(%e \n[year]
+..
+.
+.
..
.
. \" @c -- copy environment
@@ -161,6 +179,21 @@
. \}
..
.
+.\" @f -- footer
+.de @f
+. sp |\n(.pu-48p
+. tl ''%''
+..
+.
+.\" @h -- header
+.de @h
+. sp |36p
+. tl ''''
+. sp |1i
+..
+.
+..
+.
.\" @nr -- set default numeric value
.de @nr
. if \n[\$1]=0 .nr \$1 \$2
@@ -169,11 +202,15 @@
.\" @tf -- footer trap
.de @tf
.
+. \" skip automatic trigger if manual mode active, unless forced
+. if \n(@m>0 .if !'\$1'f' \{\
+. nr @m -1
+. return
+. \}
+.
. \" print footer
. (e @m
-. rt \n(.pu-\n(mbu \" return to correct position if pushed down
-. sp \n(mbu-2v-24p
-. tl \*(tb
+. @f
' bp
..
.
@@ -181,10 +218,7 @@
.de @th
. (e @m
. rt 0
-. sp 24p
-. tl \*(tt
-. rt 0
-. sp \n(mtu
+. @h
. (e \*[%env]
. ns
..
@@ -192,9 +226,7 @@
.\" @tn -- footnote trap
.de @tn
.
-. \" override footer
-. ch @tf
-.
+. nr @m 1
. \" print collected footnotes
. (e @m
___________________
@@ -206,12 +238,10 @@ ___________________
.
. \" clear footnotes
. ch @tn
+. nr @.t 0
. nr @dn 0
. rm @n
-.
-. \" trigger and restore footer
-. @tf
-. wh -\n(mbu @tf
+. @tf f
..
.
.
@@ -283,34 +313,9 @@ ___________________
.de d
. br
. @e d
-.
-. \" 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]
-. \}
+. if !'\$1'' \*(%\$1
..
+.
.\" h -- heading
.de h
. br
@@ -321,6 +326,7 @@ ___________________
.\" l -- literal display
.de l
. br
+. w ll
. @e l
..
.
@@ -371,10 +377,15 @@ ___________________
. ie !'\$1'' \&\$1
. el \&
.
+. \" get position of footer (or next trap)
+. if \n[@.t]=0 .nr @.t \n(nl+\n(.t
+.
+.
. \" print footnote at bottom of page
. ch @tn
. nr @dn +\n(dnu
-. if !'\n(dn'0' .wh -\n[@dn]u-\n(mbu-12p @tn
+. nr _tn \n[@.t]u-\n[@dn]u-12p
+. wh \n[_tn]u @tn
..
.
.\" w -- want space