Gnu nroff – output a line with dot at beginning of line

i tried to write a self-replicating program (“quine”) in raw (no macros) GNU nroff. Admittedly, this is pointless and eccentric, but it doesn’t seem to have been done before. I have failed to do so.

I’m pretty sure that whoever succeeds in writing a no-macro nroff input language quine will need to define strings, or macros or “boxes”. To do that you need to write requests like:

.as s "just assigned this to string s
.de xxx
.nop "*s"

That is, every request in nroff input has a ‘.’ at the start of the line.

Since quines just output their source code (without cheating), the output probably has to have ‘.’ as the first character of several output lines.

How on earth do you get GNU nroff to output a ‘.’ character at the start of a line? No amount of indirection or escaping can do it, as far as I can tell. Is there some hidden request that outputs a ‘.’ at the start of a line?

I’m using recently synced Arch Linux, which has Groff 1.22.3 installed.

Asked By: user732


From mdoc(7)

The special meaning of a punctuation character may be escaped with the string ‘&’



However this might be tricky in combination with subsequent lines as things like

&.as s "nron, nroff--very good, again!

Run together (and produces a whole bunch of blank lines)

$ nroff blah | head -2
.  .as s "nron, nroff‐‐very good, again!

Though you can fix that by adding a blank line, or possibly using other macros


&.as s "nron, nroff--very good, again!

Though I don’t know how that will affect the needs of quine…

Answered By: thrig

You can set up a translation with .tr which takes pairs of characters to translate from-to. Eg to translate # to .:

nroff <<!
.tr #.

Answered By: meuh
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.