PrettyPDF icon indicating copy to clipboard operation
PrettyPDF copied to clipboard

Output code overflow

Open SchmidtPaul opened this issue 11 months ago • 4 comments

First of all, thanks a lot for this. I jumped right in and created my version based on your template.

However, how are you dealing with this?

---
title: "Pretty PDFs with Quarto - Output overflow?"
format: PrettyPDF-pdf
---

The geometry was adjusted to make room for the border on the right hand side via `\geometry{a4paper, total={170mm,257mm}, left=20mm, top=20mm, bottom=20mm, right=50mm}`.

However, the code output does not seem to be affected by this?

```{r}
letters
```

Image

I spent some time trying to fix it and found e.g. this but so far no solution for me so that I may need to go back to default geometry and no border on the right side :(

SchmidtPaul avatar Feb 11 '25 08:02 SchmidtPaul

To control output text the quick fix as per the R Markdown Cookbook https://bookdown.org/yihui/rmarkdown-cookbook/text-width.html is to specify options(width = 70) (or whatever number is relevant, maybe you need slightly less, I think the default is 85), i.e., you can do this in either the YAML header as

---
title: "Pretty PDFs with Quarto - Output overflow?"
format: PrettyPDF-pdf
engine: knitr
knitr:
  opts_chunk: 
    R.options:
      width: 70
---

or in a chunk near the start of your doc, e.g.

---
title: "Pretty PDFs with Quarto - Output overflow?"
format: PrettyPDF-pdf
---

```{r}
#| include: false
options(width = 70)
```

but you might need to get into trickery with the LaTeX listings package as well.

remlapmot avatar Feb 11 '25 17:02 remlapmot

Thank you! This solves the issue. I was sceptical whether it would actually also decrease the box's width - which you can't see in PrettyPDF, so I used my modified version with a green bg color to check. But yeah, seems to work perfectly:

Image

SchmidtPaul avatar Feb 19 '25 11:02 SchmidtPaul

Thanks @remlapmot, the width options is what I'm currently using as well to deal with this problem. I'm going to leave this issue open for now since I'm working on a non-R specific fix using LaTeX.

nrennie avatar Feb 19 '25 13:02 nrennie

That's great.

This is a great extension.

On a different point, for your super Quarto tutorials blog post Frank Dondelinger and I (coincidentally when Frank and I were both at Lancaster) had the equivalent older R Markdown trick of placing the answer text within an asis chunk, i.e.,

```{asis}
Solutions text goes here
```

(whose include status is similarly toggled by the global knitr chunk options).

I realised that your Quarto solution would probably work for other engines, and I managed to get it working for the jupyter: python3, jupyter:nbstata (for Stata), and engine: julia.

https://remlapmot.github.io/post/2025/quarto-conditional-content/

It will be great when Quarto allows the equivalent of ! expr in chunk options for other engines.

cheers Tom

remlapmot avatar Feb 20 '25 13:02 remlapmot