Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!ginosko!aplcen!bink From: bink@aplcen.apl.jhu.edu (Ubben Greg) Newsgroups: comp.unix.questions Subject: Re: How to make nroff boldface on a terminal that can highlight? Summary: LEX easily converts the default NROFF "typefaces" Message-ID: <2536@aplcen.apl.jhu.edu> Date: 5 Aug 89 16:34:01 GMT References: <20477@adm.BRL.MIL> <537@anasaz.UUCP> Reply-To: bink@aplcen.apl.jhu.edu (Greg Ubben) Organization: The Johns Hopkins University, Baltimore MD Lines: 58 In article <537@anasaz.UUCP> duane@anasaz.UUCP (Duane Morse) writes: > In article <20477@adm.BRL.MIL>, justice@dao.nrc.ca (Gerald Justice) writes: > > I am writing some local man pages and was wondering if it was possible > > to have nroff pass information about boldfaced text to a user's terminal > > to have it appear as highlighted text. >... > Some terminals are smart enough to take the standard char-backspace-char > sequence and do boldface. The public domain 'less' program is smart > enough to take these sequences and use inverse video for highlighting. > We keep formatted man pages under /usr/catman, like a lot of other > systems, to avoid the overhead of formatting the pages every time someone > wants to look something up. >... Jan Anderson also mentions a BSD filter called "ul" which converts the italics and bolding overstrikes used in default (-T37) nroff output into highlighting commands for a particular output device. If you don't have access to this program (System V users), I've found that one can easily create a filter for any particular device using a simple lex(1) program. As an example, the following lex program (eproff.l) will create a filter to format nroff output for an Epson printer: %start ITALIC BOLD %% _\b { printf("\0334"); BEGIN ITALIC; } .\b { printf("\033E"); BEGIN BOLD; } .\b ; ./[^_] { ECHO; printf("\0335"); BEGIN INITIAL; } ./[\t\n ]*([!-~][^\b]|_\b) { ECHO; printf("\033F"); BEGIN INITIAL; } You would compile it by lex eproff.l && cc lex.yy.c -ll -o eproff and might use it as man lex | eproff | lp -dep ... If the input were: It does _^Hi_^Ht_^Ha_^Hl_^Hi_^Hc_^Hs _^Ht_^He_^Hx_^Ht and b^Hb^Hb^Hbo^Ho^Ho^Hol^Hl^Hl^Hld^Hd^Hd^Hd t^Ht^Ht^Hte^He^He^Hex^Hx^Hx^Hxt^Ht^Ht^Ht correctly. The output would be: It does ^[4italics^[5 ^[4text^[5 and ^[Ebold text^[F correctly. Notice the program maximizes the text between bolding commands in order to simplify the output -- this might be undesirable for reverse-video on display devices. It doesn't do so for italics because this was converted from a version which changed italics to continuous underlining for a Xerox 2700-II laser printer. You can create a filter for other devices by simply changing the printf() arguments. Or make it more general by adding a main() which looks up TERM or a -T argument in the terminfo to get the appropriate codes. My laser printer version also recognizes the line motions ^[7, ^[8, and ^[9. E-mail questions or feedback are welcome. -- Greg Ubben bink@aplcen.apl.jhu.edu