fred@urquell.osf.org (Fred Dalrymple) (01/16/90)
We need to translate some LaTeX documents into troff -mm. We therefore need a translator from: SOURCE to DESTINATION BECAUSE LaTeX troff -mm that would solve the problem in one step LaTeX TeXinfo we have a TeXinfo->troff translator LaTeX Interleaf we have an Interleaf->troff translator (although it isn't a general solution for interleaf....) LaTeX ISIL we have an ISIL->troff translator Can anyone help us? Thanks-- Fred Dalrymple Open Software Foundation fred@osf.org 617-621-8855
spqr@ecs.soton.ac.uk (Sebastian Rahtz) (01/16/90)
>>>>> On 15 Jan 90 21:18:08 GMT, fred@urquell.osf.org (Fred Dalrymple) said: > We need to translate some LaTeX documents into troff -mm. > We therefore need a translator from: > LaTeX troff -mm that would solve the problem in one step to do the job PROPERLY is impossible; so do it roughly, and then tart it up. the following sed script does the trivial bits - add in your own lines for the constructs your paper uses. #!/bin/sh # Usage: lat2mm [file] # Converts tex document to mm for previewing; eg for foo.tex, use # lat2mm foo | nroff -mm | ul # Tries to act like an nroff preprocessor, not a tex program. # The only concession to the latter paradigm is that it tries # appending a .tex suffix if it can't open a file. # After all, it is for interfacing a tex file to an nroff pipeline. # BUGS # It would take a lot of work to perfect this sed script, because # although sed is appropriate for a quick hack ("No sooner sed than done...") # it is not the ideal tool for this problem (at least, not on its own). # As a mechanism for previewing the structure of one's tex document, this # program is fine. # For use with troff, some special characters could be converted # too, eg s/---/\\(em/, s/--/\\(en/, etc. # There is a fundamental problem with small caps, in that conversion # to upper case is required. # HISTORY # Based on Sebastian's LaTeX to mm Converter # Dave goodness added 29-7-87 (some sed tricks and cmd line handling) # More Seb goodness added 29-7-87 (improved script) # Les goodness added 3-8-87 (improved LaTeX handling) prog=`basename $0` if [ $# -gt 1 ] ; then echo Usage: $prog "[ file ]" 1>&2 exit 1 fi if [ $# -eq 1 ] ; then file=$1 if [ ! -r $file ] ; then file=$file.tex if [ ! -r $file ] ; then echo $prog: cannot open $1 1>&2 exit 2 fi fi else file="-" fi cat $file | \ ############################# THE SCRIPT ITSELF ############################## sed 's/\([^\\]\)%\(.*\)/\1\\"\2/g s/^%/." / s/\\%/%/g s/\\tableofcontents/\.TC/ /\\bibliographystyle/d /\\documentstyle/d s/\\begin{document}/\.SA 1\.nr Pt 2\.nr Ps 0\.nr Si 10\.nr Cl 2.nr *F 1/ /\\end{document}/d s/\\input \([a-zA-Z0-9.]*\)/(INCLUDING FILE \1)/g /\\thanks/d s/\\title[^{]*{\(.*\)}/\.TL\1/ /\\title/N s/\\title[^{]*{\(.*\)}/\.TL\1/ s/\\footnote{\([^}]*\)}/\\\*F.FS\1.FE/ /\\footnote{/N s/\\footnote{\([^}]*\)}/\\\*F.FS\1.FE/ /\\footnote{/N s/\\footnote{\([^}]*\)}/\\\*F.FS\1.FE/ s/\\author{\(.*\)}/\.AU \"\1\"/ /\\author{/N s/\\author{\(.*\)}/\.AU \"\1\"/ s/\\date{\(.*\)}/\.AF \"\1/ s/\\maketitle.*/\.MT 4/ s/\\chapter{\([^}]*\)}/\.bp.B.ce\1.P.sp 3/ s/\\section{\(.*\)}/\.H 1 \"\1/ s/\\section\*{\(.*\)}/\.H 1 \"\1/ s/\\subsection\*{\(.*\)}/\.H 2 \"\1/ s/\\subsection{\(.*\)}/\.H 2 \"\1/ s/\\subsubsection{\(.*\)}/\.H 3 \"\1/ s/\\subsubsection\*{\(.*\)}/\.H 3 \"\1/ s/\\begin{ding.*$/\.BL/ s/\\begin{itemize}/\.BL/ s/\\begin{enumerate}/\.AL/ s/\\begin{description}/\.VL 10/ /\\begin{tabular}/,/\\end{tabular}/s/ / /g /\\begin{tabular}/,/\\end{tabular}/s/\&/ /g /\\begin{tabular}/,/\\end{tabular}/s/\\\\// s/\\begin{tabular}{\(.*\)}.*/.TSbox;\1./ s/\\end{description}/\.LE/ s/\\end{dinglist}/\.LE/ s/\\end{itemize}/\.LE/ s/\\end{enumerate}/\.LE/ s/\\end{tabular}/.TE/ s/{\\bf \([^}]*\)}/\\fB\1\\fP/g /{\\bf /N s/{\\bf \([^}]*\)}/\\fB\1\\fP/g s/{\\em \([^}]*\)}/\\fI\1\\fP/g /{\\em /N s/{\\em \([^}]*\)}/\\fI\1\\fP/g s/{\\it \([^}]*\)}/\\fI\1\\fP/g /{\\it /N s/{\\it \([^}]*\)}/\\fI\1\\fP/g s/{\\sc \([^}]*\)}/\\s-2\1\\s+2/g s/\\item/\.LI/ s/\\item\[\(.*\)\]/\.LI\"\1\"/ s/\\ref{\([^}]*\)}/REFERENCE \1/g s/\\label{\([^}]*\)}/LABEL \1/g s/\\cite\[\(.*\)\]{\([^}]*\)}/CITE \1 \2/g s/\\cite{\([^}]*\)}/CITE \1/g s/\\[a-zA-Z0-9][a-zA-Z0-9]*{[^}]*}{[^}]*}//g s/\\[a-zA-Z0-9][a-zA-Z0-9]*{[^}]*}//g s/\\[a-zA-Z0-9][a-zA-Z0-9]*=[a-zA-Z0-9][a-zA-Z0-9]*//g s/\\[a-zA-Z0-9][a-zA-Z0-9]*//g s/{\([^}]*\)}/\1/g' | \ ################################################################################ # translate the control-G's to newlines tr '\007' '\012' exit 0 # end of lat2mm -- Sebastian Rahtz S.Rahtz@uk.ac.soton.ecs (JANET) Computer Science S.Rahtz@ecs.soton.ac.uk (Bitnet) Southampton S09 5NH, UK S.Rahtz@sot-ecs.uucp (uucp)