0

I'm gratuitously using knitr to write a formal PDF document. I would like to use a code block instead a block quote because... it's funny. However, the paragraph that I would like to put in the code block doesn't wrap to the box. How can I do this? I've tried the following:

\documentclass[a4paper]{article}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{csquotes}
\begin{document}

<<setup, include=FALSE, results='hide', cache=FALSE>>=
opts_chunk$set(echo=FALSE, warning = FALSE, message = FALSE, cache = FALSE, error = FALSE)
@

Some text

<<tidy=TRUE, width=50, comment=NA>>==
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut     
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur.     
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum."
@

\end{document}

...Which gives this:

enter image description here

I tried this solution but I'd like to avoid numbering each row. I've also tried pasting in "\n" to do line breaks to no avail.

Community
  • 1
  • 1
Nancy
  • 3,989
  • 5
  • 31
  • 49
  • Does adding two spaces to the end of each line add a manual line break within a code block? – Phil Jan 28 '17 at 22:25
  • No, two spaces doesn't do anything. Manually putting the text on different lines _does_ add in \n to the string, but the string is still on one line in the document. – Nancy Jan 29 '17 at 04:06

1 Answers1

0

based on the syntax of your code, you may want to directly use LaTex instead of RStudio (knitr) to create your output. In my RStudio, I got an error message and could not compile the PDF until the LaTex-specific commands such as \begin{document} and \end{document} were removed. I hope this is what you are looking for:

---
title: "Untitled"
output: pdf_document
---

```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
options(width=80)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = TRUE, size="small")
```

Some text

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut     
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur.     
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum."

enter image description here

I noticed that you specified width=50 as chunk option for just one chunk. It might be beneficial if you set that option as a global chunk option, as in this post.

Community
  • 1
  • 1
David C.
  • 1,974
  • 2
  • 19
  • 29
  • The point is to use knitr (a .Rnw script not .Rmd) out of novelty; I could of course do this in LaTeX but it more fun/pedagogical to do it the hard way. – Nancy Jan 28 '17 at 21:55
  • You probably got the errors because you were using a .Rmd file which takes markdown and not an .Rnw file which uses latex commands like \being{document}. – Nancy Jan 28 '17 at 21:56