Xref: utzoo comp.lang.scheme:875 comp.lang.lisp:2284 comp.text:5315 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!mcsun!ukc!edcastle!aiai!jeff From: jeff@aiai.ed.ac.uk (Jeff Dalton) Newsgroups: comp.lang.scheme,comp.lang.lisp,comp.text Subject: Re: Looking for "literate programming" tools for Scheme/LISP Message-ID: <1271@skye.ed.ac.uk> Date: 23 Oct 89 17:55:45 GMT References: <1989Oct16.153232.19051@mentor.com> Reply-To: jeff@aiai.UUCP (Jeff Dalton) Organization: AIAI, University of Edinburgh, Scotland Lines: 54 A while ago, I prepared some really simple tools for processing files that were both documents and source code. The basic idea is to use a verbatim environment (with *no* interesting processing) for code, but under a different name. Consequently, it will work for any programming language, but will never do any fancy formatting. The idea is this: You write a ".ptex" file. Two "projections" are defined for such files: one converts a ".ptex" file to a ".tex" file; the other converts it to a ".lsp" (or whateverP file. Two new environments are defined: program -- converted directly to verbatim for ".tex"; contents outout as-is for ".lsp". program-only -- like program, but discarded for ".tex" All that's required are two AWK scripts and some entries in a Makefile: -------------------- Makefile entries -------------------- .SUFFIXES: .ptex .tex .lisp .lsp .ptex.tex: ; awk -f totex < $*.ptex > $*.tex .ptex.lsp: ; awk -f tocode < $*.ptex > $*.lsp .ptex.lisp: ; awk -f tocode < $*.ptex > $*.lisp -------------------- totex script -------------------- BEGIN { state="copy" } state == "copy" && /^ *\\begin{program}/ {print "\\begin{verbatim}"; break} state == "copy" && /^ *\\end{program}/ {print "\\end{verbatim}"; break} state == "copy" && /^ *\\begin{program-only}/ {state="ignore"; break} state == "copy" {print; break} /^ *\\end{program-only}/ {state = "copy"; break} -------------------- tocode script -------------------- BEGIN { state="ignore" } state == "copy" && /^ *\\end{program}/ {state = "ignore"; printf "\n"; break} state == "copy" && /^ *\\end{program-only}/ {state = "ignore"; printf "\n"; break} state == "copy" {print; break} /^ *\\begin{program-only}/ {state = "copy"; break} /^ *\\begin{program}/ {state = "copy"; break} -------------------- end -------------------- Simple, but can be effective. Jeff Dalton, JANET: J.Dalton@uk.ac.ed AI Applications Institute, ARPA: J.Dalton%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!J.Dalton