0

Despite the many conveniences of mdoc, I find syntax of troff is still a bit too newline-rich or "spaghetti" compared to the other languages. Consider this example:

.Sh DESCRIPTION
The
.Nm
utility extracts C interface descriptions from a header file composed
using the SQLite documentation syntax (see
.Sx SYNTAX ) .
It then emits the corresponding set of
.Xr mdoc 7
manpages, one per interface description.
By default,
.Nm
reads from standard input and outputs files into the current directory.
Its arguments are as follows:

All these lines for a paragraph starting a list is quite odd to me. Is there a way to call macros inline?


What I have tried involves using the strings syntax to invoke the macros, as groff's manual states that strings, diversions, and macros are stored in a shared namespace. This does get me somewhere, but the .if conditions on at the start of the macros end up not processed and spit out raw.

.Sh DESCRIPTION
The \*[Nm] utility extracts C interface descriptions from a header file composed
using the SQLite documentation syntax (see \*[Sx SYNTAX]).
It then emits the corresponding set of \*[Xr mdoc 7] manpages, one per interface
description. By default, \*[Nm] reads from standard input and outputs files into
the current directory.
Its arguments are as follows:

I then tried to add another string definition to insert a newline. .ds n \! didn't quite work, and what I ended up having was a diversion:

.box n
\!
.box

.Sh DESCRIPTION
The \*n\*[Nm] utility extracts C interface descriptions... (see \*n\*[Sx SYNTAX]).
It then...

Now the .if spam is gone, but unfortunately I get a stray, actual newline in the output. Is there a more perfect way to call these macros? (We will think about mandoc compatibility later.)

Addendum:

  • With the "see SYNTAX" bit added, it appears that the newline is somehow inherent to the .Nm macro, as the .Sx one only produces a stray trailing space. Still, can we get rid of both?
  • If I remove the space after \*n\*[Nm], the extra newline is gone, but that looks... odd in the source. The SYNTAX one is improved by calling \n*[Sx Syntax ) .] like in the original, but it somehow produces a paragraph break too.

1 Answer 1

0

I would recommend writing a sed script to do this.

E.g., for eqn, I have a script, myeqn, to convert .EA into .EN\n.EQ:

#!/bin/sed -f

s/^\. *EA\(.*\)$/.EN\n.EQ \1/g

Then I run this:

myeqn < file.ms | groff -e -ms > main.ps

You can automate this with Makefiles if needed.

P.S. The newlines in Groff take getting used to, but you start to appreciate them after a while.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.