diff options
authorJohn Ankarström <john@ankarstrom.se>2021-06-23 12:21:41 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-23 12:22:37 +0200
commitdf9030831e294af0030d3c9df092a1ea910aa6df (patch)
parent6711a42d6175984a029e7af7a4886ed44c998e4c (diff)
toc: Use .so instead of .rd
-rw-r--r--toc/README.pdfbin24502 -> 25615 bytes
5 files changed, 54 insertions, 32 deletions
diff --git a/toc/Makefile b/toc/Makefile
index 3211efd..6b6468f 100644
--- a/toc/Makefile
+++ b/toc/Makefile
@@ -1,5 +1,5 @@
+README.pdf: README.t toc.tmac toc gtoc
./gtoc -Tps README.t | ps2pdf - > README.pdf
-example.pdf: example.t
+example.pdf: example.t toc.tmac toc gtoc
./gtoc -Tps example.t | ps2pdf - > example.pdf
diff --git a/toc/README.pdf b/toc/README.pdf
index e4267e5..94b970f 100644
--- a/toc/README.pdf
+++ b/toc/README.pdf
Binary files differ
diff --git a/toc/README.t b/toc/README.t
index 10e0ee5..c326700 100644
--- a/toc/README.t
+++ b/toc/README.t
@@ -25,14 +25,15 @@ The
.i toc
script is a wrapper around troff,
passing the document through the typesetter three times.
-In every pass, it sets the values of two registers named
+In every pass, it sets the values of a registers and a string named
.i te
-.i to .
+.i tf ,
.i toc.tmac
-package defines two macros, also named
+package defines two macros, named
.c te
.c to .
@@ -42,14 +43,18 @@ register is non-zero, the
.c te
macro hands its argument to the
.c tm
-request, which prints it on standard error.
+request, which prints it on standard error,
+prefixed by
+.q (toc) .
If the
-.i to
-register is non-zero, the
+.i tf
+string is non-empty, the
.c to
macro invokes the
-.c rd
-request, reading and inserting lines from standard input
+.c so
+request, reading and inserting lines from the file
+specified by
+.i tf
into the troff document.
@@ -60,45 +65,57 @@ In the first pass, the
script sets
.i te
= 1 and
-.i to
-= 0.
+.i tf
+= empty.
This enables the
.c te
macro, printing its arguments on standard error.
-The lines printed on standard error
-are piped to the second invocation of troff.
+The lines prefixed with
+.q (toc) ,
+printed on standard error,
+are written to the file
+.i $g
+with the
+.q (toc)
+prefix removed.
In the second pass,
.i toc
.i te
= 1 and
-.i to
-= 1.
+.i tf
+.i $g .
This enables the
.c to
-macro as well, inserting the lines given on standard error
+macro as well, inserting the contents of
+.i $g
into the troff source.
.c te
macro is still activated and accordingly
prints its arguments on standard error yet another time.
-Like before, the output is piped to the third invocation of troff.
+The output is processed like earlier and written to the file
+.i $h .
In the third and final pass,
.i toc
.i te
= 0 and
-.i to
-= 1.
+.i tf
+.i $h .
This disables
.c te ,
which means that nothing is printed on standard error,
.c to
is still enabled,
-once again inserting the input on standard error into the document.
+inserting the contents of
+.i $h
+into the document.
Three is the number of passes necessary \(en and sufficient \(en
for generating forward references,
@@ -126,21 +143,26 @@ The
macro prints its arguments on standard error verbatim.
For example, the request
-\&.te .nr &a \\n%
+\&.te .nr &ref \\n%
will print
-\&.nr &a \\n%
+\&(toc).nr &ref \\n%
on standard error.
-Let us assume the page number is 3.
+.q (toc)
+prefix is removed before the line is written to the temporary file.
.c to
is invoked, it will literally insert
-\&.nr &a 3
+\&.nr &ref 3
-into the troff source.
+into the troff source, assuming
+.c te
+was invoked on the third page.
As such,
.i toc
@@ -162,14 +184,14 @@ are passed to troff
environment variable).
-Pre- and post-processors can be added by setting
+Pre-processors can be added by setting
to a custom shell script:
.ne 3
$ cat xroff
-\&... | groff "$@" | ...
+\&... | groff "$@"
$ TROFF=./xroff toc document.t
diff --git a/toc/toc b/toc/toc
index 9544934..d3de1a5 100755
--- a/toc/toc
+++ b/toc/toc
@@ -24,9 +24,9 @@ fi
tmp g
tmp h
-$TROFF -rte=1 -rto=0 "$@" 2>&1 1>/dev/null | $SED >$g
-$TROFF -rte=1 -rto=1 "$@" <$g 2>&1 1>/dev/null | $SED >$h
-$TROFF -rte=0 -rto=1 "$@" <$h
+$TROFF -rte=1 -dtf= "$@" 2>&1 1>/dev/null | $SED >$g
+$TROFF -rte=1 -dtf=$g "$@" 2>&1 1>/dev/null | $SED >$h
+$TROFF -rte=0 -dtf=$h "$@"
diff --git a/toc/toc.tmac b/toc/toc.tmac
index 8431e06..b97aaf9 100644
--- a/toc/toc.tmac
+++ b/toc/toc.tmac
@@ -10,7 +10,7 @@
.\" to -- evaluate collected lines
.de to
-. if \n(to=1 .rd
+. if !'\*(tf'' .so \*(tf
.\" te -- collect line