toni@erix.UUCP (Toni Roth) (07/18/85)
I recently started to use troff in order to write a macro package. As troff is new to me, I'm not sure it's really bugs that I've found, or if I use troff incorrect. However, I tried to write a macro that would print a header on each new page. The problem is : If it's the first page, I want to write something on a certain line on a certain distance from the edge. After that I always want to write something else further to the right, on the same line. So I had to split the in-line-commands in smaller parts, which made one piece each. I tried several variations, but none seemed to work. When I tried to find out why, I discovered that troff does not ignore comments and handles \c, \\c and \ at end of lines strangely. After a lot of trial-and error, this worked correctly: .de hd . . . \v'|1c'\ \h'|11.4c'\ \\*(ko \h'|18c.7c'\\n% .br or \v'|1c'\c \h'|11.4c'\ \\*(ko \h'|18c.7c'\\n% .br The things that didn't work was: \v'|1c'\ \h'|11.4c'\c \\*(ty\ \h'|18c.7c'\\n% .br \v'|1c'\ \h'|11.4c'\\c \\*(ty\ \h'|18c.7c'\\n% .br \v'|1c'\c\"comment \h'|11.4c'\ \\*(ty\ \h'|18c.7c'\\n% .br Which made breaks before the string ty was printed. There were many other strange things, but I can't list them all. My questions are: How do I split the in-line-commands (what do I put on the end of the macro lines) if I want to continue on the same line? How do I use \, \c and \\c ? How do I put comments on the end of in-line-command - lines?
lapoint@BRL.ARPA (Claude Lapointe) (07/24/85)
I'm not quite sure I know exactly what you're trying to do, or exactly what you are asking when you say "How do I split...." Nevertheless, perhaps the following will be of help. If I were writing the macros you show, they would be as follows. Note that your several examples reduce to only three. .de hd . . . \v'|1c'\h'|11.4c'\\*(ko\h'|18.7c'\\n% .br or \v'|1c'\h'|11.4c'\\*(ty\h'|18.7c'\\n% .br or \v'|1c'\h'|11.4c'\\*(ty\h'|18.7c'\\n%\"comment .br Be careful of comments. The book says a comment may be placed at the end of a line by preceding it with \" Realize that the character (blanks included) immediately preceding the \ becomes, by definition, the end of the line. Thus, on a text line or in a string definition (.ds) any blanks placed there merely for separation and ease of reading by a human become part of the text or string. Your line with a comment counts as a text line because it contains not only commands (more correctly, functions or escape sequences), but also content which actually appears in the output. Because I like to set off my comments with white space, I've gotten in the habit of NEVER placing comments on text or .ds lines. A comment may be on a line by itself if the line looks like a command -- . in column 1 followed by 0 or more blanks followed by \" The \ is the escape and quote character, and its rules are annoying until you get used to them. Each time [nt]roff sees one, it strips it off and in some way modifies the meaning of the following character. Thus, \v is converted immediately to an internal code meaning "alter the vertical position as indicated." Now consider \n% -- \n means replace the immediately following single character name of a register with its contents. This is done immediately when _roff sees the \n. In a macro definition, this is innappropriate. We want the value, not when the macro is defined, but when it is used. Thus \\n% At definition time, the first \ quotes the second. The created macro then contains \n% which yields the desired result at execution time. Depending on the number of times _roff will see the \construct before the ultimate result is actually output, one may need 2**n backslashes, n >= 0. (TROFF tutorial, bottom page 9) Note that the % is used in two ways (NROFF/TROFF User's Manual page 24 example near bottom and page 23 para 14): as the register name in \n%, and as the page number itself. Note the different interpretations of the | symbol in vertically oriented as opposed to horizontally oriented requests (User's Manual, page 9, last subpara of para 1.3). \c can be considered a kind of glue, sticking together text which otherwise would be broken (User's Manual page 12 para 4.2). If I wanted to underline only the syllable ter in the word interminable (which this response is becoming), one of several ways would be in\c .ul ter\c minable Without the \c...\c, I would get 3 words on output. If I am in nofill mode, each text line's end causes a break. If I want to combine input lines in the output, I can say This is part one\c followed by part two. and get the output This is part onefollowed by part two.