groff_trace
Section: Environments, Tables, and Troff Macros (7)
Updated: 2 July 2023
Index
Return to Main Contents
Name
groff_trace - macros for debugging GNU
roff
documents
.nr d-fallback 1
.nr d-fallback 1
Synopsis
[
option~...]
[
file~...]
Description
trace
is a macro package for the
document formatting system,
designed as an aid for debugging documents written in its language.
It issues a message to the standard error stream upon entry to and exit
from each macro call.
This can ease the process of isolating errors in macro definitions.
Activate the package by specifying the comman-line option
[lq]
-m~trace[rq]
to the formatter program
(often
You can achieve finer control by including the macro file within the
document;
invoke the
mso
request,
as in
[lq]
.mso~trace.tmac[rq].
Only macros that are defined after this invocation are traced.
If the
trace-full
register is set to a true value,
as with the comman-line option
[lq]
-r~trace-full=1[rq],
register and string assignments,
along with some other requests,
are traced also.
If another macro package should be traced as well,
specify it after
[lq]
-m~trace[rq]
on the command line.
The macro file
trace.tmac
is unusual because it does not contain any macros to be called by a
user.
Instead,
groff's
macro definition and alteration facilities are wrapped such that they
display diagnostic messages.
Limitations
Because
trace.tmac
wraps the
de
request
(and its cousins),
macro arguments are expanded one level more.
This causes problems if an argument uses four or more backslashes to
delay interpretation of an escape sequence.
For example,
the macro call
-
.foo [rs][rs][rs][rs]n[bar]
normally passes [lq][rs][rs]n[bar][rq] to macro [lq]foo[rq],
but with
de
redefined,
it passes [lq][rs]n[bar][rq] instead.
The solution to this problem is to use
groff's
[rs]E
escape sequence,
an escape character that is not interpreted in copy mode.
-
.foo [rs]En[bar]
Examples
We will illustrate
trace.tmac
using the shell's [lq]here document[rq] feature to supply
groff
with a document
on the standard input stream.
Since we are interested only in diagnostic messages appearing on the
standard error stream,
we discard the formatted output by redirecting the standard output
stream to
/dev/null.
Observing nested macro calls
Macro calls can be nested,
even with themselves.
Tracing recurses along with them;
this feature can help to detangle complex call stacks.
-
$~cat <<EOF | groff -m trace > /dev/null
.de countdown
. nop [rs][rs]$1
. nr count ([rs][rs]$1- 1)
. if [rs][rs]n[count] .countdown [rs][rs]n[count]
..
.countdown 3
blastoff
EOF
~*** .de countdown
~*** de trace enter: .countdown "3"
~~*** de trace enter: .countdown "2"
~~~*** de trace enter: .countdown "1"
~~~*** trace exit: .countdown "1"
~~*** trace exit: .countdown "2"
~*** trace exit: .countdown "3"
Tracing with the mso request
Now let us activate tracing within the document,
not with a comman-line option.
We might do this when using a macro package like
ms
or
mom,
where we may not want to be distracted by traces of macros we didn't
write.
-
$~cat <<EOF | groff-ms > /dev/null
.LP
This is my introductory paragraph.
.mso trace.tmac
.de Mymac
..
.Mymac
.PP
Let us review the existing literature.
EOF
~*** .de Mymac
~*** de trace enter: .Mymac
~*** trace exit: .Mymac
As tracing was not yet active when the macros [lq]LP[rq] and
[lq]PP[rq] were defined
(by
s.tmac),
their calls were not traced;
contrast with the macro [lq]Mymac[rq].
Files
- /usr/:share/:groff/:1.23.0/:tmac/:trace:.tmac
-
implements the package.
Authors
trace.tmac
was written by James Clark.
This document was written by
Bernd Warken
and
G. Branden Robinson
See also
Groff: The GNU Implementation of troff,
by Trent A. Fisher and Werner Lemberg,
is the primary
groff
manual.
You can browse it interactively with [lq]info groff[rq].
-
-
gives an overview of the
groff
document formatting system.
-
-
supplies details of the
-m
comman-line option.
-
-
offers a survey of
groff
macro packages.
-
-
is a reference manual for the
groff
language.
Index
- Name
-
- Synopsis
-
- Description
-
- Limitations
-
- Examples
-
- Observing nested macro calls
-
- Tracing with the mso request
-
- Files
-
- Authors
-
- See also
-