- 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 ...
This might be a judgement call, but I don't find the latex output of listings or highlight to be visually pleasing enough, but maybe it is just a lack of understanding on how to customize them. Anyway, jedit has the Code2HTML plugin which does a good job of translating the buffer being edited in jedit into html markup, preserving pretty much everything that appear on the jedit text area. This takes advantage of jedit mode files which offers a great deal of flexibility, including nested languages, such as javascript/php, or R and Sweave if you have the right mode files.
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