> >>>>> "Bruce" == Bruce Momjian <[EMAIL PROTECTED]> writes:
> 
> Bruce> I wanted to give the list a status on my efforts to convert to
> Bruce> lyx from troff.
> 
> Bruce> After downloading tr2latex, reworking some items that cause
> Bruce> reLyX trouble, and mapping my custom troff macros to latex
> Bruce> macros, I am now getting 98% conversion of my troff documents.
> 
> That's great. If you have a package or a page explaining how to do
> that, we'll link to it from the web page.
> 
> JMarc
> 

Here is the info you requested.  You can add it as a page on your web
site if you wish.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  [EMAIL PROTECTED]                |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
...................................................................

The attached document is in both web page and text formats.
View the one which looks best.

Converting Troff to Lyx

I have found it easy to convert existing troff documents to LyX.  First, get tr2latex, the Troff-to-TeX translator by Christian Engel, from the nearest CTAN site.  Second, I am attaching a shell script I used for this purpose.

Because troff is limited, I had written my own troff macros for bullets and computer source text. LaTeX/LyX has these capabilities, so the script maps my custom macros to the LaTeX/LyX versions. The script also does some cleanups to workaround problems with tr2latex and reLyX.

#!/bin/sh
trap "rm -f /tmp/$$.tex /tmp/$$.lyx /tmp/$$.relyx*" 0 1 2 3 15

cat "$@" |
sed 's;^\.so .*/groff_macros/macros;;g' |	# custom macros
sed 's;^\.so .*/groff_macros/bap;;g' |
sed 's;^\.so .*/groff_macros/calendar;;g' |
sed 's/^\.Th *\([^ ]*\)/\1@latexob@@latexbs@small th@latexcb@/g' |
sed 's/^\.Am */@latexob@@latexbs@small AM@latexcb@/g' |
sed 's/^\.Am *\([^ ]*\)/\1@latexob@@latexbs@small AM@latexcb@/g' |
sed 's/^\.Pm */@latexob@@latexbs@small PM@latexcb@/g' |
sed 's/^\.Pm *\([^ ]*\)/\1@latexob@@latexbs@small PM@latexcb@/g' |
sed 's/^\.Bb */@latexbs@begin@latexob@itemize@latexcb@\
@latexbs@item /g' |
sed 's/^\.Bc */@latexbs@item /g' |
sed 's/^\.Be */@latexbs@end@latexob@itemize@latexcb@/g' |
sed 's/^\.Tb */@latexbs@begin@latexob@lyxcode@latexcb@\
.nf/g' |
sed 's/^\.Te */@latexbs@end@latexob@lyxcode@latexcb@\
.fi/g' |
sed 's/^\.Tb1 */@latexbs@texttt@latexob@/g' |
sed 's/^\.Te1 */@latexbs@@latexcb@/g' |
sed 's/^\.St .*$/.\\"/g' |
sed 's/^\.Co .*$/.\\"/g' |
sed 's/^\.AI *$/.AU/g' |	# no organization in lyx
sed 's/^\.sp 0.5v\?$/.\\"/g' |	# handle this .sp
sed 's/^\.LP *//g' | 		# this is lyx equivalent
sed 's/^\.sp *$//g' | 		# want blank line
# handle nofill(.nf) by adding newlines
awk '
	BEGIN		{nofill = "N"}
	{	if ($1 == ".nf")
			nofill = "Y";
		else if ($1 == ".fi")
		{
			printf "\n";
			nofill = "N";
		}
		else	{print $0}
		if (nofill == "Y")
			printf "\n";
	}' |
tr2latex |
sed 's/@latexbs@/\\/g' |		# translate inserted latex stuff
sed 's/@latexob@/{/g' |
sed 's/@latexcb@/}/g' |
sed 's/\\bs \?/\\textbackslash{}/g' |	#convert this properly
sed 's;\\input \([a-zA-Z_0-9/\.]*\);\\input {\1};g' |	#reLyX needs {}
sed 's/\\shead/\\section\*/g' |		# map to LyX macros
sed 's/{IPlist}/{enumerate}/g' |
sed 's/\\IPitem{{[0-9\.]*}}/\\item/g' |
sed 's/\\IPitem{?{?[0-9]?\.?}?}?/\\item/g' >/tmp/$$.tex

#cat /tmp/$$.tex	# uncomment for testing
#exit

reLyX /tmp/$$.tex
cat /tmp/$$.lyx


                          Converting Troff to Lyx
                                      
   I have found it easy to convert existing troff documents to LyX.
   First, get tr2latex, the Troff-to-TeX translator by Christian Engel,
   from the nearest CTAN site.  Second, I am attaching a shell script I
   used for this purpose.
   
   Because troff is limited, I had written my own troff macros for
   bullets and computer source text. LaTeX/LyX has these capabilities, so
   the script maps my custom macros to the LaTeX/LyX versions. The script
   also does some cleanups to workaround problems with tr2latex and
   reLyX.
#!/bin/sh
trap "rm -f /tmp/$$.tex /tmp/$$.lyx /tmp/$$.relyx*" 0 1 2 3 15

cat "$@" |
sed 's;^\.so .*/groff_macros/macros;;g' |       # custom macros
sed 's;^\.so .*/groff_macros/bap;;g' |
sed 's;^\.so .*/groff_macros/calendar;;g' |
sed 's/^\.Th *\([^ ]*\)/\1@latexob@@latexbs@small th@latexcb@/g' |
sed 's/^\.Am */@latexob@@latexbs@small AM@latexcb@/g' |
sed 's/^\.Am *\([^ ]*\)/\1@latexob@@latexbs@small AM@latexcb@/g' |
sed 's/^\.Pm */@latexob@@latexbs@small PM@latexcb@/g' |
sed 's/^\.Pm *\([^ ]*\)/\1@latexob@@latexbs@small PM@latexcb@/g' |
sed 's/^\.Bb */@latexbs@begin@latexob@itemize@latexcb@\
@latexbs@item /g' |
sed 's/^\.Bc */@latexbs@item /g' |
sed 's/^\.Be */@latexbs@end@latexob@itemize@latexcb@/g' |
sed 's/^\.Tb */@latexbs@begin@latexob@lyxcode@latexcb@\
.nf/g' |
sed 's/^\.Te */@latexbs@end@latexob@lyxcode@latexcb@\
.fi/g' |
sed 's/^\.Tb1 */@latexbs@texttt@latexob@/g' |
sed 's/^\.Te1 */@latexbs@@latexcb@/g' |
sed 's/^\.St .*$/.\\"/g' |
sed 's/^\.Co .*$/.\\"/g' |
sed 's/^\.AI *$/.AU/g' |        # no organization in lyx
sed 's/^\.sp 0.5v\?$/.\\"/g' |  # handle this .sp
sed 's/^\.LP *//g' |            # this is lyx equivalent
sed 's/^\.sp *$//g' |           # want blank line
# handle nofill(.nf) by adding newlines
awk '
        BEGIN           {nofill = "N"}
        {       if ($1 == ".nf")
                        nofill = "Y";
                else if ($1 == ".fi")
                {
                        printf "\n";
                        nofill = "N";
                }
                else    {print $0}
                if (nofill == "Y")
                        printf "\n";
        }' |
tr2latex |
sed 's/@latexbs@/\\/g' |                # translate inserted latex stuff
sed 's/@latexob@/{/g' |
sed 's/@latexcb@/}/g' |
sed 's/\\bs \?/\\textbackslash{}/g' |   #convert this properly
sed 's;\\input \([a-zA-Z_0-9/\.]*\);\\input {\1};g' |   #reLyX needs {}
sed 's/\\shead/\\section\*/g' |         # map to LyX macros
sed 's/{IPlist}/{enumerate}/g' |
sed 's/\\IPitem{{[0-9\.]*}}/\\item/g' |
sed 's/\\IPitem{?{?[0-9]?\.?}?}?/\\item/g' >/tmp/$$.tex

#cat /tmp/$$.tex        # uncomment for testing
#exit

reLyX /tmp/$$.tex
cat /tmp/$$.lyx



Reply via email to