From 9365fec1a278974b4cabc9192f0797fc5d1d1682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 18 Jun 2021 10:40:06 +0200 Subject: g.tmac: Add c (code) macro, rework margins --- example.t | 51 +++++++++++++++++++++++------ g.tmac | 108 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 118 insertions(+), 41 deletions(-) diff --git a/example.t b/example.t index 3ca19bb..1ea01b1 100644 --- a/example.t +++ b/example.t @@ -1,26 +1,26 @@ .so g.tmac -.s +.p +.ta 3n +3n +3n +3n .t .x Mg , a simple macro package for troff .n John Ankarstr\[u00F6]m .d +.h +Introduction .p .i Mg is a simple macro package for troff with the following features: .p -1. -It is designed to be easy to understand and to customize +1. It is designed to be easy to understand and to customize by editing the source code. .p -2. -It makes use of the extended support for environments +2. It makes use of the extended support for environments offered by many modern troff implementations (but it can be made compatible with the original troff if need be). .p -3. -It is designed to be practically easy to use. +3. It is designed to be practically easy to use. Macros are consistently one letter long and written in lowercase. .p While @@ -33,7 +33,7 @@ Users of .i mg are encouraged to modify the source code according to their own needs. -.h +.s Internal design .p .i Mg @@ -52,4 +52,37 @@ simply sets the font size inside the environment named If the user wishes to modify the default font size, he or she can simply switch to the .i p -environment and set the font size as desired. +environment and set the font size as desired: +.c +.eo +.cc , +.\" set heading font +.h +.fam H +.ps +1p +,cc +.ec +.p +The environments are initialized +as soon as the first +.q block-level +macro is called. +At the initialization of each environment, +the default environment (0) is copied, +meaning that all environment-relevant settings +defined before the first macro call +are applied to all +.i mg +environments. +It is thus remarkably simple and intuitive to set, +for example, the default font of a document: +.c +.cc , +.fam N +.t +Document title +.p +First paragraph. +,cc +.p +\&... diff --git a/g.tmac b/g.tmac index 9f80429..d995c03 100644 --- a/g.tmac +++ b/g.tmac @@ -1,6 +1,6 @@ .eo .\" s -- setup document -.de s +.de _s . \" configure initial options . _nr mt 1i \" margin top . _nr mb 1i \" margin bottom @@ -11,23 +11,41 @@ . ns . \" configure environments . _e t \" title +. evc 0 . ps +4p . vs +2p . ft B . ad c . _e n \" name (of author) -. _nr n_mt 0.4v +. evc 0 +. nr sp 0.4v . ad c . _e d \" date -. _nr d_mt 0.4v +. evc 0 +. nr sp 0.4v . ad c -. _e p \" paragraph -. _nr p_mt 0.3v -. ad b . _e h \" heading -. _nr h_mt 0.6v +. evc 0 +. nr sp 0.6v . ps +1p . ft B +. _e s \" section heading +. evc 0 +. nr sp 0.6v +. ft B +. _e p \" paragraph +. evc 0 +. nr sp 0.3v +. nr ti 0.5c +. ad b +. _e c \" code listing +. evc 0 +. nr sp 0.3v +. nr in 0.5c +. nf +. in 0.5c +. fam C +. ps -1p . _e .. .\" _h -- page header @@ -46,11 +64,36 @@ .. .\" _e -- set environment .de _e +. if '\n(_s'0' \{\ +. nr _s 1 +. _s +. \} . br -. if !'\n[.ev]'0' .ev +. if !'\n[.ev]'0' \{\ +. nr \n[.ev]_sp \n(sp +. nr \n[.ev]_in \n(in +. nr \n[.ev]_ti \n(ti +. ev +. \} . ds penv \*[env] . ds env \$1 -. if !'\$1'' .ev \$1 +. if !'\$1'' \{\ +. ev \$1 +. nr sp \n[\n[.ev]_sp] +. nr in \n[\n[.ev]_in] +. nr ti \n[\n[.ev]_ti] +. sp \n(spu +. in \n(inu +. \} +. _mb +.. +.\" _mb -- margin bottom +.de _mb +. ie '\*[env]'n' .return +. el .if '\*[env]'d' .return +. ie '\*[penv]'t' .sp 1v +. el .ie '\*[penv]'n' .sp 1v +. el .if '\*[penv]'d' .sp 1v .. .\" i -- italic .de i @@ -60,44 +103,45 @@ .de x \$3\f(BI\$1\fP\$2 .. +.\" q -- quote +.de q +\$3\(lq\$1\(rq\$2 +.. .\" t -- title .de t . _e t .. .\" n -- name (of author) .de n -. br . _e n -. if '\*[penv]'t' .sp 0.2v -. sp \n[n_mt]u +. if '\*[penv]'t' .sp 0.2v .. .\" d -- date .de d -. br . _e d -. if '\*[penv]'t' .sp 0.2v -. sp \n[d_mt]u -. af mo 00 -. af dy 00 -. ie '\$1'' \n[year]-\n(mo-\n(dy -. el \$1 -. af mo 1 -. af dy 1 +. if '\*[penv]'t' .sp 0.2v +. af mo 00 +. af dy 00 +. ie '\$1'' \n[year]-\n(mo-\n(dy +. el \$1 +. af mo 1 +. af dy 1 +.. +.\" h -- heading +.de h +. _e h +.. +.\" s -- section heading +.de s +. _e s .. .\" p -- paragraph .de p -. br . _e p -. ie '\*[penv]'t' .sp 1v -. el .ie '\*[penv]'n' .sp 1v -. el .ie '\*[penv]'d' .sp 1v -. el .sp \n[p_mt]u -. if '\*[penv]'p' \h'0.5c' +. if '\*[penv]'p' .ti \n(tiu .. -.\" h -- heading -.de h -. br -. _e h -. sp \n[h_mt]u +.\" c -- code listing +.de c +. _e c .. .ec -- cgit v1.2.3