[comp.unix.questions] VI/NROFF symbolics question

fontana@mdiva1.uucp (01/20/89)

I am a IBM SCRIPT and GGML user.  I need to know how to
do a symbolic reference in VI and NROFF. (i.e. I want to
be able to define a table of symbolic strings and their
expanded names or string.  Then I want to only type the
symbolics in the text and have the system input the expanded
names when I run off the text.)

Any helpful hints would be appreciated.

jenni@elan.UUCP (Jenni Hufnagel) (01/24/89)

From article <108@mdiva1.uucp>, by fontana@mdiva1.uucp:
> I am a IBM SCRIPT and GGML user.  I need to know how to
> do a symbolic reference in VI and NROFF. (i.e. I want to
> be able to define a table of symbolic strings and their
> expanded names or string.  Then I want to only type the
> symbolics in the text and have the system input the expanded
> names when I run off the text.)
> 
> Any helpful hints would be appreciated.


In nroff you can define any string you want in a nterm file.  
These files are found in /usr/lib/nterm.   Pick the one that is
correct for your printer.
In the nterm file an example would be as follows

charset
sq 2 []
+- 1 +\b_
  


you  would reference sq in your document by \*(sq.




					Jenni Hufnagel	
					Elan Computer Group, Inc.
					..!{ames,hplabs,uunet}!elan!jenni
-- 
Jenni Hufnagel
..!{ames,hplabs}!elan!jenni
Elan Computer Group, Inc.
410 Cambridge Avenue, Suite A,  Palo Alto,  CA 94306,  (415) 322-2450

bryan@iconsys.UUCP (Bryan Cardoza) (01/24/89)

From article <108@mdiva1.uucp>, by fontana@mdiva1.uucp:
> be able to define a table of symbolic strings and their
> expanded names or string.  Then I want to only type the
> symbolics in the text and have the system input the expanded

In article <418@elan.UUCP> jenni@elan.UUCP (Jenni Hufnagel) writes:
>In nroff you can define any string you want in a nterm file.  
>These files are found in /usr/lib/nterm.   Pick the one that is
>correct for your printer.
>In the nterm file an example would be as follows

>charset
>sq 2 []
>+- 1 +\b_

>you  would reference sq in your document by \*(sq.

If you can't write in /usr/lib, or you don't want to clobber characters
in your default character set, you can do the following in any file:

	.ds X "A string with a one character identifier.
	.ds XY "A string with a two character identifier.

The leading double-quote is not required, but it increases clarity.
You would reference the strings as follows:

	\*X
and
	\*(XY

Be sure not to clobber any variables your macro package may use.  If you
use "mm," you should be safe as "mm" uses obscure variable names (such as
"]D," etc.).  For other macro packages, you'll either have to examine
the macro package (for example, the first part of "ms" is in the file
/usr/lib/tmac/tmac.s) or just take pot luck.

If you want to use a "string table" in several documents, you could create
a file with the string definitions, and then include the file in your
documents using the ".so" directive in n/troff.  For example:

	===== file /usr/bryan/docs/strings =====

	.\" Some general strings, for example:
	.\"
	.ds Co "Copyright 19\n(yr Icon International, Inc.
	.ds Rt "is a registered trademark of Icon International, Inc.
	.\"
	.\" Something n/troff specific, for example:
	.\"
	.if n .ds OQ ""
	.if t .ds OQ "``
	.if n .ds CQ ""
	.if t .ds CQ ''

	===== in my file =====

	.so /usr/bryan/docs/strings
	\*(OQThis is a quoted string.\*(CQ
	.br
	DT1200\(rg \*(Rt
	.br
	\*(Co

You get the idea.  The n/troff manual and tutorial has lots of other ideas.

-- 
Bryan Cardoza			uunet!iconsys!bryan
Software Engineer
SANYO/ICON			Telephone: (801) 225-6888
Orem, Utah			FAX: (801) 226-0651

guy@auspex.UUCP (Guy Harris) (01/25/89)

 >> I am a IBM SCRIPT and GGML user.  I need to know how to
 >> do a symbolic reference in VI and NROFF. (i.e. I want to
 >> be able to define a table of symbolic strings and their
 >> expanded names or string.  Then I want to only type the
 >> symbolics in the text and have the system input the expanded
 >> names when I run off the text.)

 >In nroff you can define any string you want in a nterm file.  
 >These files are found in /usr/lib/nterm.

I think you meant to say "in the DWB X.y version of 'nroff', you can
define any string you want...", or perhaps "in the Elan Computer Group
version of 'nroff'...".  I sure don't remember that feature being
present in older versions of "nroff"; I do know that in some DWB release
(2.0, I think) "nroff" was "modernized" (merged back into the
"modernized" (whatever)-Independent TROFF, and upgraded to read ASCII
printer-specification files).

While this may *work* in his case, I don't think it's necessarily what
he *wanted*.  I think he basically wanted what, as I remember from a
brief scan of the SCRIPT documentation, are basically "variables", so
that you can say (NOTE: this is not SCRIPT syntax, I don't know what
that is; it's a pseudo-syntax intended to give the general idea)

	.set variable "FOO" to "Hi, mom!"

	...
	And now, the variable "FOO" is set to "\{FOO\}".

and have it print

	And now, the variable "FOO" is set to "Hi, mom!".

Well, "vi" doesn't do any of that; it's just a dumb editor and knows
relatively little of "nroff".  The way you do that with "nroff" and
"troff", though, is with "strings":

	.ds FO "Hi, mom!"

	...

	And now, the string "FO" is set to \*FO.

Unfortunately, in vanilla versions of "nroff"/"troff", strings can have
only one-character or two-character names, although as a consolation
prize you can use non-alphanumeric characters in those names.  However,
you have to be careful to avoid using names also used by whatever macro
package you're using; the macro package documentation *might* list all
the names (or classes of names) it uses, but if it doesn't, you'll have
to look it up in the source for the macro package....

hapke@mcdurb.Urbana.Gould.COM (01/25/89)

In a recent (and good) article, guy@auspex.UUCP writes:

>        And now, the string "FO" is set to \*FO.

There's a small typo here;  the syntax for printing a two-character defined
string would be \*(FO.  A single-character string is printed with \*X.

>     However,
> you have to be careful to avoid using names also used by whatever macro
> package you're using; the macro package documentation *might* list all
> the names (or classes of names) it uses, but if it doesn't, you'll have
> to look it up in the source for the macro package....

The reason for this is that "request, macro, and string names share the same
name list"  (Ossanna, NROFF/TROFF User's Manual). This means that a string
define can overwrite a macro definition or even a standard nroff/troff command.
If you overwrite a basic command, like .ft or .if, chaos follows.  (Yes, I've
seen this happen.)

You don't have to look at the macro package to get information on names.
There's an obscure nroff/troff command, .pm, that will 'print macros.'  It
prints the names of all defined strings and macros to standard error.

Warren Hapke, Motorola MCD Urbana Design Center
  uunet!uiucuxc!mcdurb!hapke

leo@philmds.UUCP (Leo de Wit) (01/26/89)

In article <108@mdiva1.uucp> fontana@mdiva1.uucp writes:
|I am a IBM SCRIPT and GGML user.  I need to know how to
|do a symbolic reference in VI and NROFF. (i.e. I want to
|be able to define a table of symbolic strings and their
|expanded names or string.  Then I want to only type the
|symbolics in the text and have the system input the expanded
|names when I run off the text.)
|
|Any helpful hints would be appreciated.

You might consider using a preprocessor, like cpp (directly via
/lib/cpp or indirectly via cc -E), or m4. This way you can enter your
symbol definitions either directly in the file (#define symbol value),
in an include file (#include "inc_file") so it is easier to share
definitions, or on the commandline (cc -E -Dsymbol=value) so you can
add flexibility, or any combinations of the three. You can also use the
conditionals of cpp (#if, #ifdef, #ifndef, #else, #endif) to select a
whole set of symbol/value pairs at once. You will have to filter out
the # line "file" lines that cpp generates (e.g. with sed).
So this would become something like

cc -E yourfile|sed '/^# [0-9]* ".*"$/d'|nroff

Hope this helps,
                  Leo.

leung@imspw6.UUCP (Aldrin Leung) (01/26/89)

>From article <108@mdiva1.uucp>, by fontana@mdiva1.uucp:
> I am a IBM SCRIPT and GGML user.  I need to know how to
> do a symbolic reference in VI and NROFF. (i.e. I want to
> be able to define a table of symbolic strings and their
> expanded names or string.  Then I want to only type the
> symbolics in the text and have the system input the expanded
> names when I run off the text.)
> 
> Any helpful hints would be appreciated.

You can use have

	.ds sq <the string you want> 

in the beginning of the document and reference sq in your document by
\*(sq.

Aldrin W. Leung
IMS, Inc.
-- 
Aldrin W. Leung
Integrated Microcomputer System, Inc.
leung%imspw6@uunet.uu.net

steinar@fdmetd.uucp (Steinar Overbeck Cook) (01/27/89)

In article <418@elan.UUCP>, jenni@elan.UUCP (Jenni Hufnagel) writes:
> From article <108@mdiva1.uucp>, by fontana@mdiva1.uucp:
> 
> In nroff you can define any string you want in a nterm file.  
> These files are found in /usr/lib/nterm.   Pick the one that is
> correct for your printer.
> 
> 

The solution with defining the table of strings after 'charset' in a
'nterm' file, will only work if you have one of the newer versions of
nroff(1). I.e. like the ones sold by Elan. It is possible to change the
strings that are emitted by "old" nroff(1)'s though, but this requieres
hacking in the terminal description for the terminal/printer you are
using. To do this you will need a PD program called 'nroff(1)tab'.

If you have an "old" nroff(1) which uses compiled terminal descriptions,
you probably want to have a filter which expands your defines into the
correct strings.

If you have and "old" nroff(1) I would suggest using cpp(1), awk(1), sed(1),
ed(1) or even write your own little filter using lex(1).


-----
Steinar Overbeck Cook
Fellesdata a.s
P.O. Box 248
0212 OSLO 2
NORWAY
E-mail : ...!mcvax!ndosl!fdmetd!steinar
				 or
         steinar@fdmetd.uucp

guy@auspex.UUCP (Guy Harris) (01/27/89)

>Be sure not to clobber any variables your macro package may use.  If you
>use "mm," you should be safe as "mm" uses obscure variable names (such as
>"]D," etc.).

Note that, at least in the "[nt]roff" versions with which I'm familiar,
macros and strings are really the same thing, so don't use string names
that match the names of macros.

steinar@fdmetd.uucp (Steinar Overbeck Cook) (01/30/89)

In article <889@auspex.UUCP>, guy@auspex.UUCP (Guy Harris) writes:
> 
>  >> I am a IBM SCRIPT and GGML user.  I need to know how to
>  >> do a symbolic reference in VI and NROFF. (i.e. I want to
>  >> be able to define a table of symbolic strings and their
> 
> 	.set variable "FOO" to "Hi, mom!"
> 

I have written a package which takes IBM SCRIPT/VS (with GML's) and
converts it into [n/t]roff commands. As a part of this package I have
used Lex to write a filter which will handle the SCRIPT command :

   .se myvar='My variable'

and every time the macro '&myvar.' is used in the text, will expand it
into 'My variable'.

The program is very simple and straightforward, mail me if you would
like a copy of it.


-------------------
Steinar Overbeck Cook
Fellesdata a.s
P.O. Box 248
0212 OSLO 2
NORWAY
Phone : +47 2 52 80 80
Fax   : +47 2 52 85 10
E-mail : ...!mcvax!ndosl!fdmetd!steinar
				 or
         steinar@fdmetd.uucp

jimi@h-three.UUCP (jimi) (01/31/89)

In article <319@iconsys.UUCP>, bryan@iconsys.UUCP (Bryan Cardoza) writes:
> From article <108@mdiva1.uucp>, by fontana@mdiva1.uucp:
> 
> 	.ds X "A string with a one character identifier.
> 	.ds XY "A string with a two character identifier.
> 
> The leading double-quote is not required, but it increases clarity.
> You would reference the strings as follows:
> 
The leading double quote is required if the string definition
contains an initial blank or quote.

What does it mean to say the "leading double-quote...increases clarity?"
I don't understand.
-- 
Jim Ingram	          uunet!h-three!jimi | jimi%h-three@uunet.uu.net
h-three Systems Corporation   P.O. Box 12557 RTP NC 27709   919 549 8334