.\"                                          "/.
.\"        mu 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 [-]- u.tmac'.  "/.
.\"                                          "/.
.\" When editing the source of mu, 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.                 "/.
.\"                                          "/.
.
.do xflag 3 \" enable modern extensions
.eo \" disable backslash escapes
.
.\" Internal macros ----------------------------
.
.\" @a -- setup document
.de @a
. nr @a 1
.
. \" set header/footer traps
. wh 0 @th
. em @tf
. if \n(nl<=0 .@th
. nr _ \n(.p-\n(nl
. if \n(.t=\n_ .wh -1i @tf
.
. \" 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
.  ft CR
.  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 18p
.  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]
..
.
.\" (e -- set environment
.de (e
. ev \$1
..
.
.\" @e -- set extended environment
.de @e
.
. \" initialize document if not initialized
. if '\n(@a'0' .@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
..
.
.\" @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
. br
. (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
.
. \" escape control characters
. char . \&.
. char ' \&'
.
. @n
. br
.
. \" restore control characters
. char . .
. char ' '
.
. \" clear footnotes
. ch @tn
. nr @.t 0
. nr @dn 0
. rm @n
. @tf f
..
.
.
.\" Inline macros ------------------------------
.
.\" " -- inline quotation
.de "
\&\$3\(lq\$1\(rq\$2
..
.
.\" 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(.f
. nr _sl \n(.s
. (e
.
\&\$3\c
. ft \*[_fl]
. ss 7
. ie d nrf .nrf _s (\n(.s*(\n[_sl]/(\n[_s0])))
. el .nr _s \n(.s+(\n[_sl]-\n[_s0])
. ps \n(_sp
\&\$1\c
. ft
. ss \n[_ss]
. ps
\&\$2
..
.
.\" i -- italic font
.de i
\&\$3\fI\$1\fP\$2
..
.
.\" x -- bold italic font
.de x
\&\$3\f(BI\$1\fP\$2
..
.
.
.\" 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
..
.
.\" q -- quotation
.de q
. br
. @e q
. 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
. boxa @n
\h'9p'\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