- the listings package (somehow supported by the R package SweaveListingUtils
- Using highlight. I am using it in the graph gallery for example
- There are probably other ways ...
So I had a look into the code of the Code2HTML plugin which is simple enough, and have basically done a big
s/html/latex/g to support latex output (I realize this is not the best option and I should probably abstract things out so that it would be easier to add new formats: ansi, svg, ...) but it does the trick for now.
Here is a screenshot of an example file edited in jedit:
And a screenshot of the pdf file
Here are the relevant files if you want to try it out:
- The modified source of Code2HTML
- The actual jar file
- An example R file
- ... once translated into latex markup
- ... once compile with pdflatex
- do something about the gutter
- figure out how to invoke that from the command line
- write a sweave driver that would call it so that R code appears formatted in sweave documents