[comp.text] troff string register interpolation if strange char

leff@.seas.smu.edu (leff) (06/02/90)

A strange control character is being inserted on character interpolations
before a closing \} of an if statement.

In the example below, there are two operations involving interpolation of a
string register before a \} of an if.  In the first operation, the output of 
the "tm" inside of the macro, M1, includes both an X and a control character.

The second operation shows that the string register X2 receives both an X
and a control character.  

I have experienced this problem with both nroff and ditroff.

nroff inserts an octal 36 (^^) while ditroff inserts a control-Q.

The obvious workaround is to insert a dummy statement just before the \}
but I would like to understand what is happening.  Any ideas?

.de M1
.if X\\n(R1X1X \{\
.tm \\*(U1\}
.if X\\n(R1X1X \{\
.ds X2 \\*(U1\}
..
.ds U1 X
.nr R1 1
.M1
.tm \*(X2X
 Laurence Leff, Ph.D               |A job is like sex, when you do it for money
CS,SMU, Dallas, Texas 75275-0122,  |You take away all the fun.
Phone: 214-692-3459 Moderator comp.doc.techreports/TRLIST, Symbolic Math List 
 convex!smu!leff leff%smu.uucp@uunet  E1AR0002 at SMUVM1 (BITNET) 

brown@vidiot.UUCP (Vidiot) (06/08/90)

In article <16321@smunews.UUCP> leff@.seas.smu.edu (leff) writes:
<A strange control character is being inserted on character interpolations
<before a closing \} of an if statement.
<
<In the example below, there are two operations involving interpolation of a
<string register before a \} of an if.  In the first operation, the output of 
<the "tm" inside of the macro, M1, includes both an X and a control character.
<
<The second operation shows that the string register X2 receives both an X
<and a control character.  
<
<I have experienced this problem with both nroff and ditroff.
<
<nroff inserts an octal 36 (^^) while ditroff inserts a control-Q.
<
<The obvious workaround is to insert a dummy statement just before the \}
<but I would like to understand what is happening.  Any ideas?
<
<.de M1
<.if X\\n(R1X1X \{\
<.tm \\*(U1\}
<.if X\\n(R1X1X \{\
<.ds X2 \\*(U1\}
<..
<.ds U1 X
<.nr R1 1
<.M1
<.tm \*(X2X

I have read somewhere that doing what you do is incorrect.  I too ran into
and problem and have solved it by doing:

.de M1
.if X\\n(R1X1X \{\
.tm \\*(U1
.\}
.if X\\n(R1X1X \{\
.ds X2 \\*(U1
.\}
..

The . in front of the \} makes it look like a n/troff command.  But since it
isn't, it is ignored, ie, a blank line isn't put into the output.  The \}
is still seen and operated on.

Your examples can best be re-written as:

.de M1
.if X\\n(R1X1X .tm \\*(U1
.if X\\n(R1X1X .ds X2 \\*(U1
..

The \{\ and \} are best used for multi-line if continuations.
-- 
      harvard\     att!nicmad\        spool.cs.wisc.edu!astroatc!vidiot!brown
Vidiot  ucbvax!uwvax..........!astroatc!vidiot!brown
      rutgers/  decvax!nicmad/ INET:<@spool.cs.wisc.edu,@astroatc:brown@vidiot>

morrell@hpcuhb.HP.COM (Michael Morrell) (06/08/90)

/ hpcuhb:comp.text / leff@.seas.smu.edu (leff) /  1:41 pm  Jun  1, 1990 /
A strange control character is being inserted on character interpolations
before a closing \} of an if statement.

In the example below, there are two operations involving interpolation of a
string register before a \} of an if.  In the first operation, the output of 
the "tm" inside of the macro, M1, includes both an X and a control character.

The second operation shows that the string register X2 receives both an X
and a control character.  

I have experienced this problem with both nroff and ditroff.

nroff inserts an octal 36 (^^) while ditroff inserts a control-Q.

The obvious workaround is to insert a dummy statement just before the \}
but I would like to understand what is happening.  Any ideas?

.de M1
.if X\\n(R1X1X \{\
.tm \\*(U1\}
.if X\\n(R1X1X \{\
.ds X2 \\*(U1\}
..
.ds U1 X
.nr R1 1
.M1
.tm \*(X2X
----------

The input parsing nroff/troff is very brain-damaged.  The \} gets converted to
a token during the early stages (the octal 36 or ^Q you saw).  For all the
commands which take as arguments the rest of the line (.ab, .tm, .ds, .as, and
maybe others), the parser will grab all input up to the newline, including the
tokenized \} (fortunately, comments started by \" are converted to a newline
before this step or they would also cause a problem).  Note that this also
causes problems with macro calls.  As an example:

  .de xy
  Arg count = \\n(.$
  ..
  .if 1=1 \{\
  .xy foo \}

will show that 2 arguments are passed!

I know of no version of nroff or troff which fixes this (and in fact all of the
standard macro packages have errors of this sort).  My suggestion is to always
use the following style:

  .if <cond> \{.      \" comment
  <stuff>
  .\}

I avoid using "\{\" on the first line since it lets you put a comment on the
if line.

    Michael

jaap@mtxinu.COM (Jaap Akkerhuis) (06/09/90)

In article <16321@smunews.UUCP> leff@.seas.smu.edu (leff) writes:
 > A strange control character is being inserted on character interpolations
 > before a closing \} of an if statement.
 > 
 > nroff inserts an octal 36 (^^) while ditroff inserts a control-Q.
 > 
 > The obvious workaround is to insert a dummy statement just before the \}
 > but I would like to understand what is happening.  Any ideas?
 > 

Other people have explained the way to circumvent this. But nobody
really told what it was. Well, just in case you wanted to know:

What is happening is that .tm does a poor job translating the internal
cookies back to ascii.

What I remember is that 036 is the internal token for the \} for old
troff (and nroff). In the new troff (ditroff) this is 021 (^Q).

	jaap