From Kurt.Hornik@ci.tuwien.ac.at  Mon Feb 12 15:10:14 2001
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Mon, 12 Feb 2001 16:10:14 +0100
Subject: [Rd] Off-topic: Pretty-printing R (or S) code with GNU a2ps
In-Reply-To: <14962.20626.613619.35152@sonny.eddelbuettel.com>
References: <14962.20626.613619.35152@sonny.eddelbuettel.com>
Message-ID: <14983.64726.946115.11996@mithrandir.hornik.net>


	[Manually approved by MM -- because it contains binary attachment ]

--QcBiZYhiHg
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

>>>>> Dirk Eddelbuettel writes:

> GNU a2ps is a fairly versatile text-to-anything processor.  It is
> useful for typsetting source code from a wide variety of programming
> languages.  As R (ie S) wasn't supported yet, I quickly cobbled a
> style sheet for the S language together. Stylesheets are documented in
> the texinfo docs for a2ps, and examples can be found in
> /usr/share/a2ps/sheets (on Debian at least, others distros or unices
> probably have similar locations). IIRC a2ps exists for NT but might
> require Cygwin. I typeset on Linux and only print on NT :)

> Well, as I still don't really know what I'm doing with R, I would
> appreciate comments / feedback / input from anyone could spend a
> moment or two on this.  To activate the stylesheet, simple patch

>       /usr/share/a2ps/sheets/sheets.map

> as per the short diff below which declares that the stylesheet s.ssh
> shall be used for filenames matching /*.[RS]/.  The sheet itself is
> attached, just place it in the same directory, ie
> /usr/share/a2ps/sheets/.

> Usage then simply becomes
>       a2ps -Pdisplay foo.R
> or
>       a2ps foo.R -o foo.ps; gv foo.ps
> in case the "display" device isn't defined.

Thanks for bringing this up.  We have locally used style sheets S.ssh
for S code and Rd.ssh for Rd documentation format, both written by T
Hothorn.  I attach these files below.

> A few points / questions:

>  * content:  a2ps uses tricks to use TeX symbols. It works well to typset
>    <- with \leftarrow (uncomment that in s.ssh to see) but I couldn't tell
>    it to parse
>       a<-2
>    it only finds <- with whitespace, eg
>       a <- 2

Torsten gets this right by using a different alphabet, I think.

>    What could be done about <<- ?  Is there a matching TeX symbol?

Dunno.

>  * more content: Is the list of keywords really that short? I couldn't find
>    much else...

R-lang says:

	The following identifiers have a special meaning and should not
	be used for object names

	     if else repeat while function for in next break
	     TRUE FALSE NULL NA Inf NaN
	     ... ..1 ..2 etc.

so I think this is the list of keywords to use.

(Yes switch() is not in there ...)

>  * scope:  Are other file extensions in use? Are there conventions for S or
>    Splus files?  Any clever way to make a2ps understand the files in 
>    $R_HOME/library/$PACKAGE/R  are also R?  Could file(1) be taught what 
>    an R file is?

I think assuming that extensions `.R' and `.Rd' for R code and doc
source files are pretty safe.  The package installer will also allow for
code extensions `.r', `.S', `.s', and `.q', but I think only the last of
these may be specific enough to make it into the extension list.

No R magic in general.  ESS think .R/.r are safe for auto-mode-alist and
.S/.s need enforcing.  [One could try checking for Emacs-style mode
magic but I think that would be a bad idea.]

>  * editorial: shall this be the s.ssh or r.ssh or rs.ssh?

I think we want S.ssh, as this is a style sheet for code written in the
S language.

Best,
-k


--QcBiZYhiHg
Content-Type: application/octet-stream
Content-Disposition: attachment;
	filename="S.ssh"
Content-Transfer-Encoding: base64

IyBUaGlzIGlzIGEgUiBzaGVldApzdHlsZSBSIGlzCndyaXR0ZW4gYnkgIlRvcnN0ZW4gSG90aG9y
biA8aG90aG9ybkBjaS50dXdpZW4uYWMuYXQ+Igp2ZXJzaW9uIGlzIDAuMQpyZXF1aXJlcyBhMnBz
IDQuOS41Cgpkb2N1bWVudGF0aW9uIGlzCiAgICJDcmVhdGVzIHByZXR0eSBSLWNvZGUgcG9zdHNj
cmlwdCBmaWxlcy4iCmVuZCBkb2N1bWVudGF0aW9uCgphbHBoYWJldHMgYXJlCiAgICJBQkNERUZH
SElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6XyMkJT0tJi8iCgpj
YXNlIHNlbnNpdGl2ZQoKIyBhbmNlc3RvcnMgYXJlCiMgICBjCiMgZW5kIGFuY2VzdG9ycwoKc2Vx
dWVuY2VzIGFyZQogICIjIiBDb21tZW50LAogICJcIiIgUGxhaW4gU3RyaW5nICJcIiIgUGxhaW4K
IyAgIGV4Y2VwdGlvbnMgYXJlCiMgICAgL1xcXFwsLwojICAgICAgIGVuZCBleGNlcHRpb25zCmVu
ZCBzZXF1ZW5jZXMKCmtleXdvcmRzIGluIEtleXdvcmRfc3Ryb25nIGFyZQogIGlmLCB0aGVuLCBl
bHNlLCBicmVhaywgd2hpbGUsIGZvciwgZnVuY3Rpb24sIG5leHQsIHJldHVybiwgRkFMU0UsIFRS
VUUKZW5kIGtleXdvcmRzCgpvcGVyYXRvcnMgYXJlCiAgIDwtIFxsZWZ0YXJyb3cKZW5kIG9wZXJh
dG9ycwoKb3B0aW9uYWwgc2VxdWVuY2VzIGFyZQogICA8IFBsYWluIEtleXdvcmQgPiBQbGFpbgpl
bmQgc2VxdWVuY2VzCmVuZCBzdHlsZQ==
--QcBiZYhiHg
Content-Type: application/octet-stream
Content-Disposition: attachment;
	filename="Rd.ssh"
Content-Transfer-Encoding: base64

IyBTdHlsZSBzaGVldCBmb3IgUyBvdXRwdXQKIyBDb3B5cmlnaHQgKGMpIDIwMDAgVG9yc3RlbiBI
b3Rob3JuCgojCiMgCiMgVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVk
aXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkKIyBpdCB1bmRlciB0aGUgdGVybXMgb2YgdGhlIEdO
VSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlIGFzIHB1Ymxpc2hlZCBieQojIHRoZSBGcmVlIFNvZnR3
YXJlIEZvdW5kYXRpb247IGVpdGhlciB2ZXJzaW9uIDIsIG9yIChhdCB5b3VyIG9wdGlvbikKIyBh
bnkgbGF0ZXIgdmVyc2lvbi4KIwojIFRoaXMgcHJvZ3JhbSBpcyBkaXN0cmlidXRlZCBpbiB0aGUg
aG9wZSB0aGF0IGl0IHdpbGwgYmUgdXNlZnVsLAojIGJ1dCBXSVRIT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FBsYWluLAogICJcXCIgS2V5d29yZF9zdHJvbmcgInsiIFBsYWlu
CiMgICJ7IiBQbGFpbiBTdHJpbmcgIn0iIFBsYWluCiMJZXhjZXB0aW9ucyBhcmUKIwkvaXRlbXss
Y29kZXssdXNhZ2V7LGtleXdvcmR7LwojCWVuZCBleGNlcHRpb25zCiMgICJ7IiBQbGFpbiBTdHJp
bmcgIn17IiBQbGFpbgojCQojICAgZXhjZXB0aW9ucyBhcmUKIyAgIC9cXFthOnpdey8gS2V5d29y
ZCAifSIgUGxhaW4KIyAgIGVuZCBleGNlcHRpb25zCmVuZCBzZXF1ZW5jZXMKCm9wZXJhdG9ycyBh
cmUKICAgPC0gXGxlZnRhcnJvdwplbmQgb3BlcmF0b3JzCgpvcHRpb25hbCBzZXF1ZW5jZXMgYXJl
CiAgIDwgUGxhaW4gS2V5d29yZCA+IFBsYWluCmVuZCBzZXF1ZW5jZXMKZW5kIHN0eWxl
--QcBiZYhiHg--

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Off-topic: Pretty-printing R (or S) code with GNU a2ps
Kurt Hornik