# [Rd] Sweave trims console output in "tex" mode

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jan 3 17:38:41 CET 2014

```On 03/01/2014 7:32 AM, Kirill Müller wrote:
> On 01/03/2014 01:06 PM, Duncan Murdoch wrote:
> > On 14-01-03 5:47 AM, Kirill Müller wrote:
> >> I'm sorry, I didn't mean to be rude. Do you prefer including the entire
> >> original message when replying? Or perhaps I misunderstood you when you
> >> wrote:
> >
> > You don't need to include irrelevant material in your reply, but you
> > should include explanatory material when you are arguing about a
> > particular claim.  If you aren't sure whether it is relevant or not,
> > then you should probably ask for clarification rather than arguing
> > with the claim.
> >
> Thanks. In the future, I'll quote at least full sentences and everything
> they refer to, to avoid confusion and make sure that context is maintained.
> >>
> >>   > Carriage returns usually don't matter in LaTeX, so I didn't even
> >> know
> >> at the source to see where the newlines were going, and saw it there.
> >>
> >> Could you please clarify? Thanks.
> >
> > Single carriage returns are usually equivalent to spaces. Multiple
> > carriage returns separate paragraphs, but they are rare in code chunk
> > output in my Sweave usage.  I normally put plain text in the LaTeX
> > part of the Sweave document.
> >
> Indeed, it only makes a difference for code that generates large
> portions of LaTeX (such as tikzDevice).
> > I have checked my own .Rnw files, and I have used results=tex about
> > 600 times, but never used strip.white.
> >
> > I've also looked at the .Rnw files in CRAN packages, and
> > strip.white=true and strip.white=all are used there about 140 times,
> > but strip.white=false is only used 10 times.  I think only one package
> > (SweaveListingUtils) uses strip.white=false in combination with
> > results=tex.
> >
> > So while I agree Martin's "adaptive" option would have been a better
> > default than "true", I think it would be more likely to cause trouble
> > than to solve it.
> >
> I agree, given this data and considering that trimming the terminal
> newline can be considered a feature. Perhaps comments are the only use
> case where the newline is really important. But then I don't see how to
> reliably detect comments, as the catcode for % can be changed, e.g., in
> a verbatim environment. I'll consider printing a \relax after the
> comment in tikzDevice, this should be robust and sufficient.
I haven't done any tests, but I believe the trimming only happens at the
start and end of the output from each statement, i.e.
embedded newlines in the output from single statements will be kept, as
between c and d in your example.  So it should be possible to avoid
needing strip.white=false by collecting output in a character vector,
and just cat()'ing it at the end.  I don't know if this is relevant to