.\" "/. .\" mg macro package for troff "/. .\" created by John Ankarström "/. .\" "/. .\" Permission to use, copy, modify and/or "/. .\" distribute this software for any purpose "/. .\" with or without fee is hereby granted. "/. .\" "/. .\" For an index of the macros defined in "/. .\" this file, issue `grep -n [-]- g.tmac'. "/. .\" "/. .\" When editing the source of mg, keep the "/. .\" following rules in mind: "/. .\" "/. .\" * 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). "/. .\" * Place macros in alphabetical order. "/. .\" * Do not use .ev and .evc directly; use "/. .\" (e, @e and @c instead. "/. .\" "/. . .eo \" disable backslash escapes . .\" Internal macros ---------------------------- . .\" @a -- setup document .de @a . . \" initialize document . wh 0 @th . if \n(.t=\n(.p .wh -1i @tf . sp 1u \" trigger header . . \" configure environments . @e d \" date . @c 0 . nr sp 0.4v . ad c . @e h \" heading . @c 0 . nr sp 1.2v . ps +1p . ft B . @e l \" literal display . @c 0 . nr sp 0.3v . nf . in 18p . fam C . ps -1p . vs -1p . @e n \" name (of author) . @c 0 . nr sp 0.4v . ad c . @e p \" paragraph . @c 0 . nr sp 0.3v . nr ti 18p . ad b . @e q \" quotation . @c 0 . nr sp 0.3v . nr ti 1c . in 18p . ps -1p . vs -1p . @e s \" section heading . @c 0 . nr sp 1v . ft B . @e t \" title . @c 0 . ps +4p . vs +2p . ft B . ad c . @e . . \" configure special environments . (e @f \" footnote . @c 0 . ps -2p . vs -1p . (e @m \" margins (header, footer) . @c 0 . (e . . \" create formatted dates . 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 .de @c . evc \$1 . nr sp \n[@\$1_sp] . nr sq \n[@\$1_sq] . nr ti \n[@\$1_ti] .. . .\" @ds -- set default string value .de @ds . if '\*[\$1]'' .ds \$1 \$2 .. . .\" (e -- set environment .de (e . ev \$1 .. . .\" @e -- set extended environment .de @e . . \" initialize document if not initialized . if '\n(@a'0' \{\ . nr @a 1 . @a . \} . . \" save special environment variables . if !'\n[.ev]'0' \{\ . nr @\n[.ev]_sp \n(sp \" vertical space before any environment . nr @\n[.ev]_sq \n(sq \" vertical space before different environment . nr @\n[.ev]_ti \n(ti \" first line indentation . ev . \} . . \" keep track of previous and new environment . ds %penv \*[%env] . ds %env \$1 . . \" post-environment operations . if !'\$1'' \{\ . \" add small space after title . if '\*[%penv]'t' .if '\*[%env]'d' .sp 0.1v . . \" add space after title block . nr _ 0 . if !'\*[%env]'d' .nr _ 1 . if !'\*[%penv]'t' .if !'\*[%penv]'d' .nr _ 0 . if \n_ \{\ . sp 0.5i . ns . \} . . \" activate new environment . ev \$1 . nr sp \n[@\n[.ev]_sp] . nr sq \n[@\n[.ev]_sq] . nr ti \n[@\n[.ev]_ti] . sp \n(spu . if !'\*[%env]'\*[%penv]' .sp \n(squ . \} .. . .\" @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 .. . .\" @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 . @f ' bp .. . .\" @th -- header trap .de @th . (e @m . rt 0 . @h . (e \*[%env] . ns .. . .\" @tn -- footnote trap .de @tn . . nr @m 1 . \" print collected footnotes . (e @m ___________________ . br . sp 1p . (e @f . @n . br . . \" clear footnotes . ch @tn . nr @.t 0 . nr @dn 0 . rm @n . @tf f .. . . .\" Inline macros ------------------------------ . .\" b -- bold font .de b \&\$3\fB\$1\fP\$2 .. . .\" c -- constant-width font .de c . . \" save original interword spacing . nr _ss \n[.ss] . . \" copy family and (relative) point size from l environment . (e 0 . nr _s0 \n(.s . (e . (e l . ds _fl \n[.fam] . nr _sl \n(.s . (e . \&\$3\c . fam \*[_fl] . ps +(\n[_sl]-\n[_s0])u . ss 7 \&\$1\c . fam . ps . ss \n[_ss] \&\$2 .. . .\" i -- italic font .de i \&\$3\fI\$1\fP\$2 .. . .\" x -- bold italic font .de x \&\$3\f(BI\$1\fP\$2 .. . . .\" Hybrid macros ------------------------------ . .\" q -- quotation .de q . . \" inline . ie !'\$1'' \&\$3\(lq\$1\(rq\$2 . . \" block . el \{\ . br . @e q . ti \n(tiu . \} .. . . .\" Environment macros ------------------------- . . .\" d -- centered date .de d . br . @e d . if !'\$1'' \*(#\$1 .. . .\" h -- heading .de h . br . w h p . @e h . .. .\" l -- literal display .de l . br . w ll . @e l .. . .\" p -- paragraph .de p . br . @e p . if '\*[%penv]'p' .ti \n(tiu .. . .\" s -- subheading .de s . br . w s p . @e s .. . .\" t -- centered title .de t . br . @e t .. . . .\" Other macros ------------------------------- . .\" ( -- begin footnote .de ( . if !'\$1'' \&\$1\c . . \" increment and print number . nr @n \n(@n+1 \v'-.3m'\s'\En(.s*80/100'\n(@n\s0\v'.3m'\c . . \" switch environment and capture footnote . (e @f . ti 9p . boxa @n \v'-.3m'\s'\En(.s*80/100'\n(@n\s0\v'.3m'\h'2p'\c .. . .\" ) -- end footnote .de ) . br \!.br . boxa . (e \*[%env] . 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 . nr _tn \n[@.t]u-\n[@dn]u-12p . wh \n[_tn]u @tn .. . .\" w -- want space .de w . *w 0 \$@ .. .de *w . . \" parse specification -> _s : accumulated space . nr _s \$1 \" _e : environment name (e.g. eee -> e) . ds _e \$2 \" _n : number of lines specified (e.g. eee -> 3) . substring _e 0 0 . length _n \$2 . . \" add environment spacing . nr _s +\n[@\*(_e_sp] . nr _s +\n[@\*(_e_sq] . . \" add environment line height (for each line) . (e \*(_e . nr _v \n(.v . (e . nr _s +(\n(_n*\n(_v) . shift 2 . . \" recurse or request space if done . ie \n(.$>0 .*w \n(_s \$@ . el \{\ . nr _s \n(_s-\n(_v+1u \" do not request too much . if (\n(_su)>\n(.tu \{\ . br . bp . \} . \} .. . .ec \" re-enable backslash escapes