bookdown-crc icon indicating copy to clipboard operation
bookdown-crc copied to clipboard

Using listings package to break lines in R output

Open szimmer opened this issue 2 years ago • 4 comments

I'm trying to incorporate recommendations here to break the lines of R output in a PDF but I can't get it to work.

See example of what I changed here

Overview:

  • Added listings package to preamble.tex \usepackage{listings}
  • Set option to break lines in before_body.tex \lstset{breaklines=true}
  • Added a chunk of wide output using
options(width=200)
1:100

When I made the PDF, it doesn't break the lines as expected.

image

Any ideas?

szimmer avatar Jul 02 '23 22:07 szimmer

If you don't use krantz.cls documentclass as CRC uses it, does it works ?

It is possible listings package is conflicting with krantz maybe ?

Unfortunately, this is LaTeX expertise and I am not that expert - @yihui do you know if krantz has issue with listings ?

cderv avatar Jul 03 '23 15:07 cderv

This is for a CRC book so I do need to use the krantz.cls

szimmer avatar Jul 03 '23 20:07 szimmer

This is for a CRC book so I do need to use the krantz.cls

I understand that. Just if listings package is not working with krantz.cls, another solution needs to be found.

As I said I am no LaTeX expert - I can fix issue if there is some with bookdown. However, if you need a LaTeX solution for this, you should look into LaTeX specific Q&A place.

If you are publishing a book with CRC, don't they have a LaTeX helpdesk you could reach out to ?

FWIW, this is the preamble we use with the CRC publish book R Markdown cookbook (https://github.com/rstudio/rmarkdown-cookbook/blob/master/latex/preamble.tex)

I don't remember exactly what we have done to keep the line to their expected length. @yihui may know more, but he is off right now, and will add to my answers as soon as he can.

Thanks for your patience !

cderv avatar Jul 04 '23 10:07 cderv

krantz.cls is quite complicated, and I'd recommend contacting the CRC LaTeX help desk for any LaTeX issues.

An alternative solution is to customize the output hook, which doesn't require using the listings package: https://github.com/yihui/knitr-examples/blob/master/077-wrap-output.Rmd

yihui avatar Aug 08 '23 23:08 yihui