> but i can't figure out how to inhibit the space for > the end quote inside the macro, so it ends up like > > 'wow wow the text is quoted ' > > is there an escape or a request that allows for this?
Many times have I wished for such a feature to exist, but there is no equivalent to "\c" that can be applied after the fact. However: groff has the ".chop" request, which removes the last character of a string/macro/diversion, and which we can try to use to remove the last whitespace newline from the end of the quoted text, before attaching the ending quote character. But since chop only works on strings/macros/diversions, and not on the running text, we first have to save the material in a macro or diversion before we can do the chopping. The attached code is an example of how this might be done. For illustration purposes, it also shows the nesting level alongside the quote characters. But why does it work at all? The first call of .q( begins at level 0 before "She said," but only scans forward until the first .q) (after "nesting"), at a nesting level unknown to the macro. (It just collects text, and can't count the number of .q( and .q) encountered.) The reason it works is that upon the first replay of the collected qq the second .q( is invoked, which causes it to redefine qq with the remainder of what had been read the first time, plus additional material until the next .q), and so on. Note that adding the ending quotes is delegated to a separate macro .qe, which only gets expanded when the text is finally processed for output and the correct nesting level is known, and not when the line ".qe" is just copied from macro to macro. We cannot add the ending quotes directly in .q), because the numeric register ql will not necessarily contain the correct quote level for the ending quote at the time .q) is called, and since it is also invoked at different nesting levels, we can't just add an appropriate number of backslashes.
.\" .\" ---------------------------------------------------------------- .po 3c .ll 21c-6c .sp 2c .ps 18 .vs 20 .\" ---------------------------------------------------------------- .ds ql \m[red]\s[\\n(.s*5/10]\v'-0.7m'[\\n(ql]\v'+0.7m'\s0\m[] .\" ---------------------------------------------------------------- .nr ql 0 .de q( .nr ql +1 .de qq q) .ie \\n(ql%2 \\$1\\*(ql\(lq\c .el \\$1\\*(ql\(oq\c .. .de q) .chop qq .am qq \c .qe \&\\$1 \\.. .qq .. .de qe .ie \\n(ql%2 \(rq\\*(ql\\$1\c .el \(cq\\*(ql\\$1\c .nr ql -1 .. .\" ---------------------------------------------------------------- .q( She said, .q( I think we're getting a little carried away with the .q( nesting .q) \^ .q) . But I told her it's all the rage among Lisp .q( programmers .q) . .q) .\" ----------------------------------------------------------------
nestedquotes.pdf
Description: Adobe PDF document