1

I downloaded the Sweavel.sty-File from here: http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SweaveTemplate/Sweavel.sty

Now, for a modern look, I would like to produce rounded corners in the R code listings, like so: Background overflows when using rounded corners for listings (package: `listings`)

How can I change the Sweavel.sty or Sweave.sty files to obtain the desired output?

I hope my question is clear. If not, please tell so.

Any direct help or linkage to other websites/posts is greatly appreciated. Thanks for your time.

Strohmi
  • 123
  • 1
    You might consider the mdframed package. It's relatively recent, so you'd want the latest version. You can use the \surroundwithmdframed command to wrap pre-existing environments with frames. – G. Poore Aug 10 '12 at 16:06
  • Thanks for your answer, @G.Poore. Would I have to wrap the \surroundwithmdframed in the .tex-file or in the Sweavel.sty? I first tried it in the .tex-file and had no luck. I checked the docu to the mdframed package but it was not clear to me how to use the \surroundwithmdframed environment. Can you please help me out further. Thanks – Strohmi Aug 10 '12 at 16:44
  • I think you would want to use the command in your .tex file, leaving the .sty as-is. So you would want \surroundwithmdframed{Sinput}, \surroundwithmdframed{Scode}, etc. for all of the environments created in the .sty with \lstnewenvironment. Also, you would probably want to customize the mdframed frame by using optional arguments, for example, \surroundwithmdframed[linewidth=2pt]{Sinput}. And you would probably want to turn off background colors, etc. from listings (redo the styles created in the .sty with \lstdefinestyle). – G. Poore Aug 10 '12 at 16:54
  • Thanks again, @G.Poore. It is working now. I put the code into the Sweavel.sty-file. Anyone who is interested in the code, can send me a message. I will then send the code. – Strohmi Aug 10 '12 at 17:08
  • 1
    @G.Poore Can you make a simple answer for this to be removed from the unanswered list? – percusse Aug 10 '12 at 23:00
  • Thanks for posting the answer, @G.Poore. It is working fine now. However, I encountered a problem using the mdframed package that is related to pagebreaks. Whenever there is a pagebreak in the \surroundwithmdframed{Soutput}-environment, the code is not highlighted in the specific color anymore. The text color changes from dark red (Sweavel style) to black. Any ideas on how to change this? – Strohmi Aug 13 '12 at 16:12
  • I'm not sure how to fix the color-pagebreak issue. If it's on the mdframed side, maybe @MarcoDaniel can fix it--but it might be on the listings side, in which case you'd need someone who knows listings. If it can't be fixed, there are three things I can suggest. 1: Use listing's frameround and framesep options to get round corners (doesn't work with background colors). 2: Use mdframed, and set all text black. 3: Make your own package, based on Sweavel but using a highlighting package that works with mdframed (such as highlighting from my PythonTeX). – G. Poore Aug 19 '12 at 02:06
  • @G.Poore: Which issue? – Marco Daniel Aug 19 '12 at 06:23
  • @MarcoDaniel: In the comment right before mine, Strohmi describes a case where the Soutput environment, when wrapped in mdframed, loses its red text coloring after a page break. Text before the break is red, text after is back to black. I've replicated this behavior using a simple doc. I don't know the mdframed and listings code well enough to know exactly what is causing this. – G. Poore Aug 19 '12 at 13:09

1 Answers1

1

Here's an answer based off of my comments.

The mdframed package can do what you want. It's relatively recent, so you should make sure you are using the latest version. You can use the \surroundwithmdframed command to wrap pre-existing environments with frames. So you would want \surroundwithmdframed{Sinput}, \surroundwithmdframed{Scode}, etc. for all of the environments that are created in Sweavel.sty via \lstnewenvironment. Also, you would probably want to customize the mdframed frame by using optional arguments, for example, \surroundwithmdframed[linewidth=2pt]{Sinput}. Depending on your needs, it might be simplest to define an mdframed style, so you can easily use the same style for multiple environments. And you would probably want to turn off background colors, etc. from listings (modify the listings styles created in Sweavel.sty with \lstdefinestyle).

I would recommend using the \surroundwithmdframed commands within your .tex file, rather than modifying Sweavel.sty. That will make your document more portable, since anyone can use it and get the same results; it won't depend on a custom version of Sweavel.sty. If you need these custom settings a lot, you could simply throw together your own .sty file. If it's primarily for personal use, you can just do something very quick and simple like this. For more on creating styles, see this.

G. Poore
  • 12,417